Empty CMAKE_TRY_COMPILE_CONFIGURATION results in missing compiler flags
I was debugging a build failure while cross-compiling poppler (https://gitlab.freedesktop.org/poppler/poppler).
Poppler overrides the user-provided CMAKE_{C,CXX}_FLAGS
and appends them
to the per-configuration variables instead: https://gitlab.freedesktop.org/poppler/poppler/-/blob/eea6b4f9caa7555009d959de51acb81037b2a465/cmake/modules/PopplerMacros.cmake#L151.
This behaviour currently causes cross-compilation checks to fail since these these per-configuration flags are no passed to try_compile() commands.
In my case the flags specified in the toolchain file (as part of CMAKE_{C,CXX}_FLAGS_INIT
) are absolutely required to compile successfully since a missing -mabi=/-march=
flag will result in a linker error due to trying to link incompatible libraries.
In this case CMP0066 is NEW, so we should be using the per-configuration flags for try_compile, but this only happens if CMAKE_TRY_COMPILE_CONFIGURATION
is set explicitly. I believe this issue has existed since the initial commit that added CMP0066.
This was rather difficult to debug since CMake does not output compilation command for try_compile()
. Using the flag --debug-trycompile
and some staring at the source code allowed me to determine that the problem is that CMAKE_BUILD_TYPE
is not being forwarded.