[PATCH] D102416: Fix cmake script to allow cross compiling from windows
Andrei Datcu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 13 09:51:38 PDT 2021
datcuandrei created this revision.
datcuandrei added reviewers: chandlerc, samsonov.
datcuandrei added a project: LLVM.
Herald added a subscriber: mgorny.
datcuandrei requested review of this revision.
Herald added a project: Sanitizers.
Herald added subscribers: llvm-commits, Sanitizers.
`separate_arguments` would fail whenever there would be a space in CMAKE_C_COMPILER, including on Linux.
According to CMake docs, `add_custom_command` does not guarantee a bash environment. Currently, this is not a problem on Linux, but on Windows we get cmd.exe trying to execute `:`. With my changes, bash is executed explicitly and it will work even on windows, provided `bash.exe` is somewhere in PATH.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102416
Files:
compiler-rt/cmake/Modules/AddCompilerRT.cmake
llvm/cmake/modules/AddLLVM.cmake
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -101,11 +101,11 @@
# FIXME: Don't write the "local:" line on OpenBSD.
# in the export file, also add a linker script to version LLVM symbols (form: LLVM_N.M)
add_custom_command(OUTPUT ${native_export_file}
- COMMAND echo "LLVM_${LLVM_VERSION_MAJOR} {" > ${native_export_file}
- COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> ${native_export_file} || :
- COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> ${native_export_file}
- COMMAND echo " local: *;" >> ${native_export_file}
- COMMAND echo "};" >> ${native_export_file}
+ COMMAND bash -c "echo 'LLVM_${LLVM_VERSION_MAJOR} {' > ${native_export_file}"
+ COMMAND bash -c "grep -q '[[:alnum:]]' ${export_file} && echo ' global:' >> ${native_export_file} || :"
+ COMMAND bash -c "sed -e 's/$/;/' -e 's/^/ /' < ${export_file} >> ${native_export_file}"
+ COMMAND bash -c "echo ' local: *;' >> ${native_export_file}"
+ COMMAND bash -c "echo '};' >> ${native_export_file}"
DEPENDS ${export_file}
VERBATIM
COMMENT "Creating export file for ${target_name}")
Index: compiler-rt/cmake/Modules/AddCompilerRT.cmake
===================================================================
--- compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -289,7 +289,7 @@
set(output_file_${libname} ${output_name_${libname}}${CMAKE_C_OUTPUT_EXTENSION})
foreach(substitution ${substitutions})
if(substitution STREQUAL "<CMAKE_C_COMPILER>")
- string(REPLACE "<CMAKE_C_COMPILER>" "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
+ string(REPLACE "<CMAKE_C_COMPILER>" "\"${CMAKE_C_COMPILER}\" ${CMAKE_C_COMPILER_ARG1}"
compile_command_${libname} ${compile_command_${libname}})
elseif(substitution STREQUAL "<OBJECT>")
string(REPLACE "<OBJECT>" "${output_dir_${libname}}/${output_file_${libname}}"
@@ -305,7 +305,7 @@
${compile_command_${libname}})
endif()
endforeach()
- separate_arguments(compile_command_${libname})
+ separate_arguments(compile_command_${libname} NATIVE_COMMAND ${compile_command_${libname}})
add_custom_command(
OUTPUT ${output_dir_${libname}}/${output_file_${libname}}
COMMAND ${compile_command_${libname}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102416.345188.patch
Type: text/x-patch
Size: 2551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210513/4ec706fc/attachment.bin>
More information about the llvm-commits
mailing list