CHECK_LIBRARY_EXISTS incorrectly checks and detects a library when cross-compiling with an Xcode generator
CMake 3.27.9 (from Homebrew)
My project references glog via add_directory. The project uses cross-compilation (on macOS host for tvOS) via the ios-cmake toolchain.
When I generate an Xcode project with the following command:
cmake --fresh -S ... -B ... -G Xcode -DCMAKE_TOOLCHAIN_FILE=.../ios-cmake/ios.toolchain.cmake -DPLATFORM=TVOSCOMBINED -DCMAKE_PREFIX_PATH=/Users/developer/Qt/6.6.1/ios -DDEPLOYMENT_TARGET=17.0 -DBUILD_TESTING=OFF -DWITH_GTEST=OFF -DBUILD_SHARED_LIBS=OFF --debug-trycompile
The CHECK_LIBRARY_EXISTS for dbghelp in glog incorrectly detects its presence. Further inspection of the generated TryCompile (attached) test project reveals that it makes no actual attempt in detection that this library is available. You can see that the test declares and then uses a symbol hoping for the build process to reveal presence or absence of the library. Except it will always succeed, because the project is building a static library without an executable and thus no linkage actually takes place.
Edited by Ilya Kulakov