find_package searches directories prefixed by package name [Docu issue]
Peter Dimov noted that a find_package(Boost)
does also find configs in e.g. <PREFIX>/lib/cmake/Boost-1.72.0/BoostConfig.cmake
which I considered odd because this is undocumented(?) behavior.
After digging around with a debugger I located this place: https://gitlab.kitware.com/cmake/cmake/blob/826876f62a63427a8ad1b1fc3a0796cd82630421/Source/cmFindPackageCommand.cxx#L1870
From the usage of the class cmFileListGeneratorProject
I conclude that for each prefix in
* <prefix>/ (W)
* <prefix>/(cmake|CMake)/ (W)
* <prefix>/<name>*/ (W)
* <prefix>/<name>*/(cmake|CMake)/ (W)
* <prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/ (U)
* <prefix>/(lib/<arch>|lib*|share)/<name>*/ (U)
* <prefix>/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (U)
* <prefix>/<name>*/(lib/<arch>|lib*|share)/cmake/<name>*/ (W/U)
* <prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/ (W/U)
* <prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (W/U)
where <name>*
is listed it actually means a "GLOB", hence searches all folders prefixed by <name>
.
I read the docu multiple times but never realized this. I hence propose to explicitly highlight this.
In extension: Is there some "official" or recommended way to install multiple versions of the same library into a common prefix? It seems with the above it is possible: Put the Configs into versioned directories and version the library names themselves. This allows:
- having multiple versions (1.x, 1.y)
- having different configs (debug, release, ...) by running cmake multiple times with different
CMAKE_BUILD_TYPE
Boost is a great example to discuss on how to deal with multiple variants. For example: How would one deal with static/dynamic runtime? Toolsets (different msvc versions, gcc, ...)? single or multi-threaded?
So I want to extent the version question to the more generic variants question. Is this possible with CMake configs?