cmGeneratorTarget: Include Cache now occurs per language+config

Previously only occurred per config which broke per-language
system includes.
This commit is contained in:
Robert Maynard
2020-09-25 12:00:02 -04:00
parent 0cd1ef0932
commit b6418155f3
7 changed files with 50 additions and 4 deletions

View File

@@ -1195,8 +1195,8 @@ bool cmGeneratorTarget::IsSystemIncludeDirectory(
config_upper = cmSystemTools::UpperCase(config);
}
using IncludeCacheType = std::map<std::string, std::vector<std::string>>;
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);

View File

@@ -849,6 +849,8 @@ private:
mutable std::set<std::string> VisitedConfigsForObjects;
mutable std::map<cmSourceFile const*, std::string> Objects;
std::set<cmSourceFile const*> ExplicitObjectName;
// "config/language" is the key
mutable std::map<std::string, std::vector<std::string>> SystemIncludesCache;
mutable std::string ExportMacro;

View File

@@ -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()

View File

@@ -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 "$<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}>"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}>"
)
target_compile_options(c_interface INTERFACE "$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=unused-variable>")
add_library(cxx_interface INTERFACE)
set_target_properties(cxx_interface PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_system_include>"
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_system_include>"
)
target_compile_options(cxx_interface INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang>:-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)

View File

@@ -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;
}

View File

@@ -0,0 +1,4 @@
int main()
{
return 0;
}

View File

@@ -0,0 +1,7 @@
#include <header.h>
int empty_func()
{
return function_that_generates_warning(4);
}