Hdden compiler and link options being added to compile and link line

I am using Conan/CMake with QT 6.5.3
When running CMake 3.24.4 to generate Ninja files for a Release build I am finding “hidden” options added to the compile and link line.

For example, I note the link flags in ninja.build contains “-LTCG”

Nowhere in my CMakeLists.txt do I add that option. It seems to be added by a QT6 CMake Module.

If I add the following

target_link_options(${PROJECT_NAME} PRIVATE
$<$CONFIG:RELEASE:/LTCG:OFF>)

I get two options, and of course the last one “dominates”

LINK_FLAGS = /machine:x64 /INCREMENTAL:NO /subsystem:windows /entry:WinMainCRTStartup /LTCG:OFF -LTCG

I have similar issues with compile options and a sticky /GL flag. It seems to be related to QT6.

I cannot find these options when running CMake. I can print all the various variables, and none of them contain these “extra” flags. They just appear in the ninja.build file.
For example I can get the property “COMPILE_OPTIONS” and the mystery option is not there.

You can see all code that CMake sees with --trace-expand. This may be a Qt issue to ask for a way to suppress the flag.

Thank you. I found the culprit, it was not QT, it was pybind11

D:/conan/.conan/data/pybind11/2.10.1/vaone-dev/va1-1.19.x/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib/cmake/pybind11/pybind11Common.cmake(265):  function(_pybind11_return_if_cxx_and_linker_flags_work result cxxflags linkerflags cxxflags_out linkerflags_out )
D:/conan/.conan/data/pybind11/2.10.1/vaone-dev/va1-1.19.x/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib/cmake/pybind11/pybind11Common.cmake(279):  function(_pybind11_generate_lto target prefer_thin_lto )
D:/conan/.conan/data/pybind11/2.10.1/vaone-dev/va1-1.19.x/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib/cmake/pybind11/pybind11Common.cmake(366):  _pybind11_generate_lto(pybind11::lto FALSE )
D:/conan/.conan/data/pybind11/2.10.1/vaone-dev/va1-1.19.x/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib/cmake/pybind11/pybind11Common.cmake(280):  if(MINGW )
D:/conan/.conan/data/pybind11/2.10.1/vaone-dev/va1-1.19.x/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib/cmake/pybind11/pybind11Common.cmake(285):  if(CMAKE_CXX_COMPILER_ID MATCHES GNU|Clang )
D:/conan/.conan/data/pybind11/2.10.1/vaone-dev/va1-1.19.x/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib/cmake/pybind11/pybind11Common.cmake(314):  elseif(CMAKE_CXX_COMPILER_ID MATCHES Intel )
D:/conan/.conan/data/pybind11/2.10.1/vaone-dev/va1-1.19.x/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib/cmake/pybind11/pybind11Common.cmake(318):  elseif(MSVC )
D:/conan/.conan/data/pybind11/2.10.1/vaone-dev/va1-1.19.x/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib/cmake/pybind11/pybind11Common.cmake(322):  _pybind11_return_if_cxx_and_linker_flags_work(HAS_MSVC_GL_LTCG /GL -LTCG PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS )
D:/conan/.conan/data/pybind11/2.10.1/vaone-dev/va1-1.19.x/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib/cmake/pybind11/pybind11Common.cmake(267):  set(CMAKE_REQUIRED_LIBRARIES -LTCG )
D:/conan/.conan/data/pybind11/2.10.1/vaone-dev/va1-1.19.x/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/lib/cmake/pybind11/pybind11Common.cmake(268):  check_cxx_compiler_flag(/GL HAS_MSVC_GL_LTCG )
C:/Program Files/CMake/share/cmake-3.24/Modules/CheckCXXCompilerFlag.cmake(40):  cmake_check_compiler_flag(CXX /GL HAS_MSVC_GL_LTCG )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckCompilerFlag.cmake(11):  cmake_parse_arguments(PARSE_ARGV 3 CHECK_COMPILER_FLAG  OUTPUT_VARIABLE  )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckCompilerFlag.cmake(13):  cmake_check_flag_common_init(check_compiler_flag CXX _lang_src _lang_fail_regex )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(15):  if(CXX STREQUAL C )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(19):  elseif(CXX STREQUAL CXX )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(20):  set(_lang_src int main() { return 0; } )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(21):  set(_lang_fail_regex FAIL_REGEX command[ -]line option .* is valid for .* but not for C\+\+ FAIL_REGEX -Werror=.* argument .* is not valid for C\+\+ )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(56):  get_property(_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(57):  if(NOT CXX IN_LIST _supported_languages )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(62):  set(_CFCC_locale_vars LC_ALL LC_MESSAGES LANG )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(63):  foreach(v IN LISTS _CFCC_locale_vars )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(64):  set(_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_LC_ALL  )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(65):  set(ENV{LC_ALL} C )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(64):  set(_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_LC_MESSAGES  )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(65):  set(ENV{LC_MESSAGES} C )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(64):  set(_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_LANG  )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckFlagCommonConfig.cmake(65):  set(ENV{LANG} C )
C:/Program Files/CMake/share/cmake-3.24/Modules/Internal/CheckCompilerFlag.cmake(15):  set(CMAKE_REQUIRED_DEFINITIONS /GL )