From a94672b919db3ec961e5b4405352fec9ba95ddeb Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Tue, 28 Jul 2020 22:12:13 +0200 Subject: cmake: Change cmake_llvm_rc separator from -- to ++ to avoid conflict --- Modules/Platform/Windows-Clang.cmake | 2 +- Source/cmcmd.cxx | 8 ++++++-- Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake index dff8166..7cd06a2 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:") - set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_COMMAND} -E cmake_llvm_rc .pp <${CMAKE_RC_PREPROCESSOR}> -DRC_INVOKED -E -- -I /fo .pp") + set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_COMMAND} -E cmake_llvm_rc .pp <${CMAKE_RC_PREPROCESSOR}> -DRC_INVOKED -E ++ -I /fo .pp") if(CMAKE_GENERATOR STREQUAL "Ninja") set(CMAKE_NINJA_CMCLDEPS_RC 0) set(CMAKE_NINJA_DEP_TYPE_RC gcc) diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 1a5fea1..a1c6771 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1772,7 +1772,7 @@ int cmcmd::RunLLVMRC(std::vector 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 const& args) std::vector resource_compile; std::vector* 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 b20e683..2a5d5d3 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") -- cgit v0.12 From d993ebd4ca0fc1044745dd1874bab082090f9801 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Tue, 28 Jul 2020 22:12:13 +0200 Subject: clang-cl: Add '--' before source file On Linux and macOS, absolute paths start with `/` which may be interpreted by clang-cl as an option. To avoid this, we separate the source file path from preceding options with `--` to tell `clang-cl` it is not an option. --- Modules/Platform/Windows-Clang.cmake | 2 +- Modules/Platform/Windows-MSVC.cmake | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Modules/Platform/Windows-Clang.cmake b/Modules/Platform/Windows-Clang.cmake index 7cd06a2..05dff9d 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:") - set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_COMMAND} -E cmake_llvm_rc .pp <${CMAKE_RC_PREPROCESSOR}> -DRC_INVOKED -E ++ -I /fo .pp") + set(CMAKE_RC_COMPILE_OBJECT "${CMAKE_COMMAND} -E cmake_llvm_rc .pp <${CMAKE_RC_PREPROCESSOR}> -DRC_INVOKED -E -- ++ -I /fo .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 e272da9..173ef40 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 " "-c -- " CMAKE_${lang}_COMPILE_OBJECT "${CMAKE_${lang}_COMPILE_OBJECT}") + string(REPLACE "-c " "-c -- " CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "${CMAKE_${lang}_COMPILE_OBJECT}") + string(REPLACE "-c " "-c -- " 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") -- cgit v0.12 From 20ebaed97235d8397638807ff791803f8bd4e215 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Tue, 21 Jul 2020 20:13:19 +0200 Subject: Clang: Add support for passing VFS arguments --- Help/manual/cmake-variables.7.rst | 1 + Help/release/dev/clang-cl-vfs.rst | 6 ++++++ Help/variable/CMAKE_CLANG_VFS_OVERLAY.rst | 9 +++++++++ Source/cmLocalGenerator.cxx | 25 +++++++++++++++++++++---- 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 Help/release/dev/clang-cl-vfs.rst create mode 100644 Help/variable/CMAKE_CLANG_VFS_OVERLAY.rst diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index 4ce8365..d780a65 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 0000000..40b19ef --- /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 0000000..56ac328 --- /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/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 4d39312..dc3bf47 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{ "-Xclang", "-ivfsoverlay", "-Xclang", + vfsOverlay }); + } else { + this->AppendCompileOptions( + flags, std::vector{ "-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 = -- cgit v0.12