mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 22:37:30 +08:00
Restore support for include_directories() in toolchain files
Any `include_directories()` calls in toolchain files are used during our
ABI detection step even though it does not include any system headers.
Since commit 5990ecb741
(Compute implicit include directories from
compiler output, 2018-12-07, v3.14.0-rc1~108^2), that check is also used
to detect implicit include directories. Any `include_directories()` in
a toolchain file are detected as implicit and later excluded from
explicit specification on compiler command lines, thus breaking the
purpose of the calls in the first place.
Fix the implicit include directory detection step to avoid using paths
from `include_directories()` calls in the toolchain file.
Fixes: #19079
This commit is contained in:
@@ -51,6 +51,7 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src)
|
|||||||
OUTPUT_VARIABLE OUTPUT
|
OUTPUT_VARIABLE OUTPUT
|
||||||
COPY_FILE "${BIN}"
|
COPY_FILE "${BIN}"
|
||||||
COPY_FILE_ERROR _copy_error
|
COPY_FILE_ERROR _copy_error
|
||||||
|
__CMAKE_INTERNAL ABI
|
||||||
)
|
)
|
||||||
|
|
||||||
# Restore original LC_ALL, LC_MESSAGES, and LANG
|
# Restore original LC_ALL, LC_MESSAGES, and LANG
|
||||||
|
@@ -123,6 +123,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
std::string targetName;
|
std::string targetName;
|
||||||
std::vector<std::string> cmakeFlags(1, "CMAKE_FLAGS"); // fake argv[0]
|
std::vector<std::string> cmakeFlags(1, "CMAKE_FLAGS"); // fake argv[0]
|
||||||
std::vector<std::string> compileDefs;
|
std::vector<std::string> compileDefs;
|
||||||
|
std::string cmakeInternal;
|
||||||
std::string outputVariable;
|
std::string outputVariable;
|
||||||
std::string copyFile;
|
std::string copyFile;
|
||||||
std::string copyFileError;
|
std::string copyFileError;
|
||||||
@@ -174,7 +175,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
DoingCExtensions,
|
DoingCExtensions,
|
||||||
DoingCxxExtensions,
|
DoingCxxExtensions,
|
||||||
DoingCudaExtensions,
|
DoingCudaExtensions,
|
||||||
DoingSources
|
DoingSources,
|
||||||
|
DoingCMakeInternal
|
||||||
};
|
};
|
||||||
Doing doing = useSources ? DoingSources : DoingNone;
|
Doing doing = useSources ? DoingSources : DoingNone;
|
||||||
for (size_t i = 3; i < argv.size(); ++i) {
|
for (size_t i = 3; i < argv.size(); ++i) {
|
||||||
@@ -223,6 +225,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
} else if (argv[i] == "CUDA_EXTENSIONS") {
|
} else if (argv[i] == "CUDA_EXTENSIONS") {
|
||||||
doing = DoingCudaExtensions;
|
doing = DoingCudaExtensions;
|
||||||
didCudaExtensions = true;
|
didCudaExtensions = true;
|
||||||
|
} else if (argv[i] == "__CMAKE_INTERNAL") {
|
||||||
|
doing = DoingCMakeInternal;
|
||||||
} else if (doing == DoingCMakeFlags) {
|
} else if (doing == DoingCMakeFlags) {
|
||||||
cmakeFlags.push_back(argv[i]);
|
cmakeFlags.push_back(argv[i]);
|
||||||
} else if (doing == DoingCompileDefinitions) {
|
} else if (doing == DoingCompileDefinitions) {
|
||||||
@@ -296,6 +300,9 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
doing = DoingNone;
|
doing = DoingNone;
|
||||||
} else if (doing == DoingSources) {
|
} else if (doing == DoingSources) {
|
||||||
sources.push_back(argv[i]);
|
sources.push_back(argv[i]);
|
||||||
|
} else if (doing == DoingCMakeInternal) {
|
||||||
|
cmakeInternal = argv[i];
|
||||||
|
doing = DoingNone;
|
||||||
} else if (i == 3) {
|
} else if (i == 3) {
|
||||||
this->SrcFileSignature = false;
|
this->SrcFileSignature = false;
|
||||||
projectName = argv[i].c_str();
|
projectName = argv[i].c_str();
|
||||||
@@ -508,6 +515,14 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(fout, "project(CMAKE_TRY_COMPILE%s)\n", projectLangs.c_str());
|
fprintf(fout, "project(CMAKE_TRY_COMPILE%s)\n", projectLangs.c_str());
|
||||||
|
if (cmakeInternal == "ABI") {
|
||||||
|
// This is the ABI detection step, also used for implicit includes.
|
||||||
|
// Erase any include_directories() calls from the toolchain file so
|
||||||
|
// that we do not see them as implicit. Our ABI detection source
|
||||||
|
// does not include any system headers anyway.
|
||||||
|
fprintf(fout,
|
||||||
|
"set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES \"\")\n");
|
||||||
|
}
|
||||||
fprintf(fout, "set(CMAKE_VERBOSE_MAKEFILE 1)\n");
|
fprintf(fout, "set(CMAKE_VERBOSE_MAKEFILE 1)\n");
|
||||||
for (std::string const& li : testLangs) {
|
for (std::string const& li : testLangs) {
|
||||||
std::string langFlags = "CMAKE_" + li + "_FLAGS";
|
std::string langFlags = "CMAKE_" + li + "_FLAGS";
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
include_directories(${CMAKE_CURRENT_LIST_DIR}/IncludeDirectories)
|
5
Tests/RunCMake/ToolchainFile/IncludeDirectories.c
Normal file
5
Tests/RunCMake/ToolchainFile/IncludeDirectories.c
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#include <IncDir.h>
|
||||||
|
|
||||||
|
void IncDir(void)
|
||||||
|
{
|
||||||
|
}
|
2
Tests/RunCMake/ToolchainFile/IncludeDirectories.cmake
Normal file
2
Tests/RunCMake/ToolchainFile/IncludeDirectories.cmake
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
enable_language(C)
|
||||||
|
add_library(IncDir STATIC IncludeDirectories.c)
|
1
Tests/RunCMake/ToolchainFile/IncludeDirectories/IncDir.h
Normal file
1
Tests/RunCMake/ToolchainFile/IncludeDirectories/IncDir.h
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/* IncDir.h */
|
@@ -9,3 +9,11 @@ run_cmake_toolchain(CallEnableLanguage)
|
|||||||
run_cmake_toolchain(CallProject)
|
run_cmake_toolchain(CallProject)
|
||||||
run_cmake_toolchain(FlagsInit)
|
run_cmake_toolchain(FlagsInit)
|
||||||
run_cmake_toolchain(LinkFlagsInit)
|
run_cmake_toolchain(LinkFlagsInit)
|
||||||
|
|
||||||
|
function(run_IncludeDirectories)
|
||||||
|
run_cmake_toolchain(IncludeDirectories)
|
||||||
|
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/IncludeDirectories-build)
|
||||||
|
set(RunCMake_TEST_NO_CLEAN 1)
|
||||||
|
run_cmake_command(IncludeDirectories-build ${CMAKE_COMMAND} --build . --config Debug)
|
||||||
|
endfunction()
|
||||||
|
run_IncludeDirectories()
|
||||||
|
Reference in New Issue
Block a user