Fix macOS arm64 cross compiling.

This fixes the following issues when cross compiling SwiftShader for arm64 macOS using CMake: - Sets architecture based on CMAKE_OSX_ARCHITECTURES settings. - Add missing dependency to LLVM. - Add a workaround for assembly file compilation on macOS in marl. Bug: fix build Test: cmake .. -DCMAKE_OSX_ARCHITECTURES=arm64 Change-Id: I8abba9e39907d8f4d59f51c57f09cd55d4edc148 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/51890 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarYilong Li <liyl@google.com> Commit-Queue: Yilong Li <liyl@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 51045556
...@@ -68,6 +68,22 @@ else() ...@@ -68,6 +68,22 @@ else()
endif() endif()
endif() endif()
# Cross compiling on macOS. The cross compiling architecture should override
# auto-detected system architecture settings.
if(CMAKE_OSX_ARCHITECTURES)
if(CMAKE_OSX_ARCHITECTURES MATCHES "arm64")
set(ARCH "aarch64")
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
set(ARCH "x86_64")
elseif(CMAKE_OSX_ARCHITECTURES MATCHES "i386")
set(ARCH "x86")
else()
message(FATAL_ERROR "Architecture ${CMAKE_OSX_ARCHITECTURES} is not "
"supported. Only one architecture (arm64, x86_64 "
"or i386) could be specified at build time.")
endif()
endif()
set(CMAKE_MACOSX_RPATH TRUE) set(CMAKE_MACOSX_RPATH TRUE)
if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (CMAKE_GENERATOR_TOOLSET STREQUAL "")) if ((CMAKE_GENERATOR MATCHES "Visual Studio") AND (CMAKE_GENERATOR_TOOLSET STREQUAL ""))
......
...@@ -160,7 +160,10 @@ set(LLVM_LIST ...@@ -160,7 +160,10 @@ set(LLVM_LIST
${LLVM_DIR}/lib/CodeGen/GCMetadataPrinter.cpp ${LLVM_DIR}/lib/CodeGen/GCMetadataPrinter.cpp
${LLVM_DIR}/lib/CodeGen/GCRootLowering.cpp ${LLVM_DIR}/lib/CodeGen/GCRootLowering.cpp
${LLVM_DIR}/lib/CodeGen/GCStrategy.cpp ${LLVM_DIR}/lib/CodeGen/GCStrategy.cpp
${LLVM_DIR}/lib/CodeGen/GlobalMerge.cpp
${LLVM_DIR}/lib/CodeGen/GlobalISel/CallLowering.cpp ${LLVM_DIR}/lib/CodeGen/GlobalISel/CallLowering.cpp
${LLVM_DIR}/lib/CodeGen/GlobalISel/Combiner.cpp
${LLVM_DIR}/lib/CodeGen/GlobalISel/CombinerHelper.cpp
${LLVM_DIR}/lib/CodeGen/GlobalISel/CSEInfo.cpp ${LLVM_DIR}/lib/CodeGen/GlobalISel/CSEInfo.cpp
${LLVM_DIR}/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp ${LLVM_DIR}/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
${LLVM_DIR}/lib/CodeGen/GlobalISel/GISelChangeObserver.cpp ${LLVM_DIR}/lib/CodeGen/GlobalISel/GISelChangeObserver.cpp
...@@ -268,6 +271,7 @@ set(LLVM_LIST ...@@ -268,6 +271,7 @@ set(LLVM_LIST
${LLVM_DIR}/lib/CodeGen/RegAllocGreedy.cpp ${LLVM_DIR}/lib/CodeGen/RegAllocGreedy.cpp
${LLVM_DIR}/lib/CodeGen/RegisterClassInfo.cpp ${LLVM_DIR}/lib/CodeGen/RegisterClassInfo.cpp
${LLVM_DIR}/lib/CodeGen/RegisterCoalescer.cpp ${LLVM_DIR}/lib/CodeGen/RegisterCoalescer.cpp
${LLVM_DIR}/lib/CodeGen/RegAllocPBQP.cpp
${LLVM_DIR}/lib/CodeGen/RegisterPressure.cpp ${LLVM_DIR}/lib/CodeGen/RegisterPressure.cpp
${LLVM_DIR}/lib/CodeGen/RegisterScavenging.cpp ${LLVM_DIR}/lib/CodeGen/RegisterScavenging.cpp
${LLVM_DIR}/lib/CodeGen/RegisterUsageInfo.cpp ${LLVM_DIR}/lib/CodeGen/RegisterUsageInfo.cpp
...@@ -456,6 +460,7 @@ set(LLVM_LIST ...@@ -456,6 +460,7 @@ set(LLVM_LIST
${LLVM_DIR}/lib/IR/Value.cpp ${LLVM_DIR}/lib/IR/Value.cpp
${LLVM_DIR}/lib/IR/ValueSymbolTable.cpp ${LLVM_DIR}/lib/IR/ValueSymbolTable.cpp
${LLVM_DIR}/lib/IR/Verifier.cpp ${LLVM_DIR}/lib/IR/Verifier.cpp
${LLVM_DIR}/lib/MC/ConstantPools.cpp
${LLVM_DIR}/lib/MC/ELFObjectWriter.cpp ${LLVM_DIR}/lib/MC/ELFObjectWriter.cpp
${LLVM_DIR}/lib/MC/MachObjectWriter.cpp ${LLVM_DIR}/lib/MC/MachObjectWriter.cpp
${LLVM_DIR}/lib/MC/MCAsmBackend.cpp ${LLVM_DIR}/lib/MC/MCAsmBackend.cpp
...@@ -732,6 +737,7 @@ set(LLVM_LIST ...@@ -732,6 +737,7 @@ set(LLVM_LIST
${LLVM_DIR}/lib/Transforms/Scalar/InstSimplifyPass.cpp ${LLVM_DIR}/lib/Transforms/Scalar/InstSimplifyPass.cpp
${LLVM_DIR}/lib/Transforms/Scalar/JumpThreading.cpp ${LLVM_DIR}/lib/Transforms/Scalar/JumpThreading.cpp
${LLVM_DIR}/lib/Transforms/Scalar/LICM.cpp ${LLVM_DIR}/lib/Transforms/Scalar/LICM.cpp
${LLVM_DIR}/lib/Transforms/Scalar/LoopDataPrefetch.cpp
${LLVM_DIR}/lib/Transforms/Scalar/LoopDeletion.cpp ${LLVM_DIR}/lib/Transforms/Scalar/LoopDeletion.cpp
${LLVM_DIR}/lib/Transforms/Scalar/LoopDistribute.cpp ${LLVM_DIR}/lib/Transforms/Scalar/LoopDistribute.cpp
${LLVM_DIR}/lib/Transforms/Scalar/LoopIdiomRecognize.cpp ${LLVM_DIR}/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
...@@ -757,6 +763,7 @@ set(LLVM_LIST ...@@ -757,6 +763,7 @@ set(LLVM_LIST
${LLVM_DIR}/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp ${LLVM_DIR}/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
${LLVM_DIR}/lib/Transforms/Scalar/Reassociate.cpp ${LLVM_DIR}/lib/Transforms/Scalar/Reassociate.cpp
${LLVM_DIR}/lib/Transforms/Scalar/SCCP.cpp ${LLVM_DIR}/lib/Transforms/Scalar/SCCP.cpp
${LLVM_DIR}/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
${LLVM_DIR}/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp ${LLVM_DIR}/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
${LLVM_DIR}/lib/Transforms/Scalar/SimplifyCFGPass.cpp ${LLVM_DIR}/lib/Transforms/Scalar/SimplifyCFGPass.cpp
${LLVM_DIR}/lib/Transforms/Scalar/SpeculativeExecution.cpp ${LLVM_DIR}/lib/Transforms/Scalar/SpeculativeExecution.cpp
...@@ -943,6 +950,7 @@ elseif(ARCH STREQUAL "mipsel" OR ARCH STREQUAL "mips64el") ...@@ -943,6 +950,7 @@ elseif(ARCH STREQUAL "mipsel" OR ARCH STREQUAL "mips64el")
) )
elseif(ARCH STREQUAL "aarch64") elseif(ARCH STREQUAL "aarch64")
list(APPEND LLVM_LIST list(APPEND LLVM_LIST
${LLVM_DIR}/lib/Support/AArch64TargetParser.cpp
${LLVM_DIR}/lib/Target/AArch64/AArch64A53Fix835769.cpp ${LLVM_DIR}/lib/Target/AArch64/AArch64A53Fix835769.cpp
${LLVM_DIR}/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp ${LLVM_DIR}/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp
${LLVM_DIR}/lib/Target/AArch64/AArch64AdvSIMDScalarPass.cpp ${LLVM_DIR}/lib/Target/AArch64/AArch64AdvSIMDScalarPass.cpp
......
...@@ -167,6 +167,18 @@ if(NOT MSVC) ...@@ -167,6 +167,18 @@ if(NOT MSVC)
${MARL_SRC_DIR}/osfiber_x64.c ${MARL_SRC_DIR}/osfiber_x64.c
${MARL_SRC_DIR}/osfiber_x86.c ${MARL_SRC_DIR}/osfiber_x86.c
) )
# CMAKE_OSX_ARCHITECTURES settings aren't propagated to assembly files when
# building for Apple platforms (https://gitlab.kitware.com/cmake/cmake/-/issues/20771),
# we treat assembly files as C files to work around this bug.
set_source_files_properties(
${MARL_SRC_DIR}/osfiber_asm_aarch64.S
${MARL_SRC_DIR}/osfiber_asm_arm.S
${MARL_SRC_DIR}/osfiber_asm_mips64.S
${MARL_SRC_DIR}/osfiber_asm_ppc64.S
${MARL_SRC_DIR}/osfiber_asm_x64.S
${MARL_SRC_DIR}/osfiber_asm_x86.S
PROPERTIES LANGUAGE C
)
endif(NOT MSVC) endif(NOT MSVC)
########################################################### ###########################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment