I have a CMake project that generates a library. I have written a CMake script, FindXXX.cmake, to help users of my library. This way they can use find_package(XXX) and get the variables needed. So far so good.
The problem now is that users have copied this FindXXX.cmake into their own projects. If I modify it, they will just stick with the former one.
Is there a common way to distribute such a script? Should my installer put it in some special location so that CMake finds it without having users copying it in their project?
Try to copy to ${CMAKE_ROOT}/Modules
. You may need system administrator rights.
Another solution could be add some registry entry on Windows: HKEY_CURRENT_USER\Software\Kitware\CMakeSetup\Settings\StartPath
. You should add the next WhereBuild{i}
value to your project CMake files. The trick here is that the CMake search for known libraries from the previously-used libraries.
Based on the suggested documentation:
You should create the following library and copy FindProjectName.cmake: C:\Program Files\ProjectName\CMake on Windows, /usr/local/ProjectName/share/cmake on Linux.
Actually, while copying a FindXXX.cmake file to ${CMAKE_ROOT}/Modules will work, there are several other locations your project can put a "project configuration file" instead where CMake will find it automatically without a FindXXX.cmake file.
According to the find_package documentation you can install your project configuration file into your own installation tree, and CMake will find it, if your installation tree is in one of the "conventional" locations.
Look for the text on that page that begins with "CMake constructs a set of possible installation prefixes for the package" to see the details about where you can install your project configuration file so that CMake finds it automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With