summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-08-10 15:33:00 +0000
committerKitware Robot <kwrobot@kitware.com>2020-08-10 11:33:19 -0400
commit0953c0051edcf3d4fb103b864fc0a7068dfedf59 (patch)
tree551dea245e9dcc46f078909fa5b5666b7a4e4e9c
parentc65f6a524e3a782877e6747194a92dbf85184999 (diff)
parent20ebaed97235d8397638807ff791803f8bd4e215 (diff)
downloadcmake-0953c0051edcf3d4fb103b864fc0a7068dfedf59.tar.gz
Merge topic 'clang-cl-vfs'
20ebaed972 Clang: Add support for passing VFS arguments d993ebd4ca clang-cl: Add '--' before source file a94672b919 cmake: Change cmake_llvm_rc separator from -- to ++ to avoid conflict Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5087
-rw-r--r--Help/manual/cmake-variables.7.rst1
-rw-r--r--Help/release/dev/clang-cl-vfs.rst6
-rw-r--r--Help/variable/CMAKE_CLANG_VFS_OVERLAY.rst9
-rw-r--r--Modules/Platform/Windows-Clang.cmake2
-rw-r--r--Modules/Platform/Windows-MSVC.cmake8
-rw-r--r--Source/cmLocalGenerator.cxx25
-rw-r--r--Source/cmcmd.cxx8
-rw-r--r--Tests/RunCMake/CommandLine/RunCMakeTest.cmake8
8 files changed, 56 insertions, 11 deletions
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index 4ce836510f..d780a657ac 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -158,6 +158,7 @@ Variables that Change Behavior
/variable/CMAKE_AUTOMOC_RELAXED_MODE
/variable/CMAKE_BACKWARDS_COMPATIBILITY
/variable/CMAKE_BUILD_TYPE
+ /variable/CMAKE_CLANG_VFS_OVERLAY
/variable/CMAKE_CODEBLOCKS_COMPILER_ID
/variable/CMAKE_CODEBLOCKS_EXCLUDE_EXTERNAL_FILES
/variable/CMAKE_CODELITE_USE_TARGETS
diff --git a/Help/release/dev/clang-cl-vfs.rst b/Help/release/dev/clang-cl-vfs.rst
new file mode 100644
index 0000000000..40b19efddb
--- /dev/null
+++ b/Help/release/dev/clang-cl-vfs.rst
@@ -0,0 +1,6 @@
+clang-cl-vfs
+------------
+
+* A :variable:`CMAKE_CLANG_VFS_OVERLAY` variable was added to tell
+ Clang to use a VFS overlay to support the Windows SDK when
+ cross-compiling from hosts with case-sensitive filesystems.
diff --git a/Help/variable/CMAKE_CLANG_VFS_OVERLAY.rst b/Help/variable/CMAKE_CLANG_VFS_OVERLAY.rst
new file mode 100644
index 0000000000..56ac328ab2
--- /dev/null
+++ b/Help/variable/CMAKE_CLANG_VFS_OVERLAY.rst
@@ -0,0 +1,9 @@
+CMAKE_CLANG_VFS_OVERLAY
+-----------------------
+
+.. versionadded:: 3.19
+
+When cross compiling for windows with clang-cl, this variable can be an
+absolute path pointing to a clang virtual file system yaml file, which
+will enable clang-cl to resolve windows header names on a case sensitive
+file system.
diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake
index dff81663fd..05dff9d505 100644
--- a/Modules/Platform/Windows-Clang.cmake
+++ b/Modules/Platform/Windows-Clang.cmake
@@ -142,7 +142,7 @@ if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
endif()
if(DEFINED CMAKE_RC_PREPROCESSOR)
set(CMAKE_DEPFILE_FLAGS_RC "-clang:-MD -clang:-MF -clang:<DEPFILE>")
- set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_COMMAND} -E cmake_llvm_rc <SOURCE> <OBJECT>.pp <${CMAKE_RC_PREPROCESSOR}> <DEFINES> -DRC_INVOKED <INCLUDES> <FLAGS> -E <SOURCE> -- <CMAKE_RC_COMPILER> <DEFINES> -I <SOURCE_DIR> <INCLUDES> /fo <OBJECT> <OBJECT>.pp")
+ set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_COMMAND} -E cmake_llvm_rc <SOURCE> <OBJECT>.pp <${CMAKE_RC_PREPROCESSOR}> <DEFINES> -DRC_INVOKED <INCLUDES> <FLAGS> -E -- <SOURCE> ++ <CMAKE_RC_COMPILER> <DEFINES> -I <SOURCE_DIR> <INCLUDES> /fo <OBJECT> <OBJECT>.pp")
if(CMAKE_GENERATOR STREQUAL "Ninja")
set(CMAKE_NINJA_CMCLDEPS_RC 0)
set(CMAKE_NINJA_DEP_TYPE_RC gcc)
diff --git a/Modules/Platform/Windows-MSVC.cmake b/Modules/Platform/Windows-MSVC.cmake
index e272da94fb..173ef409c0 100644
--- a/Modules/Platform/Windows-MSVC.cmake
+++ b/Modules/Platform/Windows-MSVC.cmake
@@ -333,6 +333,14 @@ macro(__windows_compiler_msvc lang)
set(CMAKE_LINK_PCH ON)
if (CMAKE_${lang}_COMPILER_ID STREQUAL "Clang")
set(CMAKE_PCH_PROLOGUE "#pragma clang system_header")
+
+ # macOS paths usually start with /Users/*. Unfortunately, clang-cl interprets
+ # paths starting with /U as macro undefines, so we need to put a -- before the
+ # input file path to force it to be treated as a path.
+ string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_${lang}_COMPILE_OBJECT "${CMAKE_${lang}_COMPILE_OBJECT}")
+ string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "${CMAKE_${lang}_COMPILE_OBJECT}")
+ string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "${CMAKE_${lang}_COMPILE_OBJECT}")
+
elseif(MSVC_VERSION GREATER_EQUAL 1913)
# At least MSVC toolet 14.13 from VS 2017 15.6
set(CMAKE_PCH_PROLOGUE "#pragma system_header")
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 7e35fe7984..2380ccebe5 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1938,6 +1938,9 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
this->AddConfigVariableFlags(flags, cmStrCat("CMAKE_", lang, "_FLAGS"),
config);
+ std::string const& compiler = this->Makefile->GetSafeDefinition(
+ cmStrCat("CMAKE_", lang, "_COMPILER_ID"));
+
if (lang == "Swift") {
if (cmProp v = target->GetProperty("Swift_LANGUAGE_VERSION")) {
if (cmSystemTools::VersionCompare(
@@ -1951,9 +1954,6 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
target->AddCUDAArchitectureFlags(flags);
target->AddCUDAToolkitFlags(flags);
- std::string const& compiler =
- this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
-
if (compiler == "Clang") {
bool separable = target->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION");
@@ -1965,7 +1965,24 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
}
}
}
-
+ // Add VFS Overlay for Clang compiliers
+ if (compiler == "Clang") {
+ if (const char* vfsOverlay =
+ this->Makefile->GetDefinition("CMAKE_CLANG_VFS_OVERLAY")) {
+ std::string const& compilerSimulateId =
+ this->Makefile->GetSafeDefinition(
+ cmStrCat("CMAKE_", lang, "_SIMULATE_ID"));
+ if (compilerSimulateId == "MSVC") {
+ this->AppendCompileOptions(
+ flags,
+ std::vector<std::string>{ "-Xclang", "-ivfsoverlay", "-Xclang",
+ vfsOverlay });
+ } else {
+ this->AppendCompileOptions(
+ flags, std::vector<std::string>{ "-ivfsoverlay", vfsOverlay });
+ }
+ }
+ }
// Add MSVC runtime library flags. This is activated by the presence
// of a default selection whether or not it is overridden by a property.
cmProp msvcRuntimeLibraryDefault =
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 1a5fea1e33..a1c6771b2d 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -1772,7 +1772,7 @@ int cmcmd::RunLLVMRC(std::vector<std::string> const& args)
// args[2] == source_file_path
// args[3] == intermediate_file
// args[4..n] == preprocess+args
- // args[n+1] == --
+ // args[n+1] == ++
// args[n+2...] == llvm-rc+args
if (args.size() < 3) {
std::cerr << "Invalid cmake_llvm_rc arguments";
@@ -1784,7 +1784,11 @@ int cmcmd::RunLLVMRC(std::vector<std::string> const& args)
std::vector<std::string> resource_compile;
std::vector<std::string>* pArgTgt = &preprocess;
for (std::string const& arg : cmMakeRange(args).advance(4)) {
- if (arg == "--") {
+ // We use ++ as seperator between the preprocessing step definition and the
+ // rc compilation step becase we need to prepend a -- to seperate the
+ // source file properly from other options when using clang-cl for
+ // preprocessing.
+ if (arg == "++") {
pArgTgt = &resource_compile;
} else {
if (arg.find("SOURCE_DIR") != std::string::npos) {
diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
index b20e683ed3..2a5d5d3d4e 100644
--- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake
@@ -779,15 +779,15 @@ function(run_llvm_rc)
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake_command(llvm_rc_no_args ${CMAKE_COMMAND} -E cmake_llvm_rc)
run_cmake_command(llvm_rc_no_-- ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp ${CMAKE_COMMAND} -E echo "This is a test")
- run_cmake_command(llvm_rc_empty_preprocessor ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp -- ${CMAKE_COMMAND} -E echo "This is a test")
- run_cmake_command(llvm_rc_failing_first_command ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp ${CMAKE_COMMAND} -P FailedProgram.cmake -- ${CMAKE_COMMAND} -E echo "This is a test")
- run_cmake_command(llvm_rc_failing_second_command ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp ${CMAKE_COMMAND} -E echo "This is a test" -- ${CMAKE_COMMAND} -P FailedProgram.cmake )
+ run_cmake_command(llvm_rc_empty_preprocessor ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp ++ ${CMAKE_COMMAND} -E echo "This is a test")
+ run_cmake_command(llvm_rc_failing_first_command ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp ${CMAKE_COMMAND} -P FailedProgram.cmake ++ ${CMAKE_COMMAND} -E echo "This is a test")
+ run_cmake_command(llvm_rc_failing_second_command ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/source_file test.tmp ${CMAKE_COMMAND} -E echo "This is a test" ++ ${CMAKE_COMMAND} -P FailedProgram.cmake )
if(EXISTS ${RunCMake_TEST_BINARY_DIR}/test.tmp)
message(SEND_ERROR "${test} - FAILED:\n"
"test.tmp was not deleted")
endif()
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir")
- run_cmake_command(llvm_rc_full_run ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir/source_file test.tmp ${CMAKE_COMMAND} -E echo "This is a test" -- ${CMAKE_COMMAND} -E copy test.tmp SOURCE_DIR/llvmrc.result )
+ run_cmake_command(llvm_rc_full_run ${CMAKE_COMMAND} -E cmake_llvm_rc ${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir/source_file test.tmp ${CMAKE_COMMAND} -E echo "This is a test" ++ ${CMAKE_COMMAND} -E copy test.tmp SOURCE_DIR/llvmrc.result )
if(EXISTS ${RunCMake_TEST_BINARY_DIR}/ExpandSourceDir/test.tmp)
message(SEND_ERROR "${test} - FAILED:\n"
"test.tmp was not deleted")