summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-05-30 09:27:17 -0400
committerBrad King <brad.king@kitware.com>2019-05-30 09:27:17 -0400
commit540a175d2059e59fc0c5c8b8d5812c89639b27e3 (patch)
treef81588c7279b977b6547e3d5284da91a8fd0244e
parentf07d42632bd4f29eda871de12ebb5f03f9d4edda (diff)
parent2d0b0e2b9d50aa14ccf345c727b2da73dfba9bd6 (diff)
downloadcmake-540a175d2059e59fc0c5c8b8d5812c89639b27e3.tar.gz
Merge branch 'implicit-includes-CPATH' into release-3.14
Merge-request: !3395
-rw-r--r--Help/release/3.14.rst8
-rw-r--r--Source/cmLocalGenerator.cxx28
-rw-r--r--Source/cmLocalGenerator.h2
-rw-r--r--Tests/CMakeLists.txt18
-rw-r--r--Tests/IncludeDirectoriesCPATH/CMakeLists.txt22
-rw-r--r--Tests/IncludeDirectoriesCPATH/consumer.cpp6
-rw-r--r--Tests/IncludeDirectoriesCPATH/viacpath/systemlib.h15
7 files changed, 96 insertions, 3 deletions
diff --git a/Help/release/3.14.rst b/Help/release/3.14.rst
index 8a251bd18e..e3a7a62fbf 100644
--- a/Help/release/3.14.rst
+++ b/Help/release/3.14.rst
@@ -412,3 +412,11 @@ Changes made since CMake 3.14.0 include the following.
incorrectly propagate usage requirements of those dependencies to
dependents that link the static library. This has been fixed.
The bug also existed in 3.13.0 through 3.13.4 and is fixed in 3.13.5.
+
+3.14.5
+------
+
+* Entries of the ``CPATH`` environment variable are no longer excluded
+ from explicit use via :command:`include_directories` and
+ :command:`target_include_directories` as they were in CMake 3.14.0
+ through 3.14.4.
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 7e15234563..f6962d160c 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -88,6 +88,19 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
this->ComputeObjectMaxPath();
+ // Canonicalize entries of the CPATH environment variable the same
+ // way detection of CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES does.
+ {
+ std::vector<std::string> cpath;
+ cmSystemTools::GetPath(cpath, "CPATH");
+ for (std::string& cp : cpath) {
+ if (cmSystemTools::FileIsFullPath(cp)) {
+ cp = cmSystemTools::CollapseFullPath(cp);
+ this->EnvCPATH.emplace(std::move(cp));
+ }
+ }
+ }
+
std::vector<std::string> enabledLanguages =
this->GetState()->GetEnabledLanguages();
@@ -988,9 +1001,18 @@ std::vector<BT<std::string>> cmLocalGenerator::GetIncludeDirectoriesImplicit(
}
// Checks if this is not an excluded (implicit) include directory.
- auto notExcluded = [&implicitSet, &implicitExclude](std::string const& dir) {
- return ((implicitSet.find(dir) == implicitSet.end()) &&
- (implicitExclude.find(dir) == implicitExclude.end()));
+ auto notExcluded = [this, &implicitSet, &implicitExclude,
+ &lang](std::string const& dir) {
+ return (
+ // Do not exclude directories that are not in an excluded set.
+ ((implicitSet.find(dir) == implicitSet.end()) &&
+ (implicitExclude.find(dir) == implicitExclude.end()))
+ // Do not exclude entries of the CPATH environment variable even though
+ // they are implicitly searched by the compiler. They are meant to be
+ // user-specified directories that can be re-ordered or converted to
+ // -isystem without breaking real compiler builtin headers.
+ || ((lang == "C" || lang == "CXX") &&
+ (this->EnvCPATH.find(dir) != this->EnvCPATH.end())));
};
// Get the target-specific include directories.
diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h
index f9839f6c19..9521ec5b80 100644
--- a/Source/cmLocalGenerator.h
+++ b/Source/cmLocalGenerator.h
@@ -429,6 +429,8 @@ protected:
std::string::size_type ObjectPathMax;
std::set<std::string> ObjectMaxPathViolations;
+ std::set<std::string> EnvCPATH;
+
typedef std::unordered_map<std::string, cmGeneratorTarget*>
GeneratorTargetMap;
GeneratorTargetMap GeneratorTargetSearchIndex;
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 431a4921e2..588c8e0d22 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -3620,6 +3620,24 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
--test-command IncludeDirectories)
list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/IncludeDirectories")
+ if(CMAKE_GENERATOR MATCHES "^((Unix|MSYS) Makefiles|Ninja)$" AND
+ ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
+ OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+ OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")))
+ add_test(IncludeDirectoriesCPATH ${CMAKE_CTEST_COMMAND}
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/IncludeDirectoriesCPATH"
+ "${CMake_BINARY_DIR}/Tests/IncludeDirectoriesCPATH"
+ --build-two-config
+ ${build_generator_args}
+ --build-project IncludeDirectoriesCPATH
+ --build-options ${build_options})
+ list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/IncludeDirectoriesCPATH")
+ set_tests_properties(IncludeDirectoriesCPATH
+ PROPERTIES
+ ENVIRONMENT "CPATH=${CMAKE_CURRENT_SOURCE_DIR}/IncludeDirectoriesCPATH/viacpath")
+ endif()
+
add_test(InterfaceLinkLibraries ${CMAKE_CTEST_COMMAND}
--build-and-test
"${CMake_SOURCE_DIR}/Tests/InterfaceLinkLibraries"
diff --git a/Tests/IncludeDirectoriesCPATH/CMakeLists.txt b/Tests/IncludeDirectoriesCPATH/CMakeLists.txt
new file mode 100644
index 0000000000..31cbc3680a
--- /dev/null
+++ b/Tests/IncludeDirectoriesCPATH/CMakeLists.txt
@@ -0,0 +1,22 @@
+cmake_minimum_required (VERSION 3.14)
+project(IncludeDirectoriesCPATH CXX)
+message(STATUS "ENV{CPATH}: '$ENV{CPATH}'")
+message(STATUS "CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES: '${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}'")
+
+include(CheckCXXCompilerFlag)
+check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test)
+if(run_sys_includes_test)
+ # The Bullseye wrapper appears to break the -isystem effect.
+ execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE out ERROR_VARIABLE out)
+ if("x${out}" MATCHES "Bullseye")
+ set(run_sys_includes_test 0)
+ endif()
+endif()
+if (NOT run_sys_includes_test)
+ return()
+endif()
+
+add_library(consumer consumer.cpp)
+add_library(consumer_system consumer.cpp)
+target_compile_options(consumer_system PRIVATE -Werror=unused-variable)
+target_include_directories(consumer_system SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/viacpath")
diff --git a/Tests/IncludeDirectoriesCPATH/consumer.cpp b/Tests/IncludeDirectoriesCPATH/consumer.cpp
new file mode 100644
index 0000000000..59608dada2
--- /dev/null
+++ b/Tests/IncludeDirectoriesCPATH/consumer.cpp
@@ -0,0 +1,6 @@
+#include "systemlib.h"
+
+int consumer()
+{
+ return systemlib();
+}
diff --git a/Tests/IncludeDirectoriesCPATH/viacpath/systemlib.h b/Tests/IncludeDirectoriesCPATH/viacpath/systemlib.h
new file mode 100644
index 0000000000..1aaafa9f40
--- /dev/null
+++ b/Tests/IncludeDirectoriesCPATH/viacpath/systemlib.h
@@ -0,0 +1,15 @@
+#ifndef SYSTEMLIB_H
+#define SYSTEMLIB_H
+
+int systemlib()
+{
+ return 0;
+}
+
+int unusedFunc()
+{
+ int unused;
+ return systemlib();
+}
+
+#endif