From 8ba16db1637940540fbb254cad7f85c2323c6a3a Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Tue, 18 Apr 2023 17:12:58 +0200 Subject: Tests/RunCMake: Add option for dynamic expected output Add `RunCMake_TEST_EXPECT_*` variables for this. --- Tests/RunCMake/RunCMake.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake index 8e85f6c..5e91e99 100644 --- a/Tests/RunCMake/RunCMake.cmake +++ b/Tests/RunCMake/RunCMake.cmake @@ -47,6 +47,8 @@ function(run_cmake test) elseif(EXISTS ${top_src}/${test}-${o}.txt) file(READ ${top_src}/${test}-${o}.txt expect_${o}) string(REGEX REPLACE "\n+$" "" expect_${o} "${expect_${o}}") + elseif(DEFINED RunCMake_TEST_EXPECT_${o}) + string(REGEX REPLACE "\n+$" "" expect_${o} "${RunCMake_TEST_EXPECT_${o}}") else() unset(expect_${o}) endif() -- cgit v0.12 From 033dc7ee2f02b0ebdfd1bc4edbcb24d1fc8c4152 Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Thu, 27 Apr 2023 11:18:26 +0200 Subject: Autogen: Add AUTOGEN_USE_SYSTEM_INCLUDE target property `AUTOGEN_USE_SYSTEM_INCLUDE` was added. `AUTOGEN_USE_SYSTEM_INCLUDE` is a boolean property that can be set on a target to indicate that the autogen target include directory should be added as a system include directory or normal include directory to the target. --- Auxiliary/vim/syntax/cmake.vim | 2 + Help/manual/cmake-properties.7.rst | 1 + Help/manual/cmake-variables.7.rst | 1 + Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst | 14 +++++++ Help/release/dev/autogen-system-include.rst | 7 ++++ Help/variable/CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE.rst | 10 +++++ Source/cmGeneratorTarget.cxx | 23 +++++++++++ Source/cmGeneratorTarget.h | 2 + Source/cmQtAutoGenInitializer.cxx | 15 ++++++- Source/cmTarget.cxx | 1 + .../GlobalAutogenSystemUseInclude/CMakeLists.txt | 28 +++++++++++++ .../GlobalAutogenSystemUseInclude/main.cpp | 4 ++ Tests/QtAutogen/Tests.cmake | 1 + .../Autogen/AutogenUseSystemIncludeCommon.cmake | 10 +++++ .../Autogen/AutogenUseSystemIncludeOff.cmake | 3 ++ .../Autogen/AutogenUseSystemIncludeOn.cmake | 3 ++ Tests/RunCMake/Autogen/Inspect.cmake | 13 ++++++ Tests/RunCMake/Autogen/RunCMakeTest.cmake | 48 ++++++++++++++++++++++ 18 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst create mode 100644 Help/release/dev/autogen-system-include.rst create mode 100644 Help/variable/CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE.rst create mode 100644 Tests/QtAutogen/GlobalAutogenSystemUseInclude/CMakeLists.txt create mode 100644 Tests/QtAutogen/GlobalAutogenSystemUseInclude/main.cpp create mode 100644 Tests/RunCMake/Autogen/AutogenUseSystemIncludeCommon.cmake create mode 100644 Tests/RunCMake/Autogen/AutogenUseSystemIncludeOff.cmake create mode 100644 Tests/RunCMake/Autogen/AutogenUseSystemIncludeOn.cmake create mode 100644 Tests/RunCMake/Autogen/Inspect.cmake diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim index d6b5b19..814c45a 100644 --- a/Auxiliary/vim/syntax/cmake.vim +++ b/Auxiliary/vim/syntax/cmake.vim @@ -73,6 +73,7 @@ syn keyword cmakeProperty contained \ AUTOGEN_ORIGIN_DEPENDS \ AUTOGEN_PARALLEL \ AUTOGEN_SOURCE_GROUP + \ AUTOGEN_USE_SYSTEM_INCLUDE \ AUTOGEN_TARGETS_FOLDER \ AUTOGEN_TARGET_DEPENDS \ AUTOMOC @@ -683,6 +684,7 @@ syn keyword cmakeVariable contained \ CMAKE_ASM_VISIBILITY_PRESET \ CMAKE_AUTOGEN_ORIGIN_DEPENDS \ CMAKE_AUTOGEN_PARALLEL + \ CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE \ CMAKE_AUTOGEN_VERBOSE \ CMAKE_AUTOMOC \ CMAKE_AUTOMOC_COMPILER_PREDEFINES diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index c0e2ee2..8ee5573 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -133,6 +133,7 @@ Properties on Targets /prop_tgt/AUTOGEN_ORIGIN_DEPENDS /prop_tgt/AUTOGEN_PARALLEL /prop_tgt/AUTOGEN_TARGET_DEPENDS + /prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE /prop_tgt/AUTOMOC /prop_tgt/AUTOMOC_COMPILER_PREDEFINES /prop_tgt/AUTOMOC_DEPEND_FILTERS diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index f3212de..7c5a654 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -397,6 +397,7 @@ Variables that Control the Build /variable/CMAKE_ARCHIVE_OUTPUT_DIRECTORY_CONFIG /variable/CMAKE_AUTOGEN_ORIGIN_DEPENDS /variable/CMAKE_AUTOGEN_PARALLEL + /variable/CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE /variable/CMAKE_AUTOGEN_VERBOSE /variable/CMAKE_AUTOMOC /variable/CMAKE_AUTOMOC_COMPILER_PREDEFINES diff --git a/Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst b/Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst new file mode 100644 index 0000000..fd21070 --- /dev/null +++ b/Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst @@ -0,0 +1,14 @@ +AUTOGEN_USE_SYSTEM_INCLUDE +-------------------------- + +``AUTOGEN_USE_SYSTEM_INCLUDE`` is a boolean property that can be set +on a target to indicate that the autogen target include directory should +be added as a system include directory or normal include directory to the +target. + +See the :manual:`cmake-qt(7)` manual for more information on using CMake +with Qt. + +This property is initialized by the +:variable:`CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE` variable if it is set when +a target is created. diff --git a/Help/release/dev/autogen-system-include.rst b/Help/release/dev/autogen-system-include.rst new file mode 100644 index 0000000..aea81be --- /dev/null +++ b/Help/release/dev/autogen-system-include.rst @@ -0,0 +1,7 @@ +autogen-system-include +---------------------- + +* The :prop_tgt:`AUTOGEN_USE_SYSTEM_INCLUDE` target property and + corresponding :variable:`CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE` were + added to explicitly control whether autogen headers are + considered system headers. diff --git a/Help/variable/CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE.rst b/Help/variable/CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE.rst new file mode 100644 index 0000000..80ed847 --- /dev/null +++ b/Help/variable/CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE.rst @@ -0,0 +1,10 @@ +CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE +-------------------------------- + +.. versionadded:: 3.27 + +This variable is used to initialize the :prop_tgt:`AUTOGEN_USE_SYSTEM_INCLUDE` +property on all targets as they are created. See that target property for +additional information. + +By default ``CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE`` is unset. diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index db3d7e6..e7145b2 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -731,6 +731,29 @@ void cmGeneratorTarget::AddIncludeDirectory(const std::string& src, BT(src, this->Makefile->GetBacktrace()), true)); } +void cmGeneratorTarget::AddSystemIncludeDirectory(std::string const& inc, + std::string const& lang) +{ + std::string config_upper; + auto const& configs = + this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); + + for (auto const& config : configs) { + std::string inc_with_config = inc; + if (!config.empty()) { + cmSystemTools::ReplaceString(inc_with_config, "$", config); + config_upper = cmSystemTools::UpperCase(config); + } + auto const& key = cmStrCat(config_upper, "/", lang); + this->Target->AddSystemIncludeDirectories({ inc_with_config }); + this->SystemIncludesCache[key].emplace_back(inc_with_config); + + // SystemIncludesCache should be sorted so that binary search can be used + std::sort(this->SystemIncludesCache[key].begin(), + this->SystemIncludesCache[key].end()); + } +} + std::vector const* cmGeneratorTarget::GetSourceDepends( cmSourceFile const* sf) const { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 87227fd..8b44eb5 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -912,6 +912,8 @@ public: std::vector GetGeneratedISPCObjects( std::string const& config) const; + void AddSystemIncludeDirectory(std::string const& inc, + std::string const& lang); bool AddHeaderSetVerification(); std::string GenerateHeaderSetVerificationFile( cmSourceFile& source, const std::string& dir, diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 4c45949..deb2c04 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -576,7 +576,20 @@ bool cmQtAutoGenInitializer::InitCustomTargets() // Add autogen include directory to the origin target INCLUDE_DIRECTORIES if (this->MocOrUicEnabled() || (this->Rcc.Enabled && this->MultiConfig)) { - this->GenTarget->AddIncludeDirectory(this->Dir.IncludeGenExp, true); + auto addBefore = false; + auto const& value = + this->GenTarget->GetProperty("AUTOGEN_USE_SYSTEM_INCLUDE"); + if (value.IsSet()) { + if (cmIsOn(value)) { + this->GenTarget->AddSystemIncludeDirectory(this->Dir.IncludeGenExp, + "CXX"); + } else { + addBefore = true; + } + } else { + addBefore = true; + } + this->GenTarget->AddIncludeDirectory(this->Dir.IncludeGenExp, addBefore); } // Scan files diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 4f14648..c156f69 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -546,6 +546,7 @@ TargetProperty const StaticTargetProperties[] = { // -- Autogen { "AUTOGEN_ORIGIN_DEPENDS"_s, IC::CanCompileSources }, { "AUTOGEN_PARALLEL"_s, IC::CanCompileSources }, + { "AUTOGEN_USE_SYSTEM_INCLUDE"_s, IC::CanCompileSources }, // -- moc { "AUTOMOC_DEPEND_FILTERS"_s, IC::CanCompileSources }, // -- C++ diff --git a/Tests/QtAutogen/GlobalAutogenSystemUseInclude/CMakeLists.txt b/Tests/QtAutogen/GlobalAutogenSystemUseInclude/CMakeLists.txt new file mode 100644 index 0000000..1095fb1 --- /dev/null +++ b/Tests/QtAutogen/GlobalAutogenSystemUseInclude/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.26) +project(GlobalAutogenSystemUseInclude) + +include("../AutogenCoreTest.cmake") + +block() + set(test_autogen_use_system_include ON) + set(CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE ${test_autogen_use_system_include}) + + add_executable(autogen_test_on main.cpp) + get_target_property(target_autogen_use_system_include autogen_test_on AUTOGEN_USE_SYSTEM_INCLUDE) + + if(NOT ${CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE} STREQUAL ${target_autogen_use_system_include}) + message(FATAL_ERROR "CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE not set") + endif() +endblock() + +block() + set(test_autogen_use_system_include OFF) + set(CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE ${test_autogen_use_system_include}) + + add_executable(autogen_test_off main.cpp) + get_target_property(target_autogen_use_system_include autogen_test_off AUTOGEN_USE_SYSTEM_INCLUDE) + + if(NOT ${CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE} STREQUAL ${target_autogen_use_system_include}) + message(FATAL_ERROR "CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE not set") + endif() +endblock() diff --git a/Tests/QtAutogen/GlobalAutogenSystemUseInclude/main.cpp b/Tests/QtAutogen/GlobalAutogenSystemUseInclude/main.cpp new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/QtAutogen/GlobalAutogenSystemUseInclude/main.cpp @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/QtAutogen/Tests.cmake b/Tests/QtAutogen/Tests.cmake index cdce2b1..3e4f04d 100644 --- a/Tests/QtAutogen/Tests.cmake +++ b/Tests/QtAutogen/Tests.cmake @@ -3,6 +3,7 @@ ADD_AUTOGEN_TEST(AutogenOriginDependsOff autogenOriginDependsOff) ADD_AUTOGEN_TEST(AutogenOriginDependsOn) ADD_AUTOGEN_TEST(AutogenTargetDepends) ADD_AUTOGEN_TEST(Complex QtAutogen) +ADD_AUTOGEN_TEST(GlobalAutogenSystemUseInclude) ADD_AUTOGEN_TEST(GlobalAutogenTarget) ADD_AUTOGEN_TEST(GlobalAutogenExecutable) ADD_AUTOGEN_TEST(LowMinimumVersion lowMinimumVersion) diff --git a/Tests/RunCMake/Autogen/AutogenUseSystemIncludeCommon.cmake b/Tests/RunCMake/Autogen/AutogenUseSystemIncludeCommon.cmake new file mode 100644 index 0000000..bbefd5f --- /dev/null +++ b/Tests/RunCMake/Autogen/AutogenUseSystemIncludeCommon.cmake @@ -0,0 +1,10 @@ +enable_language(CXX) + +find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets Gui) + +set(CMAKE_AUTOMOC ON) + +add_library(dummy SHARED empty.cpp) +target_link_libraries(dummy Qt${with_qt_version}::Core + Qt${with_qt_version}::Widgets + Qt${with_qt_version}::Gui) diff --git a/Tests/RunCMake/Autogen/AutogenUseSystemIncludeOff.cmake b/Tests/RunCMake/Autogen/AutogenUseSystemIncludeOff.cmake new file mode 100644 index 0000000..dfdbb98 --- /dev/null +++ b/Tests/RunCMake/Autogen/AutogenUseSystemIncludeOff.cmake @@ -0,0 +1,3 @@ +include("${CMAKE_CURRENT_LIST_DIR}/AutogenUseSystemIncludeCommon.cmake") + +set_target_properties(dummy PROPERTIES AUTOGEN_USE_SYSTEM_INCLUDE OFF) diff --git a/Tests/RunCMake/Autogen/AutogenUseSystemIncludeOn.cmake b/Tests/RunCMake/Autogen/AutogenUseSystemIncludeOn.cmake new file mode 100644 index 0000000..f556ed4 --- /dev/null +++ b/Tests/RunCMake/Autogen/AutogenUseSystemIncludeOn.cmake @@ -0,0 +1,3 @@ +include("${CMAKE_CURRENT_LIST_DIR}/AutogenUseSystemIncludeCommon.cmake") + +set_target_properties(dummy PROPERTIES AUTOGEN_USE_SYSTEM_INCLUDE ON) diff --git a/Tests/RunCMake/Autogen/Inspect.cmake b/Tests/RunCMake/Autogen/Inspect.cmake new file mode 100644 index 0000000..d5dc4b4 --- /dev/null +++ b/Tests/RunCMake/Autogen/Inspect.cmake @@ -0,0 +1,13 @@ +enable_language(CXX) + +set(info "") +foreach(var + CMAKE_INCLUDE_FLAG_CXX + CMAKE_INCLUDE_SYSTEM_FLAG_CXX + ) + if(DEFINED ${var}) + string(APPEND info "set(${var} \"${${var}}\")\n") + endif() +endforeach() + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "${info}") diff --git a/Tests/RunCMake/Autogen/RunCMakeTest.cmake b/Tests/RunCMake/Autogen/RunCMakeTest.cmake index 6a3c49b..2f2b645 100644 --- a/Tests/RunCMake/Autogen/RunCMakeTest.cmake +++ b/Tests/RunCMake/Autogen/RunCMakeTest.cmake @@ -22,4 +22,52 @@ if (DEFINED with_qt_version) set(RunCMake_TEST_NO_CLEAN 1) run_cmake_command(MocPredefs-build ${CMAKE_COMMAND} --build . --config Debug) endblock() + + # Detect information from the toolchain: + # - CMAKE_INCLUDE_FLAG_CXX + # - CMAKE_INCLUDE_SYSTEM_FLAG_CXX + run_cmake(Inspect) + include("${RunCMake_BINARY_DIR}/Inspect-build/info.cmake") + + if(CMAKE_INCLUDE_SYSTEM_FLAG_CXX) + if(RunCMake_GENERATOR MATCHES "Visual Studio") + string(REGEX REPLACE "^-" "/" test_expect_stdout "${CMAKE_INCLUDE_SYSTEM_FLAG_CXX}") + else() + set(test_expect_stdout "-*${CMAKE_INCLUDE_SYSTEM_FLAG_CXX}") + endif() + string(APPEND test_expect_stdout " *(\"[^\"]*|([^ ]|\\ )*)[\\/]dummy_autogen[\\/]include") + if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + string(APPEND test_expect_stdout "_Debug") + endif() + + block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/AutogenUseSystemIncludeOn-build) + run_cmake(AutogenUseSystemIncludeOn) + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_TEST_EXPECT_stdout "${test_expect_stdout}") + message(STATUS "RunCMake_TEST_EXPECT_stdout: ${RunCMake_TEST_EXPECT_stdout}") + run_cmake_command(AutogenUseSystemIncludeOn ${CMAKE_COMMAND} --build . --config Debug --verbose) + endblock() + endif() + + if(CMAKE_INCLUDE_FLAG_CXX) + if(RunCMake_GENERATOR MATCHES "Visual Studio") + string(REGEX REPLACE "^-" "/" test_expect_stdout "${CMAKE_INCLUDE_FLAG_CXX}") + else() + set(test_expect_stdout "-*${CMAKE_INCLUDE_FLAG_CXX}") + endif() + string(APPEND test_expect_stdout " *(\"[^\"]*|([^ ]|\\ )*)[\\/]dummy_autogen[\\/]include") + if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + string(APPEND test_expect_stdout "_Debug") + endif() + + block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/AutogenUseSystemIncludeOff-build) + run_cmake(AutogenUseSystemIncludeOff) + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_TEST_EXPECT_stdout "${test_expect_stdout}") + message(STATUS "RunCMake_TEST_EXPECT_stdout: ${RunCMake_TEST_EXPECT_stdout}") + run_cmake_command(AutogenUseSystemIncludeOff ${CMAKE_COMMAND} --build . --config Debug --verbose) + endblock() + endif() endif () -- cgit v0.12 From 7bf4e3009000b0ab576f364abc779e9a1599af08 Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Thu, 27 Apr 2023 11:28:30 +0200 Subject: Autogen: Default AUTOGEN_USE_SYSTEM_INCLUDE to ON if it is not set Add policy CMP0151 to preserve the old behavior by default. --- Help/manual/cmake-policies.7.rst | 1 + Help/policy/CMP0151.rst | 28 ++++++++++++++++++++++++++++ Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst | 3 +++ Source/cmPolicies.h | 4 ++++ Source/cmQtAutoGenInitializer.cxx | 13 ++++++++++++- Tests/RunCMake/Autogen/CMP0151-common.cmake | 10 ++++++++++ Tests/RunCMake/Autogen/CMP0151-new.cmake | 1 + Tests/RunCMake/Autogen/CMP0151-old.cmake | 1 + Tests/RunCMake/Autogen/RunCMakeTest.cmake | 22 ++++++++++++++++++++-- 9 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 Help/policy/CMP0151.rst create mode 100644 Tests/RunCMake/Autogen/CMP0151-common.cmake create mode 100644 Tests/RunCMake/Autogen/CMP0151-new.cmake create mode 100644 Tests/RunCMake/Autogen/CMP0151-old.cmake diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst index ff57390..7c48806 100644 --- a/Help/manual/cmake-policies.7.rst +++ b/Help/manual/cmake-policies.7.rst @@ -57,6 +57,7 @@ Policies Introduced by CMake 3.27 .. toctree:: :maxdepth: 1 + CMP0151: AUTOMOC include directory is a system include directory by default. CMP0150: ExternalProject_Add and FetchContent_Declare treat relative git repository paths as being relative to parent project's remote. CMP0149: Visual Studio generators select latest Windows SDK by default. CMP0148: The FindPythonInterp and FindPythonLibs modules are removed. diff --git a/Help/policy/CMP0151.rst b/Help/policy/CMP0151.rst new file mode 100644 index 0000000..c12f595 --- /dev/null +++ b/Help/policy/CMP0151.rst @@ -0,0 +1,28 @@ +CMP0151 +------- + +.. versionadded:: 3.27 + +AUTOMOC include directory is a system include directory by default. + +Headers generated for :ref:`Qt AUTOMOC` are placed in target-specific include +directories. CMake 3.26 and older added these as normal include directories. +CMake 3.27 and newer prefer to add them as system include directories. +This policy provides compatibility for projects that have not been updated +to expect this. + +If the :prop_tgt:`AUTOGEN_USE_SYSTEM_INCLUDE` target property is set, +perhaps via the :variable:`CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE` variable, +then its value is used regardless of the setting of this policy. + +The ``OLD`` behavior for this policy is to add autogen include directory to +the target's include directories. +The ``NEW`` behavior for this policy is to add autogen include directory to +the target's system include directories. + +This policy was introduced in CMake version 3.27. Use the +:command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly. +Unlike many policies, CMake version |release| does *not* warn +when this policy is not set and simply uses ``OLD`` behavior. + +.. include:: DEPRECATED.txt diff --git a/Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst b/Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst index fd21070..84212c8 100644 --- a/Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst +++ b/Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst @@ -6,6 +6,9 @@ on a target to indicate that the autogen target include directory should be added as a system include directory or normal include directory to the target. +If this property is not set, the autogen target include directory is added +as a system include directory by default. See policy :policy:`CMP0151`. + See the :manual:`cmake-qt(7)` manual for more information on using CMake with Qt. diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 23e50a9..a0030d3 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -455,6 +455,10 @@ class cmMakefile; "ExternalProject_Add and FetchContent_Declare commands " \ "treat relative GIT_REPOSITORY paths as being relative " \ "to the parent project's remote.", \ + 3, 27, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0151, \ + "AUTOMOC include directory is a system include directory by " \ + "default.", \ 3, 27, 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index deb2c04..544e1ef 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -587,7 +587,18 @@ bool cmQtAutoGenInitializer::InitCustomTargets() addBefore = true; } } else { - addBefore = true; + switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0151)) { + case cmPolicies::WARN: + case cmPolicies::OLD: + addBefore = true; + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + this->GenTarget->AddSystemIncludeDirectory(this->Dir.IncludeGenExp, + "CXX"); + break; + } } this->GenTarget->AddIncludeDirectory(this->Dir.IncludeGenExp, addBefore); } diff --git a/Tests/RunCMake/Autogen/CMP0151-common.cmake b/Tests/RunCMake/Autogen/CMP0151-common.cmake new file mode 100644 index 0000000..bbefd5f --- /dev/null +++ b/Tests/RunCMake/Autogen/CMP0151-common.cmake @@ -0,0 +1,10 @@ +enable_language(CXX) + +find_package(Qt${with_qt_version} REQUIRED COMPONENTS Core Widgets Gui) + +set(CMAKE_AUTOMOC ON) + +add_library(dummy SHARED empty.cpp) +target_link_libraries(dummy Qt${with_qt_version}::Core + Qt${with_qt_version}::Widgets + Qt${with_qt_version}::Gui) diff --git a/Tests/RunCMake/Autogen/CMP0151-new.cmake b/Tests/RunCMake/Autogen/CMP0151-new.cmake new file mode 100644 index 0000000..9c77e58 --- /dev/null +++ b/Tests/RunCMake/Autogen/CMP0151-new.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/CMP0151-common.cmake") diff --git a/Tests/RunCMake/Autogen/CMP0151-old.cmake b/Tests/RunCMake/Autogen/CMP0151-old.cmake new file mode 100644 index 0000000..9c77e58 --- /dev/null +++ b/Tests/RunCMake/Autogen/CMP0151-old.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/CMP0151-common.cmake") diff --git a/Tests/RunCMake/Autogen/RunCMakeTest.cmake b/Tests/RunCMake/Autogen/RunCMakeTest.cmake index 2f2b645..4505132 100644 --- a/Tests/RunCMake/Autogen/RunCMakeTest.cmake +++ b/Tests/RunCMake/Autogen/RunCMakeTest.cmake @@ -41,8 +41,17 @@ if (DEFINED with_qt_version) endif() block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0151-new-build) + run_cmake_with_options(CMP0151-new ${RunCMake_TEST_OPTIONS} -DCMAKE_POLICY_DEFAULT_CMP0151=NEW) + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_TEST_EXPECT_stdout "${test_expect_stdout}") + message(STATUS "RunCMake_TEST_EXPECT_stdout: ${RunCMake_TEST_EXPECT_stdout}") + run_cmake_command(CMP0151-new-build ${CMAKE_COMMAND} --build . --config Debug --verbose) + endblock() + + block() set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/AutogenUseSystemIncludeOn-build) - run_cmake(AutogenUseSystemIncludeOn) + run_cmake_with_options(AutogenUseSystemIncludeOn ${RunCMake_TEST_OPTIONS} -DCMAKE_POLICY_DEFAULT_CMP0151=NEW) set(RunCMake_TEST_NO_CLEAN 1) set(RunCMake_TEST_EXPECT_stdout "${test_expect_stdout}") message(STATUS "RunCMake_TEST_EXPECT_stdout: ${RunCMake_TEST_EXPECT_stdout}") @@ -62,8 +71,17 @@ if (DEFINED with_qt_version) endif() block() + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0151-old-build) + run_cmake_with_options(CMP0151-old ${RunCMake_TEST_OPTIONS} -DCMAKE_POLICY_DEFAULT_CMP0151=OLD) + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_TEST_EXPECT_stdout "${test_expect_stdout}") + message(STATUS "RunCMake_TEST_EXPECT_stdout: ${RunCMake_TEST_EXPECT_stdout}") + run_cmake_command(CMP0151-old-build ${CMAKE_COMMAND} --build . --config Debug --verbose) + endblock() + + block() set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/AutogenUseSystemIncludeOff-build) - run_cmake(AutogenUseSystemIncludeOff) + run_cmake_with_options(AutogenUseSystemIncludeOff ${RunCMake_TEST_OPTIONS} -DCMAKE_POLICY_DEFAULT_CMP0151=NEW) set(RunCMake_TEST_NO_CLEAN 1) set(RunCMake_TEST_EXPECT_stdout "${test_expect_stdout}") message(STATUS "RunCMake_TEST_EXPECT_stdout: ${RunCMake_TEST_EXPECT_stdout}") -- cgit v0.12