summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Auxiliary/vim/syntax/cmake.vim2
-rw-r--r--Help/manual/cmake-properties.7.rst1
-rw-r--r--Help/manual/cmake-variables.7.rst1
-rw-r--r--Help/prop_tgt/AUTOGEN_USE_SYSTEM_INCLUDE.rst14
-rw-r--r--Help/release/dev/autogen-system-include.rst7
-rw-r--r--Help/variable/CMAKE_AUTOGEN_USE_SYSTEM_INCLUDE.rst10
-rw-r--r--Source/cmGeneratorTarget.cxx23
-rw-r--r--Source/cmGeneratorTarget.h2
-rw-r--r--Source/cmQtAutoGenInitializer.cxx15
-rw-r--r--Source/cmTarget.cxx1
-rw-r--r--Tests/QtAutogen/GlobalAutogenSystemUseInclude/CMakeLists.txt28
-rw-r--r--Tests/QtAutogen/GlobalAutogenSystemUseInclude/main.cpp4
-rw-r--r--Tests/QtAutogen/Tests.cmake1
-rw-r--r--Tests/RunCMake/Autogen/AutogenUseSystemIncludeCommon.cmake10
-rw-r--r--Tests/RunCMake/Autogen/AutogenUseSystemIncludeOff.cmake3
-rw-r--r--Tests/RunCMake/Autogen/AutogenUseSystemIncludeOn.cmake3
-rw-r--r--Tests/RunCMake/Autogen/Inspect.cmake13
-rw-r--r--Tests/RunCMake/Autogen/RunCMakeTest.cmake48
18 files changed, 185 insertions, 1 deletions
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<std::string>(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);
+ 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<cmSourceFile*> 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<std::string> 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 ()