try_compile generated temporary targets don't honor link_libraries.

Hello! My project has a global link_libraries call which introduces a different libcxx headers and standard libs. It works fine for all my code and dependencies. However, things like CheckTypeSize and CheckFunctionExists which uses try_compile don’t work at all, because my toolchain relies on the specified default headers/libs to work correctly.

I also tried setting CMAKE_CXX_STANDARD_LIBRARIES and CMAKE_C_STANDARD_LIBRARIES, but try_compile still cannot see them. The only way to make it work is using CMAKE_CXX_FLAGS which looks dirty.

I also notice a flag: CMAKE_TRY_COMPILE_TARGET_TYPE. When doing cross-compiling, it defaults to STATIC_LIBRARY, which can make checks work, but that’s too permissive. check_library_exists will almost always return true. So I have to force CMAKE_TRY_COMPILE_TARGET_TYPE = EXECUTABLE

Is there any standard way of adding default headers/libs to try_compile?