[CMake] Include file in the Makefile

Michael Ellery mellery451 at gmail.com
Thu Mar 23 12:59:12 EDT 2017


> On Mar 22, 2017, at 2:07 PM, Hom Nath Gharti <hng.email at gmail.com> wrote:
> 
> Dear all,
> 
> I use PETSc in my package and I need to use the following line in my
> GNU Makefile:
> 
> include ${PETSC_DIR}/lib/petsc/conf/variables
> 
> What is the equivalent command for CMakeLists.txt for this?
> 
> Thanks for your help.
> 
> Thanks,
> HNG
> -- 

The typical way to use an installed library is via find_package, which requires either a pkgspec or a find module. It looks like someone has already written a find module:

https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake

so, you can do something like:

* fork/or submodule this repo above 
* append to CMAKE_MODULE_PATH in your CMakeLists.txt file to add the path to this module above.
* call find_package(PETSc)
* use the variables that are documented in the finder to set your include_directories and target_link_libraries.

If you are certain the env variable PETSC_DIR is always going to be set (as above), then you can simply build paths based on that variable and pass them to include_directories and target_link_libraries, but the finders also do a better job of dealing with various build environments, etc.

HTH,
Mike Ellery


More information about the CMake mailing list