FindThreads.cmake incompatible with --find-package mode
When trying to use --find-package
mode to extract a package's build flags for use outside CMake, I encountered a problem when the package in question (or one of its dependencies) calls find_package(Threads REQUIRED)
. An easy way to encounter the error is to query Threads
directly:
$ cmake --find-package -DNAME=Threads -DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=EXIST
CMake Error at /usr/share/cmake-3.10/Modules/FindThreads.cmake:54 (message):
FindThreads only works if either C or CXX language is enabled
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/CMakeFindPackageMode.cmake:180 (find_package)
Threads not found.
CMake Error: Problem processing arguments. Aborting.
I tried setting CMAKE_C_COMPILER_LOADED
to avoid the first error and got this result instead:
$ cmake --find-package -DNAME=Threads -DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=EXIST -DCMAKE_C_COMPILER_LOADED=1
CMake Error at /usr/share/cmake-3.10/Modules/CheckIncludeFile.cmake:56 (try_compile):
The TRY_COMPILE() command is not supported in --find-package mode.
It seems like FindThreads.cmake
is incompatible with CMake's --find-package
mode.
I know that --find-package
is not recommended for new work, but it's a handy way to expose the build flags to non-CMake systems. I'd appreciate any pointers on how to work around this problem.