From b6418155f35ce997eb9f252f63751d76ff7342bf Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 25 Sep 2020 12:00:02 -0400 Subject: cmGeneratorTarget: Include Cache now occurs per language+config Previously only occurred per config which broke per-language system includes. --- Source/cmGeneratorTarget.cxx | 7 +++---- Source/cmGeneratorTarget.h | 2 ++ Tests/IncludeDirectories/CMakeLists.txt | 1 + .../SystemIncludeDirectoriesPerLang/CMakeLists.txt | 23 ++++++++++++++++++++++ .../cxx_system_include/header.h | 10 ++++++++++ .../SystemIncludeDirectoriesPerLang/main.c | 4 ++++ .../smoke_out_includes.cxx | 7 +++++++ 7 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/CMakeLists.txt create mode 100644 Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/cxx_system_include/header.h create mode 100644 Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/main.c create mode 100644 Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/smoke_out_includes.cxx diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 8589ab1..ed36838 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1195,8 +1195,8 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory( config_upper = cmSystemTools::UpperCase(config); } - using IncludeCacheType = std::map>; - auto iter = this->SystemIncludesCache.find(config_upper); + std::string key = cmStrCat(config_upper, "/", language); + auto iter = this->SystemIncludesCache.find(key); if (iter == this->SystemIncludesCache.end()) { cmGeneratorExpressionDAGChecker dagChecker( @@ -1224,8 +1224,7 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory( std::sort(result.begin(), result.end()); result.erase(std::unique(result.begin(), result.end()), result.end()); - IncludeCacheType::value_type entry(config_upper, result); - iter = this->SystemIncludesCache.insert(entry).first; + iter = this->SystemIncludesCache.emplace(key, result).first; } return std::binary_search(iter->second.begin(), iter->second.end(), dir); diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 8e0def7..2390b03 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -849,6 +849,8 @@ private: mutable std::set VisitedConfigsForObjects; mutable std::map Objects; std::set ExplicitObjectName; + + // "config/language" is the key mutable std::map> SystemIncludesCache; mutable std::string ExportMacro; diff --git a/Tests/IncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/CMakeLists.txt index eb08676..1f5b664 100644 --- a/Tests/IncludeDirectories/CMakeLists.txt +++ b/Tests/IncludeDirectories/CMakeLists.txt @@ -17,6 +17,7 @@ if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREA endif() if (run_sys_includes_test) add_subdirectory(SystemIncludeDirectories) + add_subdirectory(SystemIncludeDirectoriesPerLang) endif() endif() diff --git a/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/CMakeLists.txt b/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/CMakeLists.txt new file mode 100644 index 0000000..70dfa01 --- /dev/null +++ b/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.17 FATAL_ERROR) + +project(SystemIncludeDirectoriesPerLang) + +add_library(c_interface INTERFACE) +set_target_properties(c_interface PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "$<$:${CMAKE_CURRENT_SOURCE_DIR}>" + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<$:${CMAKE_CURRENT_SOURCE_DIR}>" +) +target_compile_options(c_interface INTERFACE "$<$:-Werror=unused-variable>") + +add_library(cxx_interface INTERFACE) +set_target_properties(cxx_interface PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "$<$:${CMAKE_CURRENT_SOURCE_DIR}/cxx_system_include>" + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<$:${CMAKE_CURRENT_SOURCE_DIR}/cxx_system_include>" +) +target_compile_options(cxx_interface INTERFACE "$<$:-Werror=unused-variable>") + +# The C header must come before the C++ header for this test to smoke out the +# failure. The order of sources is how CMake determines the include cache +# and we need it to cache on the 'bad' language first +add_executable(consume_multi_lang_includes main.c smoke_out_includes.cxx) +target_link_libraries(consume_multi_lang_includes PRIVATE c_interface cxx_interface) diff --git a/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/cxx_system_include/header.h b/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/cxx_system_include/header.h new file mode 100644 index 0000000..8dcd226 --- /dev/null +++ b/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/cxx_system_include/header.h @@ -0,0 +1,10 @@ + +// Generate a warning in here + +int function_that_generates_warning(int x) +{ + int y = x; + int z = 2; + y -= x; + return y; +} diff --git a/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/main.c b/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/main.c new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/main.c @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/smoke_out_includes.cxx b/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/smoke_out_includes.cxx new file mode 100644 index 0000000..dbfc557 --- /dev/null +++ b/Tests/IncludeDirectories/SystemIncludeDirectoriesPerLang/smoke_out_includes.cxx @@ -0,0 +1,7 @@ + +#include + +int empty_func() +{ + return function_that_generates_warning(4); +} -- cgit v0.12