Merge topic 'system-include-cache'

fb978f001d GeneratorTarget: Fix missing system include cache key
7d8d239574 GeneratorTarget: Factor out AddSystemIncludeCacheKey()

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9681
This commit is contained in:
Brad King
2024-07-24 14:05:34 +00:00
committed by Kitware Robot
4 changed files with 116 additions and 95 deletions

View File

@@ -585,6 +585,10 @@ void cmGeneratorTarget::AddSystemIncludeDirectory(std::string const& inc,
}
auto const& key = cmStrCat(config_upper, "/", lang);
this->Target->AddSystemIncludeDirectories({ inc_with_config });
if (this->SystemIncludesCache.find(key) ==
this->SystemIncludesCache.end()) {
this->AddSystemIncludeCacheKey(key, config, lang);
}
this->SystemIncludesCache[key].emplace_back(inc_with_config);
// SystemIncludesCache should be sorted so that binary search can be used
@@ -1163,6 +1167,51 @@ const std::string& cmGeneratorTarget::GetLocationForBuild() const
return location;
}
void cmGeneratorTarget::AddSystemIncludeCacheKey(
const std::string& key, const std::string& config,
const std::string& language) const
{
cmGeneratorExpressionDAGChecker dagChecker(
this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr, this->LocalGenerator,
config);
bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
cmList result;
for (std::string const& it : this->Target->GetSystemIncludeDirectories()) {
result.append(cmGeneratorExpression::Evaluate(
it, this->LocalGenerator, config, this, &dagChecker, nullptr, language));
}
std::vector<cmGeneratorTarget const*> const& deps =
this->GetLinkImplementationClosure(config, UseTo::Compile);
for (cmGeneratorTarget const* dep : deps) {
handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
&dagChecker, result, excludeImported, language);
}
cmLinkImplementation const* impl =
this->GetLinkImplementation(config, UseTo::Compile);
if (impl != nullptr) {
auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language);
if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) {
for (auto const& lib : runtimeEntries->second) {
if (lib.Target) {
handleSystemIncludesDep(this->LocalGenerator, lib.Target, config,
this, &dagChecker, result, excludeImported,
language);
}
}
}
}
std::for_each(result.begin(), result.end(),
cmSystemTools::ConvertToUnixSlashes);
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
SystemIncludesCache.emplace(key, result);
}
bool cmGeneratorTarget::IsSystemIncludeDirectory(
const std::string& dir, const std::string& config,
const std::string& language) const
@@ -1176,47 +1225,8 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(
auto iter = this->SystemIncludesCache.find(key);
if (iter == this->SystemIncludesCache.end()) {
cmGeneratorExpressionDAGChecker dagChecker(
this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr,
this->LocalGenerator, config);
bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
cmList result;
for (std::string const& it : this->Target->GetSystemIncludeDirectories()) {
result.append(cmGeneratorExpression::Evaluate(it, this->LocalGenerator,
config, this, &dagChecker,
nullptr, language));
}
std::vector<cmGeneratorTarget const*> const& deps =
this->GetLinkImplementationClosure(config, UseTo::Compile);
for (cmGeneratorTarget const* dep : deps) {
handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
&dagChecker, result, excludeImported, language);
}
cmLinkImplementation const* impl =
this->GetLinkImplementation(config, UseTo::Compile);
if (impl != nullptr) {
auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language);
if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) {
for (auto const& lib : runtimeEntries->second) {
if (lib.Target) {
handleSystemIncludesDep(this->LocalGenerator, lib.Target, config,
this, &dagChecker, result, excludeImported,
language);
}
}
}
}
std::for_each(result.begin(), result.end(),
cmSystemTools::ConvertToUnixSlashes);
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
iter = this->SystemIncludesCache.emplace(key, result).first;
this->AddSystemIncludeCacheKey(key, config, language);
iter = this->SystemIncludesCache.find(key);
}
return std::binary_search(iter->second.begin(), iter->second.end(), dir);

View File

@@ -656,6 +656,10 @@ public:
const std::string& config,
const std::string& language) const;
void AddSystemIncludeCacheKey(const std::string& key,
const std::string& config,
const std::string& language) const;
/** Add the target output files to the global generator manifest. */
void ComputeTargetManifest(const std::string& config) const;

View File

@@ -2,8 +2,6 @@ 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

View File

@@ -28,62 +28,71 @@ if (DEFINED with_qt_version)
# - 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()
foreach(autogen_type IN ITEMS MOC UIC)
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}")
run_cmake_command(CMP0151-new-build ${CMAKE_COMMAND} --build . --config Debug --verbose)
endblock()
set(RunCMake_TEST_VARIANT_DESCRIPTION "-AUTO${autogen_type}=ON")
if(CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
if(RunCMake_GENERATOR MATCHES "Visual Studio")
string(REGEX REPLACE "^-" "/" test_expect_stdout_common "${CMAKE_INCLUDE_SYSTEM_FLAG_CXX}")
else()
set(test_expect_stdout_common "-*${CMAKE_INCLUDE_SYSTEM_FLAG_CXX}")
endif()
set(test_expect_stdout_1 "${test_expect_stdout_common}")
set(test_expect_stdout_2 "${test_expect_stdout_common}")
string(APPEND test_expect_stdout_1 " *(\"[^\"]*|([^ ]|\\ )*)[\\/]dummy_autogen[\\/]include")
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
string(APPEND test_expect_stdout_1 "_Debug")
endif()
string(APPEND test_expect_stdout_2 " *(\"[^\"]*|([^ ]|\\ )*)[\\/]QtCore")
set(test_expect_stdout "${test_expect_stdout_1}.*${test_expect_stdout_2}")
block()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/AutogenUseSystemIncludeOn-build)
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}")
run_cmake_command(AutogenUseSystemIncludeOn ${CMAKE_COMMAND} --build . --config Debug --verbose)
endblock()
endif()
block()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0151-new-build)
run_cmake_with_options(CMP0151-new ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTO${autogen_type}=ON -DCMAKE_POLICY_DEFAULT_CMP0151=NEW)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_EXPECT_stdout "${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_with_options(AutogenUseSystemIncludeOn ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTO${autogen_type}=ON -DCMAKE_POLICY_DEFAULT_CMP0151=NEW)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_EXPECT_stdout "${test_expect_stdout}")
run_cmake_command(AutogenUseSystemIncludeOn-build ${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}/CMP0151-old-build)
run_cmake_with_options(CMP0151-old ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTO${autogen_type}=ON -DCMAKE_POLICY_DEFAULT_CMP0151=OLD)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_EXPECT_stdout "${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_with_options(AutogenUseSystemIncludeOff ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTO${autogen_type}=ON -DCMAKE_POLICY_DEFAULT_CMP0151=NEW)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_EXPECT_stdout "${test_expect_stdout}")
run_cmake_command(AutogenUseSystemIncludeOff-build ${CMAKE_COMMAND} --build . --config Debug --verbose)
endblock()
endif()
endblock()
endforeach()
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}/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}")
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_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}")
run_cmake_command(AutogenUseSystemIncludeOff ${CMAKE_COMMAND} --build . --config Debug --verbose)
endblock()
if(RunCMake_GENERATOR MATCHES "Make|Ninja")
block()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/AutogenSkipLinting-build)