CMAKE_TRY_COMPILE_TARGET_TYPE value affects CMAKE_<LANG>_IMPLICIT_LINK_DIRECTORIES
Consider the following code:
cmake_minimum_required(VERSION 3.6)
project(test LANGUAGES NONE)
# set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) # Uncomment to get empty CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES
enable_language(CXX)
include(CMakePrintHelpers)
cmake_print_variables(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES)
It runs as expected:
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES="/usr/lib/gcc/x86_64-linux-gnu/11;/usr/lib/x86_64-linux-gnu;/usr/lib;/lib/x86_64-linux-gnu;/lib"
-- Configuring done (0.2s)
-- Generating done (0.0s)
However, with the uncommented line, the CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES
is empty:
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES=""
-- Configuring done (0.3s)
-- Generating done (0.0s)
Such behavior at least is undocumented and might cause confusion.