Skip to content

Commit

Permalink
Ongoing cmake build work. (#42182)
Browse files Browse the repository at this point in the history
* Ongoing cmake build work.

* Fix indentation.
* Add linux support.
* Add tvos support.
* Use clang only options only with clang.
* Add check for iconv.

* Fix indentation.
  • Loading branch information
vargaz authored Sep 18, 2020
1 parent 9299efc commit fd09c80
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 47 deletions.
114 changes: 74 additions & 40 deletions src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include(CheckIncludeFile)
include(CheckFunctionExists)
include(TestBigEndian)
include(FindPkgConfig)
include(CheckCCompilerFlag)

include("cmake/QuietOSXRanlib.cmake")

Expand Down Expand Up @@ -130,25 +131,25 @@ if(NOT AOT_TARGET_TRIPLE STREQUAL "")
set(MONO_CROSS_COMPILE 1)
add_definitions(-DNO_GLOBALIZATION_SHIM)
if(NOT AOT_OFFSETS_FILE STREQUAL "")
set(MONO_OFFSETS_FILE "${AOT_OFFSETS_FILE}")
set(MONO_OFFSETS_FILE "${AOT_OFFSETS_FILE}")
endif()
if(AOT_TARGET_TRIPLE STREQUAL "x86_64-apple-darwin10")
set(TARGET_SYSTEM_NAME "iOS")
set(TARGET_ARCH "x86_64")
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")
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")
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")
set(TARGET_SYSTEM_NAME "iOS")
set(TARGET_ARCH "arm")
elseif(AOT_TARGET_TRIPLE STREQUAL "wasm32-unknown-none")
set(TARGET_SYSTEM_NAME "Emscripten")
set(TARGET_ARCH "wasm")
set(TARGET_SYSTEM_NAME "Emscripten")
set(TARGET_ARCH "wasm")
else()
message(FATAL_ERROR "AOT target '${AOT_TARGET_TRIPLE}' not supported.")
message(FATAL_ERROR "AOT target '${AOT_TARGET_TRIPLE}' not supported.")
endif()
endif()

Expand All @@ -164,16 +165,24 @@ if(GCC)
# We rely on signed overflow to behave
append("-fwrapv" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)

set(WARNINGS "-Wall -Wunused -Wmissing-declarations -Wpointer-arith -Wno-cast-qual -Wwrite-strings -Wno-switch -Wno-switch-enum -Wno-unused-value -Wno-attributes -Qunused-arguments -Wno-unused-function -Wno-tautological-compare -Wno-parentheses-equality -Wno-self-assign -Wno-return-stack-address -Wno-constant-logical-operand -Wno-zero-length-array -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs -Wno-format-zero-length")
set(WARNINGS "-Wall -Wunused -Wmissing-declarations -Wpointer-arith -Wno-cast-qual -Wwrite-strings -Wno-switch -Wno-switch-enum -Wno-unused-value -Wno-attributes -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs -Wno-format-zero-length -Wno-unused-function")

set(WERROR "-Werror=incompatible-pointer-types -Werror=return-type -Werror-implicit-function-declaration")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(WARNINGS "${WARNINGS} -Qunused-arguments -Wno-tautological-compare -Wno-parentheses-equality -Wno-self-assign -Wno-return-stack-address -Wno-constant-logical-operand -Wno-zero-length-array")
endif()

check_c_compiler_flag("-Werror=incompatible-pointer-types" WERROR_INCOMPATIBLE_POINTER_TYPES)
if(WERROR_INCOMPATIBLE_POINTER_TYPES)
set(WERROR "${WERROR} -Werror=incompatible-pointer-types")
endif()
set(WERROR "${WERROR} -Werror=return-type -Werror-implicit-function-declaration")

append("${WARNINGS} ${WERROR}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)

set(MONO_ZERO_LEN_ARRAY 0)

if(ENABLE_WERROR)
append("-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
endif()
endif()

Expand All @@ -187,9 +196,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(PTHREAD_POINTER_ID 1)
set(USE_MACH_SEMA 1)
if (GC_SUSPEND STREQUAL "default")
set(GC_SUSPEND "hybrid")
set(GC_SUSPEND "hybrid")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "tvOS")
# See man cmake-toolchains(7) on which variables
# control cross-compiling to ios
add_definitions(-DNO_GLOBALIZATION_SHIM)
Expand All @@ -202,16 +211,37 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(DISABLE_CRASH_REPORTING 1)
set(ENABLE_MONOTOUCH 1)
add_definitions(-DMONOTOUCH=1)
add_definitions(-DHOST_IOS=1)
set(HAVE_SYSTEM 0)
set(MONO_DL_NEED_USCORE 1)
if(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
set(HOST_TVOS 1)
endif()

# Force some defines
set(HAVE_GETPWUID_R 0)
set(HAVE_SYS_USER_H 0)
set(HAVE_GETENTROPY 0)
if(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
set(HAVE_PTHREAD_KILL 0)
set(HAVE_KILL 0)
set(HAVE_SIGACTION 0)
set(HAVE_FORK 0)
set(HAVE_EXECV 0)
set(HAVE_EXECVE 0)
set(HAVE_EXECVP 0)
set(HAVE_SIGNAL 0)
endif()
add_definitions("-DSMALL_CONFIG")
add_definitions("-D_XOPEN_SOURCE")
add_definitions("-DHAVE_LARGE_FILE_SUPPORT=1")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(HOST_LINUX 1)
add_definitions(-D_GNU_SOURCE -D_REENTRANT)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(HOST_WASM 1)
set(TARGET_ARCH "wasm")
# CMAKE_SYSTEM_PROCESSOR is set to x86
set(CMAKE_SYSTEM_PROCESSOR "wasm")
set(DISABLE_EXECUTABLES 1)
# FIXME: Is there a cmake option for this ?
set(DISABLE_SHARED_LIBS 1)
Expand All @@ -230,9 +260,10 @@ endif()
if(TARGET_SYSTEM_NAME STREQUAL "Darwin")
set(TARGET_MACH 1)
set(TARGET_OSX 1)
elseif(TARGET_SYSTEM_NAME STREQUAL "iOS")
elseif(TARGET_SYSTEM_NAME STREQUAL "iOS" OR TARGET_SYSTEM_NAME STREQUAL "tvOS")
set(TARGET_MACH 1)
set(TARGET_IOS 1)
elseif(TARGET_SYSTEM_NAME STREQUAL "Linux")
elseif(TARGET_SYSTEM_NAME STREQUAL "Emscripten")
set(TARGET_WASM 1)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
Expand All @@ -246,10 +277,10 @@ endif()
# HOST ARCH CHECKS
######################################

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

Expand All @@ -259,10 +290,9 @@ 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")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7s")
set(HOST_ARM 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
# CMAKE_SYSTEM_PROCESSOR is set to x86
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "wasm")
else()
message(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR='${CMAKE_SYSTEM_PROCESSOR}' not supported.")
endif()
Expand All @@ -284,19 +314,18 @@ elseif(TARGET_ARCH STREQUAL "x86")
elseif(TARGET_ARCH STREQUAL "arm64")
set(TARGET_ARM64 1)
set(MONO_ARCHITECTURE "\"arm64\"")
elseif(TARGET_ARCH STREQUAL "arm")
elseif(TARGET_ARCH STREQUAL "arm" OR TARGET_ARCH STREQUAL "armv7s")
set(TARGET_ARM 1)
set(MONO_ARCHITECTURE "\"arm\"")
if(TARGET_IOS)
add_definitions("-DARM_FPU_VFP=1")
endif()
elseif(TARGET_ARCH STREQUAL "wasm")
set(MONO_ARCHITECTURE "\"wasm\"")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
# CMAKE_SYSTEM_PROCESSOR is set to x86
set(MONO_ARCHITECTURE "\"wasm\"")
else()
message(FATAL_ERROR "TARGET_ARCH='${TARGET_ARCH}' not supported.")
endif()


######################################
# LLVM CHECKS
######################################
Expand All @@ -305,34 +334,34 @@ if(LLVM_PREFIX)

set(LLVM_CONFIG ${LLVM_PREFIX}/bin/llvm-config)
if (NOT EXISTS ${LLVM_CONFIG})
message(FATAL_ERROR "LLVM executable '${LLVM_CONFIG}' not found.")
message(FATAL_ERROR "LLVM executable '${LLVM_CONFIG}' not found.")
endif()

if(TARGET_ARCH STREQUAL "x86_64")
set(llvm_codegen_libs "x86codegen")
set(llvm_codegen_libs "x86codegen")
elseif(TARGET_ARCH STREQUAL "x86")
set(llvm_codegen_libs "x86codegen")
set(llvm_codegen_libs "x86codegen")
elseif(TARGET_ARCH STREQUAL "arm64")
set(llvm_codegen_libs "aarch64codegen")
set(llvm_codegen_libs "aarch64codegen")
elseif(TARGET_ARCH STREQUAL "arm")
set(llvm_codegen_libs "armcodegen")
set(llvm_codegen_libs "armcodegen")
elseif(TARGET_ARCH STREQUAL "wasm")
set(llvm_codegen_libs "")
set(llvm_codegen_libs "")
else()
message(FATAL_ERROR "FIXME")
message(FATAL_ERROR "FIXME")
endif()

execute_process(COMMAND ${LLVM_CONFIG} --mono-api-version RESULT_VARIABLE llvm_config_res OUTPUT_VARIABLE llvm_api_version OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT ${llvm_config_res} EQUAL 0)
message(FATAL_ERROR "'${LLVM_CONFIG} --mono-api-version' failed. Use the llvm fork at https://github.com/dotnet/llvm-project.")
message(FATAL_ERROR "'${LLVM_CONFIG} --mono-api-version' failed. Use the llvm fork at https://github.com/dotnet/llvm-project.")
endif()
execute_process(COMMAND ${LLVM_CONFIG} --cflags OUTPUT_VARIABLE llvm_cflags OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --cxxflags OUTPUT_VARIABLE llvm_cxxflags OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --system-libs OUTPUT_VARIABLE llvm_system_libs OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVM_CONFIG} --libs analysis core bitwriter orcjit ${llvm_codegen_libs} OUTPUT_VARIABLE llvm_libs OUTPUT_STRIP_TRAILING_WHITESPACE)

if (${llvm_api_version} LESS 900)
message(FATAL_ERROR "LLVM version too old.")
message(FATAL_ERROR "LLVM version too old.")
endif()

set(ENABLE_LLVM 1)
Expand All @@ -355,15 +384,20 @@ elseif(TARGET_OSX)
set(ENV{PKG_CONFIG_PATH} "{$PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig")
pkg_check_modules(ICU icu-uc)
set(OSX_ICU_LIBRARY_PATH /usr/lib/libicucore.dylib)
set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations")
set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations")
set(HAVE_SYS_ICU 1)
elseif(TARGET_WASM)
#set(ICU_CFLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -DHAVE_SET_MAX_VARIABLE")
set(ICU_FLAGS "-DPALEXPORT=\"\" -DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option")
set(ICU_FLAGS "-DPALEXPORT=\"\" -DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option")
set(HAVE_SYS_ICU 1)
set(STATIC_ICU 1)
set(ICU_LIBS "icucore")
elseif(TARGET_IOS)
# FIXME:
elseif(HOST_LINUX)
pkg_check_modules(ICU icu-uc)
set(ICU_FLAGS "-DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations")
set(HAVE_SYS_ICU 1)
else()
message(FATAL_ERROR "")
endif()
Expand Down
9 changes: 9 additions & 0 deletions src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
/* Host Platform is Darwin */
#cmakedefine HOST_DARWIN 1

/* Host Platform is iOS */
#cmakedefine HOST_IOS 1

/* Host Platform is tvOS */
#cmakedefine HOST_TVOS 1

/* Use classic Windows API support */
#cmakedefine HAVE_CLASSIC_WINAPI_SUPPORT 1

Expand Down Expand Up @@ -480,6 +486,9 @@
/* CLOCK_REALTIME */
#cmakedefine HAVE_CLOCK_REALTIME 1

/* clockid_t */
#cmakedefine HAVE_CLOCKID_T 1

/* mach_absolute_time */
#cmakedefine HAVE_MACH_ABSOLUTE_TIME 1

Expand Down
13 changes: 13 additions & 0 deletions src/mono/cmake/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,16 @@ check_type_size("void*" SIZEOF_VOID_P)
check_type_size("long" SIZEOF_LONG)
check_type_size("long long" SIZEOF_LONG_LONG)
check_type_size("size_t" SIZEOF_SIZE_T)

# ICONV
find_library(LIBICONV_FOUND iconv)
if(NOT LIBICONV_FOUND STREQUAL "LIBICONV_FOUND-NOTFOUND")
set(ICONV_LIB "iconv")
endif()

file(WRITE ${CMAKE_BINARY_DIR}{$CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c
"#include <sched.h>\n"
"void main () { CPU_COUNT((void *) 0); }\n"
)
try_compile(GLIBC_HAS_CPU_COUNT ${CMAKE_BINARY_DIR}/CMakeTmp SOURCES "${CMAKE_BINARY_DIR}{$CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c"
COMPILE_DEFINITIONS "-D_GNU_SOURCE")
14 changes: 7 additions & 7 deletions src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ set(icu_shim_sources_base
addprefix(icu_shim_sources "${ICU_SHIM_PATH}" "${icu_shim_sources_base}")
set_source_files_properties(${icu_shim_sources} PROPERTIES COMPILE_DEFINITIONS OSX_ICU_LIBRARY_PATH="${OSX_ICU_LIBRARY_PATH}")
set_source_files_properties(${icu_shim_sources} PROPERTIES COMPILE_FLAGS "-I${ICU_INCLUDEDIR} -I${CMAKE_SOURCE_DIR}/../libraries/Native/Unix/System.Globalization.Native/ -I${CMAKE_SOURCE_DIR}/../libraries/Native/Unix/Common/ ${ICU_FLAGS}")
set(ICU_LIBS "icucore")
set(ICU_LDFLAGS "-L${ICU_LIBDIR}")
endif()

Expand Down Expand Up @@ -182,7 +181,6 @@ set(arm_sources
exceptions-arm.c
tramp-arm.c
mini-arm-gsharedvt.c
mini-arm-gsharedvt.h
tramp-arm-gsharedvt.c
cpu-arm.h)

Expand Down Expand Up @@ -221,6 +219,8 @@ set(posix_sources

if(HOST_DARWIN)
set(os_sources "${darwin_sources};${posix_sources}")
elseif(HOST_LINUX)
set(os_sources "${posix_sources}")
endif()

set(interp_sources
Expand Down Expand Up @@ -274,10 +274,10 @@ endif()

if(HOST_DARWIN)
set(OS_LIBS "-framework CoreFoundation" "-framework Foundation")
endif()

if(HOST_IOS)
elseif(HOST_IOS)
set(OS_LIBS "-framework CoreFoundation" "-lobjc" "-lc++")
elseif(HOST_LINUX)
set(OS_LIBS pthread m dl)
endif()

add_library(monosgen-objects OBJECT "${eglib_sources};${metadata_sources};${utils_sources};${sgen_sources};${icu_shim_sources};${eventpipe_sources};${mini_sources}")
Expand All @@ -296,7 +296,7 @@ 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})
target_link_libraries(monosgen ${OS_LIBS} ${ICONV_LIB} ${LLVM_LIBS} ${ICU_LIBS})
if(ICU_LDFLAGS)
set_target_properties(monosgen PROPERTIES LINK_FLAGS ${ICU_LDFLAGS})
endif()
Expand Down Expand Up @@ -357,7 +357,7 @@ add_custom_command(
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(mono-sgen monosgen-static ${OS_LIBS} ${ICONV_LIB} ${LLVM_LIBS} ${ICU_LIBS})
if(ICU_LDFLAGS)
set_target_properties(mono-sgen PROPERTIES LINK_FLAGS ${ICU_LDFLAGS})
endif()
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/simd-intrinsics-netcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,9 @@ MONO_EMPTY_SOURCE_FILE (simd_intrinsics_netcore);
void
ves_icall_System_Runtime_Intrinsics_X86_X86Base___cpuidex (int abcd[4], int function_id, int subfunction_id)
{
#ifndef MONO_CROSS_COMPILE
mono_hwcap_x86_call_cpuidex (function_id, subfunction_id,
&abcd [0], &abcd [1], &abcd [2], &abcd [3]);
#endif
}
#endif

0 comments on commit fd09c80

Please sign in to comment.