How to distribute FindXXX.cmake

I have a CMake project that generates a library. I wrote a CMake script, FindXXX.cmake, to help users of my library. That way they can use find_package (XXX) and get the necessary variables. So far, so good.

The problem is that users have copied this FindXXX.cmake into their own projects. If I change it, they will just stick to the former.

Is there a common way to distribute such a script? Should my installer put it in some special place for CMake to detect it without having users copy it in their project?

+4
source share
2 answers

Try copying to ${CMAKE_ROOT}/Modules . You may need system administrator rights.

Another solution might be to add a registry entry in Windows: HKEY_CURRENT_USER\Software\Kitware\CMakeSetup\Settings\StartPath . You must add the following WhereBuild{i} value to your CMake project files. The trick here is to search in CMake for known libraries from previously used libraries.

Based on the proposed documentation :

You must create the following library and copy FindProjectName.cmake: C: \ Program Files \ ProjectName \ CMake on Windows, / usr / local / ProjectName / share / cmake on Linux.

+4
source

In fact, when copying the FindXXX.cmake file to $ {CMAKE_ROOT} / Modules will work, there are several other places where your project can place the "project configuration file" instead of where CMake will find it automatically without the FindXXX.cmake file.

According to the find_package documentation, you can install the project configuration file in your own installation tree, and CMake will find it if your installation tree is in one of the “normal” locations.

Find the text on this page that begins with “CMake creates a set of possible installation prefixes for the package” to find out more about where you can install the project configuration file so that CMake detects it automatically.

+2
source

All Articles