Skip to content

Commit

Permalink
Add x86/arm64/arm support to the cmake build. Fix issues. (dotnet#41860)
Browse files Browse the repository at this point in the history
  • Loading branch information
vargaz authored Sep 4, 2020
1 parent ddbb03a commit 964766a
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 23 deletions.
41 changes: 36 additions & 5 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,21 @@ endif()
if(NOT AOT_TARGET_TRIPLE STREQUAL "")
set(MONO_CROSS_COMPILE 1)
add_definitions(-DNO_GLOBALIZATION_SHIM)
if (NOT AOT_OFFSETS_FILE STREQUAL "")
if(NOT AOT_OFFSETS_FILE STREQUAL "")
set(MONO_OFFSETS_FILE "${AOT_OFFSETS_FILE}")
endif()
if (AOT_TARGET_TRIPLE STREQUAL "x86_64-apple-darwin10")
if(AOT_TARGET_TRIPLE STREQUAL "x86_64-apple-darwin10")
set(TARGET_SYSTEM_NAME "iOS")
set(TARGET_ARCH "x86_64")
elseif(AOT_TARGET_TRIPLE STREQUAL "i386-apple-darwin10")
set(TARGET_SYSTEM_NAME "iOS")
set(TARGET_ARCH "x86")
elseif(AOT_TARGET_TRIPLE STREQUAL "aarch64-apple-darwin10")
set(TARGET_SYSTEM_NAME "iOS")
set(TARGET_ARCH "arm64")
elseif(AOT_TARGET_TRIPLE STREQUAL "arm-apple-darwin10")
set(TARGET_SYSTEM_NAME "iOS")
set(TARGET_ARCH "arm")
else()
message(FATAL_ERROR "AOT target '${AOT_TARGET_TRIPLE}' not supported.")
endif()
Expand Down Expand Up @@ -224,10 +233,19 @@ endif()

if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "")
set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_OSX_ARCHITECTURES}")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
set(CMAKE_SYSTEM_PROCESSOR "x86")
endif()
endif()

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(HOST_AMD64 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
set(HOST_X86 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(HOST_ARM64 1)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
set(HOST_ARM 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
# CMAKE_SYSTEM_PROCESSOR is set to x86
else()
Expand All @@ -245,8 +263,15 @@ endif()
if(TARGET_ARCH STREQUAL "x86_64")
set(TARGET_AMD64 1)
set(MONO_ARCHITECTURE "\"amd64\"")
set(RID_SUFFIX "x64")
set(COREARCH "x64")
elseif(TARGET_ARCH STREQUAL "x86")
set(TARGET_X86 1)
set(MONO_ARCHITECTURE "\"x86\"")
elseif(TARGET_ARCH STREQUAL "arm64")
set(TARGET_ARM64 1)
set(MONO_ARCHITECTURE "\"arm64\"")
elseif(TARGET_ARCH STREQUAL "arm")
set(TARGET_ARM 1)
set(MONO_ARCHITECTURE "\"arm\"")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
# CMAKE_SYSTEM_PROCESSOR is set to x86
set(MONO_ARCHITECTURE "\"wasm\"")
Expand All @@ -258,7 +283,7 @@ endif()
######################################
# LLVM CHECKS
######################################
if (LLVM_PREFIX)
if(LLVM_PREFIX)
# FIXME: windows

set(LLVM_CONFIG ${LLVM_PREFIX}/bin/llvm-config)
Expand All @@ -268,6 +293,12 @@ if (LLVM_PREFIX)

if(TARGET_ARCH STREQUAL "x86_64")
set(llvm_codegen_libs "x86codegen")
elseif(TARGET_ARCH STREQUAL "x86")
set(llvm_codegen_libs "x86codegen")
elseif(TARGET_ARCH STREQUAL "arm64")
set(llvm_codegen_libs "aarch64codegen")
elseif(TARGET_ARCH STREQUAL "arm")
set(llvm_codegen_libs "armcodegen")
else()
message(FATAL_ERROR "FIXME")
endif()
Expand Down
98 changes: 83 additions & 15 deletions src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,34 @@ set(utils_common_sources
unlocked.h
ward.h)

if(TARGET_AMD64)
if(MONO_CROSS_COMPILE)
set(utils_arch_sources mach-support-unknown.c)
elseif(HOST_AMD64)
set(utils_arch_sources
mach-support-amd64.c)
elseif(HOST_X86)
set(utils_arch_sources
mach-support-x86.c)
elseif(HOST_ARM64)
set(utils_arch_sources
mach-support-arm64.c)
elseif(HOST_ARM)
set(utils_arch_sources
mach-support-arm.c)
else()
#message(FATAL_ERROR "")
endif()

if(CROSS_COMPILE)
if(MONO_CROSS_COMPILE)
set(utils_arch_sources "${utils_arch_sources};mono-hwcap-cross.c")
elseif(TARGET_AMD64)
set(utils_arch_sources "${utils_arch_sources};mono-hwcap-x86.c")
elseif(TARGET_X86)
set(utils_arch_sources "${utils_arch_sources};mono-hwcap-x86.c")
elseif(TARGET_ARM64)
set(utils_arch_sources "${utils_arch_sources};mono-hwcap-arm64.c")
elseif(TARGET_ARM)
set(utils_arch_sources "${utils_arch_sources};mono-hwcap-arm.c")
elseif(TARGET_WASM)
set(utils_arch_sources "${utils_arch_sources};mono-hwcap-wasm.c;mono-mmap-wasm.c")
else()
Expand Down Expand Up @@ -855,6 +872,35 @@ set(amd64_sources
tramp-amd64-gsharedvt.c
cpu-amd64.h)

set(x86_sources
mini-x86.c
mini-x86.h
exceptions-x86.c
tramp-x86.c
mini-x86-gsharedvt.c
tramp-x86-gsharedvt.c
cpu-x86.h)

set(arm64_sources
mini-arm64.c
mini-arm64.h
exceptions-arm64.c
tramp-arm64.c
mini-arm64-gsharedvt.c
mini-arm64-gsharedvt.h
tramp-arm64-gsharedvt.c
cpu-arm64.h)

set(arm_sources
mini-arm.c
mini-arm.h
exceptions-arm.c
tramp-arm.c
mini-arm-gsharedvt.c
mini-arm-gsharedvt.h
tramp-arm-gsharedvt.c
cpu-arm.h)

set(wasm_sources
mini-wasm.c
tramp-wasm.c
Expand All @@ -865,6 +911,12 @@ set(wasm_sources

if(TARGET_AMD64)
set(arch_sources ${amd64_sources})
elseif(TARGET_X86)
set(arch_sources ${x86_sources})
elseif(TARGET_ARM64)
set(arch_sources ${arm64_sources})
elseif(TARGET_ARM)
set(arch_sources ${arm_sources})
elseif(TARGET_WASM)
set(arch_sources ${wasm_sources})
endif()
Expand Down Expand Up @@ -941,25 +993,23 @@ endif()
add_library(monosgen-objects OBJECT "${eglib_sources};${metadata_sources};${utils_sources};${sgen_sources};${icu_shim_sources};${eventpipe_sources};${mini_sources}")
add_library(monosgen-static STATIC $<TARGET_OBJECTS:monosgen-objects>)
set_target_properties(monosgen-static PROPERTIES OUTPUT_NAME monosgen-2.0)
install(TARGETS monosgen-static LIBRARY)
install(FILES ${metadata_public_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mono-2.0/mono/metadata)
install(FILES ${utils_public_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mono-2.0/mono/utils)
install(FILES ${mini_public_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mono-2.0/mono/jit)
if(NOT DISABLE_LIBS)
install(TARGETS monosgen-static LIBRARY)
install(FILES ${metadata_public_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mono-2.0/mono/metadata)
install(FILES ${utils_public_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mono-2.0/mono/utils)
install(FILES ${mini_public_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mono-2.0/mono/jit)
endif()
if(NOT DISABLE_SHARED_LIBS)
add_library(monosgen SHARED $<TARGET_OBJECTS:monosgen-objects>)
set_target_properties(monosgen PROPERTIES OUTPUT_NAME monosgen-2.0)
set_target_properties(monosgen PROPERTIES LIBRARY_OUTPUT_DIRECTORY .libs)
target_link_libraries(monosgen ${OS_LIBS} "iconv" ${LLVM_LIBS} ${ICU_LIBS})
install(TARGETS monosgen LIBRARY)
endif()

if(NOT DISABLE_EXECUTABLES)
set_target_properties(monosgen PROPERTIES OUTPUT_NAME monosgen-2.0)
set_target_properties(monosgen PROPERTIES LIBRARY_OUTPUT_DIRECTORY .libs)
endif()

# FIXME: Always rebuilds, creates non-deterministic builds
# FIXME: Use the previous format
#string(TIMESTAMP BUILD_DATE)
Expand Down Expand Up @@ -987,10 +1037,28 @@ add_custom_command(
VERBATIM
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cpu-x86.h
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/genmdesc.py TARGET_X86 ${CMAKE_CURRENT_SOURCE_DIR} cpu-x86.h x86_desc ${CMAKE_CURRENT_SOURCE_DIR}/cpu-x86.md
VERBATIM
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cpu-arm64.h
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/genmdesc.py TARGET_ARM64 ${CMAKE_CURRENT_SOURCE_DIR} cpu-arm64.h arm64_cpu_desc ${CMAKE_CURRENT_SOURCE_DIR}/cpu-arm64.md
VERBATIM
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cpu-arm.h
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/genmdesc.py TARGET_ARM ${CMAKE_CURRENT_SOURCE_DIR} cpu-arm.h arm_cpu_desc ${CMAKE_CURRENT_SOURCE_DIR}/cpu-arm.md
VERBATIM
)

if(NOT DISABLE_EXECUTABLES)
set(CMAKE_SKIP_RPATH 1)
add_executable(mono-sgen "main-sgen.c")
target_link_libraries(mono-sgen monosgen-static ${OS_LIBS} "iconv" ${LLVM_LIBS} ${ICU_LIBS})
target_link_libraries(monosgen ${OS_LIBS} "iconv" ${LLVM_LIBS} ${ICU_LIBS})
if(ICU_LDFLAGS)
set_target_properties(mono-sgen monosgen PROPERTIES LINK_FLAGS ${ICU_LDFLAGS})
endif()
Expand Down
8 changes: 5 additions & 3 deletions src/mono/mono/profiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ include_directories(
${PROJECT_SOURCE_DIR}/../eglib
${PROJECT_SOURCE_DIR}/../sgen)

add_library(mono-profiler-aot-static STATIC aot.c helper.c)
set_target_properties(mono-profiler-aot-static PROPERTIES OUTPUT_NAME mono-profiler-aot)
install(TARGETS mono-profiler-aot-static LIBRARY)
if(NOT DISABLE_LIBS)
add_library(mono-profiler-aot-static STATIC aot.c helper.c)
set_target_properties(mono-profiler-aot-static PROPERTIES OUTPUT_NAME mono-profiler-aot)
install(TARGETS mono-profiler-aot-static LIBRARY)
endif()

0 comments on commit 964766a

Please sign in to comment.