After a detailed analysis of cmake, I believe this is the solution and not just fixing the symptom.
cmake uses /usr/bin/xcodebuild when using -G Xcode. The internal behavior of cmake is significantly different when using xcodebuild in contrast to generating Unix makefiles. Specifically, try_run used by CHECK_C_SOURCE_RUNS and try_compile used by CHECK_C_SOURCE_COMPILES do not use the environment variables in the same way when using the Xcode Generator.
Guy, the normal behavior of CHECK_C_SOURCE_RUNS for Unix makefiles will check linker flags because it does attempt to link and run the resulting executable. This is why ‘—-as-needed' fails when using basic cmake.
I hope I never have to reverse engineer cmake in the future.
David |