If some project provides its own CMake modules, where would be the best place to install them on the system so other projects can simply use them via include() and find_package()?
Does CMake have any such additional path out of the box somehow?
If some project provides its own CMake modules, where would be the best place to install them on the system so other projects can simply use them via include() and find_package()?
Does CMake have any such additional path out of the box somehow?
Iβd also be curios to know what is the best/common practice for this.
In our project we have our own CMake modules too, and we have been installing them into ${CMAKE_INSTALL_PREFIX}/share/OurPackage/modules/ as a part of a relocatable package, so the resulting folder structure is this:
βββ debug
β βββ lib
β βββ [ ... debug binaries ... ]
βββ include
β βββ our-package
β βββ [ ... public headers ... ]
βββ lib
β βββ [ ... release binaries ... ]
βββ share
βββ OurPackage
βββ modules # here are the modules
β βββ some.cmake
β βββ thing.cmake
β βββ another.cmake
βββ OurPackageConfig.cmake
βββ OurPackageConfigVersion.cmake
βββ OurPackageTargets-debug.cmake
βββ OurPackageTargets-release.cmake
βββ OurPackageTargets.cmake
And then of course our users aside from providing path to our package in CMAKE_PREFIX_PATH (or in OurPackage_DIR) also need to add path to our modules (/path/to/our/package/prefix/share/OurPackage/modules) into their projectβs CMAKE_MODULE_PATH.
Not sure if this is how it should be done, but it seems to be working fine so far.
Iβd just make a package. If you want users to then include things piece-by-piece, offer a variable for where they live:
find_package(YourCoolPackage)
list(INSERT CMAKE_MODULE_PATH 0
${YourCoolPackage_CMAKE_MODULE_PATH})
include(YourCoolPackage_API)
Then you provide a YourCoolPackageConfig.cmake in its normal search locations (<prefix>/share/cmake/YourCoolPackage-1.0/YourCoolPackageConfig.cmake).
If piece-by-piece isnβt necessary, just include() the API bits in the package itself.