Mono: switch to CMake build on Windows (#44976)
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 25 Nov 2020 17:56:52 +0000 (18:56 +0100)
committerGitHub <noreply@github.com>
Wed, 25 Nov 2020 17:56:52 +0000 (18:56 +0100)
This unifies the build with the other platforms.

Hooks up the versioning targets so the mono libraries get the correct version.

22 files changed:
eng/native/init-compiler-and-cmake.cmd [new file with mode: 0644]
src/mono/CMakeLists.txt
src/mono/Directory.Build.props
src/mono/cmake/config.h.in
src/mono/cmake/configure.cmake
src/mono/mono.proj
src/mono/mono/CMakeLists.txt
src/mono/mono/metadata/attach.c
src/mono/mono/mini/CMakeLists.txt
src/mono/mono/mini/aot-runtime.c
src/mono/mono/mini/driver.c
src/mono/mono/mini/gen-version-h.sh [deleted file]
src/mono/mono/mini/mini-darwin.c
src/mono/mono/mini/mini-posix.c
src/mono/mono/mini/mini-runtime.c
src/mono/mono/mini/mini-windows.c
src/mono/mono/mini/mini.c
src/mono/mono/profiler/aot.c
src/mono/mono/utils/CMakeLists.txt
src/mono/mono/utils/checked-build.c
src/mono/mono/utils/mono-counters.c
src/mono/mono/zlib/CMakeLists.txt [new file with mode: 0644]

diff --git a/eng/native/init-compiler-and-cmake.cmd b/eng/native/init-compiler-and-cmake.cmd
new file mode 100644 (file)
index 0000000..e579fec
--- /dev/null
@@ -0,0 +1,89 @@
+@if not defined _echo @echo off
+rem
+rem This file locates VS C++ compilers and cmake for windows.
+
+:SetupArgs
+:: Initialize the args that will be passed to cmake
+set __VCBuildArch=x86_amd64
+
+:Arg_Loop
+:: Since the native build requires some configuration information before msbuild is called, we have to do some manual args parsing
+if [%1] == [] goto :ToolsVersion
+if /i [%1] == [x86]         ( set __VCBuildArch=x86&&shift&goto Arg_Loop)
+if /i [%1] == [arm]         ( set __VCBuildArch=x86_arm&&shift&goto Arg_Loop)
+if /i [%1] == [x64]         ( set __VCBuildArch=x86_amd64&&shift&goto Arg_Loop)
+if /i [%1] == [arm64]       ( set __VCBuildArch=x86_arm64&&shift&goto Arg_Loop)
+
+shift
+goto :Arg_Loop
+
+:ToolsVersion
+:: Default to highest Visual Studio version available
+::
+:: For VS2017 and later, multiple instances can be installed on the same box SxS and VSxxxCOMNTOOLS is only set if the user
+:: has launched the VS2017 or VS2019 Developer Command Prompt.
+::
+:: Following this logic, we will default to the VS2017 or VS2019 toolset if VS150COMNTOOLS or VS160COMMONTOOLS tools is
+:: set, as this indicates the user is running from the VS2017 or VS2019 Developer Command Prompt and
+:: is already configured to use that toolset. Otherwise, we will fail the script if no supported VS instance can be found.
+
+if defined VisualStudioVersion goto :RunVCVars
+
+set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
+if exist %_VSWHERE% (
+  for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools
+)
+if not exist "%_VSCOMNTOOLS%" goto :MissingVersion
+
+call "%_VSCOMNTOOLS%\VsDevCmd.bat" -no_logo
+
+:RunVCVars
+if "%VisualStudioVersion%"=="16.0" (
+    goto :VS2019
+) else if "%VisualStudioVersion%"=="15.0" (
+    goto :VS2017
+)
+
+:MissingVersion
+:: Can't find appropriate VS install
+echo Error: Visual Studio 2019 required
+echo        Please see https://github.com/dotnet/runtime/tree/master/docs/workflow/building/libraries for build instructions.
+exit /b 1
+
+:VS2019
+:: Setup vars for VS2019
+set __VSVersion=vs2019
+set __PlatformToolset=v142
+:: Set the environment for the native build
+call "%VS160COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
+goto FindDIASDK
+
+:VS2017
+:: Setup vars for VS2017
+set __VSVersion=vs2017
+set __PlatformToolset=v141
+:: Set the environment for the native build
+call "%VS150COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
+goto FindDIASDK
+
+:FindDIASDK
+if exist "%VSINSTALLDIR%DIA SDK" goto CheckRepoRoot
+echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^
+Did you install all the requirements for building on Windows, including the "Desktop Development with C++" workload? ^
+Please see https://github.com/dotnet/runtime/blob/master/docs/workflow/requirements/windows-requirements.md ^
+Another possibility is that you have a parallel installation of Visual Studio and the DIA SDK is there. In this case it ^
+may help to copy its "DIA SDK" folder into "%VSINSTALLDIR%" manually, then try again.
+exit /b 1
+
+:CheckRepoRoot
+
+if exist "%__repoRoot%" goto :FindCMake
+:: Can't find repo root
+echo Error: variable __repoRoot not set.
+exit /b 1
+
+:FindCMake
+:: Find CMake
+
+:: Eval the output from set-cmake-path.ps1
+for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "cd "%__repoRoot:"=%"; & eng\native\set-cmake-path.ps1"') do %%a
index b6df1c2..310d2ba 100644 (file)
@@ -1,12 +1,15 @@
 cmake_minimum_required(VERSION 3.14.5)
 
+if (CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15)
+  cmake_policy(SET CMP0091 NEW)
+endif()
+
 project(mono)
 
 include(GNUInstallDirs)
 include(CheckIncludeFile)
 include(CheckFunctionExists)
 include(TestBigEndian)
-include(FindPkgConfig)
 include(CheckCCompilerFlag)
 
 include("cmake/QuietOSXRanlib.cmake")
@@ -30,8 +33,6 @@ endfunction()
 
 # User options
 include(options)
-# Header/function checks
-include(configure)
 
 function(process_enable_minimal)
   string(REPLACE "," ";" tmp1 "${ENABLE_MINIMAL}")
@@ -45,16 +46,23 @@ if(ENABLE_MINIMAL)
   process_enable_minimal()
 endif()
 
-execute_process(
-  COMMAND grep ^MONO_CORLIB_VERSION= ${CMAKE_CURRENT_SOURCE_DIR}/configure.ac
-  COMMAND cut -d = -f  2
-  OUTPUT_VARIABLE CORLIB_VERSION_OUT
-)
-if(CORLIB_VERSION_OUT STREQUAL "")
-  message(FATAL_ERROR)
-endif()
-string(STRIP "${CORLIB_VERSION_OUT}" MONO_CORLIB_VERSION_BASE)
-set(MONO_CORLIB_VERSION "\"${MONO_CORLIB_VERSION_BASE}\"")
+function(extract_mono_corlib_version)
+  file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/configure.ac corlib_version_line REGEX ^MONO_CORLIB_VERSION=)
+
+  if(corlib_version_line STREQUAL "")
+    message(FATAL_ERROR "Couldn't find MONO_CORLIB_VERSION from configure.ac")
+  endif()
+
+  string(REGEX REPLACE "MONO_CORLIB_VERSION=([0-9a-fA-F\-]+)" "\\1" corlib_version ${corlib_version_line})
+
+  if(corlib_version STREQUAL "")
+    message(FATAL_ERROR "Couldn't parse corlib version")
+  endif()
+
+  set(MONO_CORLIB_VERSION "\"${corlib_version}\"" PARENT_SCOPE)
+endfunction()
+
+extract_mono_corlib_version()
 
 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mono.proj")
   set(ENABLE_NETCORE 1)
@@ -96,31 +104,26 @@ if(ENABLE_LAZY_GC_THREAD_CREATION)
   set(LAZY_GC_THREAD_CREATION 1)
 endif()
 
-#FIXME:
-set(VERSION "\"\"")
 set(DISABLED_FEATURES "\"\"")
 
 if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
   set(GCC 1)
 endif()
 
-add_definitions(-g)
 add_definitions(-DHAVE_CONFIG_H)
-add_definitions(-D_THREAD_SAFE)
+add_definitions(-DMONO_DLL_EXPORT)
 
 if(GCC)
+  add_definitions(-g)  # TODO: should this really be on by default?
   add_definitions(-fPIC)
-  add_definitions(-DMONO_DLL_EXPORT)
   add_definitions(-fvisibility=hidden)
+  set(USE_GCC_ATOMIC_OPS 1)
 endif()
 
-set(USE_GCC_ATOMIC_OPS 1)
 set(HAVE_CLASSIC_WINAPI_SUPPORT 1)
 set(HAVE_MOVING_COLLECTOR 1)
 set(HAVE_CONC_GC_AS_DEFAULT 1)
 set(MONO_INSIDE_RUNTIME 1)
-# FIXME:
-set(NAME_DEV_RANDOM "/dev/random")
 
 ######################################
 # AOT CROSS COMPILER SUPPORT
@@ -156,39 +159,6 @@ if(NOT AOT_TARGET_TRIPLE STREQUAL "")
 endif()
 
 ######################################
-# GCC CHECKS
-######################################
-
-if(GCC)
-  # We require C99 with some GNU extensions, e.g. `linux` macro
-  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
-  # The runtime code does not respect ANSI C strict aliasing rules
-  append("-fno-strict-aliasing" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
-  # 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 -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs -Wno-format-zero-length -Wno-unused-function")
-
-  if (CMAKE_C_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=incompatible-pointer-types")
-  endif()
-  set(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)
-  endif()
-endif()
-
-######################################
 # HOST OS CHECKS
 ######################################
 
@@ -197,6 +167,7 @@ message ("CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")
 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
   add_definitions(-D_THREAD_SAFE)
   set(HOST_DARWIN 1)
+  set(HOST_OSX 1)
   set(PTHREAD_POINTER_ID 1)
   set(USE_MACH_SEMA 1)
 elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "tvOS")
@@ -206,38 +177,26 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "tvOS")
   add_definitions(-D_THREAD_SAFE)
   set(HOST_DARWIN 1)
   set(HOST_IOS 1)
+  if(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
+    set(HOST_TVOS 1)
+  endif()
   set(PTHREAD_POINTER_ID 1)
   set(USE_MACH_SEMA 1)
   set(DISABLE_EXECUTABLES 1)
   set(DISABLE_CRASH_REPORTING 1)
-  set(HAVE_SYSTEM 0)
-  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()
+  set(ENABLE_MONOTOUCH 1)
+  add_definitions(-DMONOTOUCH=1)
   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)
+  add_definitions(-D_THREAD_SAFE)
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
   set(HOST_LINUX 1)
   add_definitions(-D_GNU_SOURCE -D_REENTRANT)
+  add_definitions(-D_THREAD_SAFE)
   # The normal check fails because it uses --isystem <ndk root>/sysroot/usr/include
   set(HAVE_USR_INCLUDE_MALLOC_H 1)
   set(HOST_ANDROID 1)
@@ -250,6 +209,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
   set(HAVE_SCHED_SETAFFINITY 0)
   # FIXME: Rest of the flags from configure.ac
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
+  add_definitions(-D_THREAD_SAFE)
   set(HOST_WASM 1)
   set(TARGET_ARCH "wasm")
   # CMAKE_SYSTEM_PROCESSOR is set to x86
@@ -259,6 +219,28 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
   set(DISABLE_SHARED_LIBS 1)
   # sys/random.h exists, but its not found
   set(HAVE_SYS_RANDOM_H 1)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+  set(HOST_WIN32 1)
+  set(DISABLE_CRASH_REPORTING 1)
+  set(DISABLE_PORTABILITY 1)
+  set(HOST_NO_SYMLINKS 1)
+  set(MONO_KEYWORD_THREAD "__declspec (thread)")
+  set(MONO_ZERO_LEN_ARRAY 1)
+
+  # FIXME: disable SIMD support for Windows, see https://github.com/dotnet/runtime/issues/1933
+  set(DISABLE_SIMD 1)
+
+  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") # statically link VC runtime library
+  add_compile_options(/W3)   # set warning level 3
+  add_compile_options(/EHsc) # set exception handling behavior
+  add_compile_options(/FC)   # use full pathnames in diagnostics
+  if(CMAKE_BUILD_TYPE STREQUAL "Release")
+    add_compile_options(/Oi) # enable intrinsics
+    add_compile_options(/GF) # enable string pooling
+    add_compile_options(/Zi) # enable debugging information
+    add_compile_options(/GL) # whole program optimization
+    add_link_options(/LTCG)  # link-time code generation
+  endif()
 else()
   message(FATAL_ERROR "Host '${CMAKE_SYSTEM_NAME}' not supported.")
 endif()
@@ -274,15 +256,21 @@ endif()
 if(TARGET_SYSTEM_NAME STREQUAL "Darwin")
   set(TARGET_MACH 1)
   set(TARGET_OSX 1)
+  set(TARGET_DARWIN 1)
   if (GC_SUSPEND STREQUAL "default")
     set(GC_SUSPEND "hybrid")
   endif()
 elseif(TARGET_SYSTEM_NAME STREQUAL "iOS" OR TARGET_SYSTEM_NAME STREQUAL "tvOS")
   set(TARGET_MACH 1)
   set(TARGET_IOS 1)
+  set(TARGET_DARWIN 1)
+  if(TARGET_SYSTEM_NAME STREQUAL "tvOS")
+    set(TARGET_TVOS 1)
+  endif()
   set(ENABLE_MONOTOUCH 1)
   add_definitions(-DMONOTOUCH=1)
 elseif(TARGET_SYSTEM_NAME STREQUAL "Linux")
+  set(TARGET_LINUX 1)
 elseif(TARGET_SYSTEM_NAME STREQUAL "Android")
   set(TARGET_ANDROID 1)
 elseif(TARGET_SYSTEM_NAME STREQUAL "Emscripten")
@@ -290,6 +278,8 @@ elseif(TARGET_SYSTEM_NAME STREQUAL "Emscripten")
   if (CMAKE_BUILD_TYPE STREQUAL "Release")
     add_compile_options(-Os)
   endif()
+elseif(TARGET_SYSTEM_NAME STREQUAL "Windows")
+  set(TARGET_WIN32 1)
 else()
   message(FATAL_ERROR "Target '${TARGET_SYSTEM_NAME}' not supported.")
 endif()
@@ -316,7 +306,7 @@ endif()
 
 message ("CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
 
-if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
   set(HOST_AMD64 1)
 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
   set(HOST_X86 1)
@@ -344,6 +334,8 @@ elseif(TARGET_ARCH STREQUAL "i686")
   set(TARGET_ARCH "x86")
 elseif(TARGET_ARCH STREQUAL "aarch64")
   set(TARGET_ARCH "arm64")
+elseif(TARGET_ARCH STREQUAL "AMD64")
+  set(TARGET_ARCH "x86_64")
 endif()
 
 message("TARGET_ARCH=${TARGET_ARCH}")
@@ -379,6 +371,44 @@ else()
 endif()
 
 ######################################
+# HEADER/FUNCTION CHECKS
+######################################
+include(configure)
+
+######################################
+# GCC CHECKS
+######################################
+
+if(GCC)
+  # We require C99 with some GNU extensions, e.g. `linux` macro
+  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+  # The runtime code does not respect ANSI C strict aliasing rules
+  append("-fno-strict-aliasing" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+  # 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 -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs -Wno-format-zero-length -Wno-unused-function")
+
+  if (CMAKE_C_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=incompatible-pointer-types")
+  endif()
+  set(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)
+  endif()
+endif()
+
+######################################
 # LLVM CHECKS
 ######################################
 set(LLVM_LIBS)
@@ -402,8 +432,8 @@ if(LLVM_PREFIX)
     set(llvm_config_path "${LLVM_PREFIX}/include/llvm/Config/llvm-config.h")
 
     # llvm-config --mono-api-version
-    find_program(AWK awk mawk gawk)
-    execute_process(COMMAND /bin/sh -c "\"${AWK}\" '/MONO_API_VERSION/ { print $3 }' ${llvm_config_path}" RESULT_VARIABLE awk_res OUTPUT_VARIABLE llvm_api_version OUTPUT_STRIP_TRAILING_WHITESPACE)
+    file(STRINGS ${llvm_config_path} llvm_api_version_line REGEX "MONO_API_VERSION ")
+    string(REGEX REPLACE ".*MONO_API_VERSION ([0-9]+)" "\\1" llvm_api_version ${llvm_api_version_line})
 
     # llvm-config --cflags
     set(llvm_cflags "-I${LLVM_PREFIX}/include")
@@ -444,7 +474,7 @@ if(LLVM_PREFIX)
     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 mcjit orcjit ${llvm_codegen_libs} OUTPUT_VARIABLE llvm_libs OUTPUT_STRIP_TRAILING_WHITESPACE)
-endif()
+  endif()
 
   if (${llvm_api_version} LESS 900)
     message(FATAL_ERROR "LLVM version too old.")
@@ -464,7 +494,8 @@ endif()
 ######################################
 set(ICU_SHIM_PATH "../../../libraries/Native/Unix/System.Globalization.Native")
 if(MONO_CROSS_COMPILE)
-elseif(TARGET_OSX)
+elseif(HOST_OSX)
+  include(FindPkgConfig)
   # FIXME: Handle errors
   # Defines ICU_INCLUDEDIR/ICU_LIBDIR
   set(ENV{PKG_CONFIG_PATH} "{$PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig")
@@ -472,23 +503,27 @@ elseif(TARGET_OSX)
   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-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations")
   set(HAVE_SYS_ICU 1)
-elseif(TARGET_WASM)
+elseif(HOST_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-extra-semi-stmt -Wno-unknown-warning-option")
   set(HAVE_SYS_ICU 1)
   set(STATIC_ICU 1)
   set(ICU_LIBS "icucore")
-elseif(TARGET_IOS)
+elseif(HOST_IOS)
   # FIXME:
-elseif(TARGET_ANDROID)
+elseif(HOST_ANDROID)
   set(ICU_FLAGS "-DPALEXPORT=\"\" -DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -DHAVE_SET_MAX_VARIABLE -DTARGET_UNIX -DTARGET_ANDROID -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(HAVE_SYS_ICU 1)
 elseif(HOST_LINUX)
+  include(FindPkgConfig)
   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)
+elseif(HOST_WIN32)
+  set(ICU_FLAGS "-DTARGET_WINDOWS -DPALEXPORT=EXTERN_C")
+  set(HAVE_SYS_ICU 1)
 else()
-  message(FATAL_ERROR "")
+  message(FATAL_ERROR "Unknown host")
 endif()
 
 ######################################
@@ -511,7 +546,7 @@ set(BREAKPOINT "G_STMT_START { raise(SIGTRAP); } G_STMT_END")
 if(GCC)
   set(GNUC_UNUSED "__attribute__((__unused__))")
   set(GNUC_NORETURN "__attribute__((__noreturn__))")
-  if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86|x86_64")
+  if(HOST_AMD64 OR HOST_X86)
     set(BREAKPOINT "G_STMT_START { __asm__(\"int \$03\"); } G_STMT_END")
   endif()
 endif()
@@ -522,9 +557,11 @@ else()
   set(ORDER G_LITTLE_ENDIAN)
 endif()
 
-if(WIN32)
-  # FIXME:
-  message(FATAL_ERROR "FIXME")
+if(HOST_WIN32)
+  set(PATHSEP "\\")
+  set(SEARCHSEP ";")
+  set(OS "WIN32")
+  set(PIDTYPE "void *")
 else()
   set(PATHSEP "/")
   set(SEARCHSEP ":")
@@ -573,21 +610,51 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
 endif()
 ### End of debug build checks
 
+######################################
+# OTHER CHECKS
+######################################
+if(HOST_WIN32)
+  set(NAME_DEV_RANDOM "\"\"")
+else()
+  # FIXME:
+  set(NAME_DEV_RANDOM "\"/dev/random\"")
+endif()
+### End of other checks
+
+######################################
+# EXTRACT VERSION
+######################################
+if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
+  file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/_version.h" product_version_string_line REGEX "VER_PRODUCTVERSION_STR ")
+  string(REGEX REPLACE ".*VER_PRODUCTVERSION_STR *(.*)" "\\1" product_version_string ${product_version_string_line})
+else()
+  file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/_version.h" product_version_string_line REGEX "sccsid")
+  string(REGEX REPLACE ".*Version *(.*)\";" "\"\\1\"" product_version_string ${product_version_string_line})
+endif()
+
+file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/runtime_version.h" runtime_version_major_line REGEX "RuntimeProductMajorVersion ")
+file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/runtime_version.h" runtime_version_minor_line REGEX "RuntimeProductMinorVersion ")
+file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/runtime_version.h" runtime_version_patch_line REGEX "RuntimeProductPatchVersion ")
+string(REGEX REPLACE ".*RuntimeProductMajorVersion *([0-9]+)" "\\1" runtime_version_major ${runtime_version_major_line})
+string(REGEX REPLACE ".*RuntimeProductMinorVersion *([0-9]+)" "\\1" runtime_version_minor ${runtime_version_minor_line})
+string(REGEX REPLACE ".*RuntimeProductPatchVersion *([0-9]+)" "\\1" runtime_version_patch ${runtime_version_patch_line})
+
+set(VERSION "\"${runtime_version_major}.${runtime_version_minor}.${runtime_version_patch}.0\"")
+set(FULL_VERSION ${product_version_string})
+### End of extract version
 
 ######################################
 # OS SPECIFIC CHECKS
 ######################################
-if(ENABLE_NETCORE)
-  if(TARGET_IOS OR TARGET_ANDROID)
-    # FIXME: the mobile products use mono_dllmap_insert so allow this
-    unset(DISABLE_DLLMAP)
-  else()
-    set(DISABLE_DLLMAP 1)
-  endif()
+if(TARGET_IOS OR TARGET_ANDROID)
+  # FIXME: the mobile products use mono_dllmap_insert so allow this
+  unset(DISABLE_DLLMAP)
+else()
+  set(DISABLE_DLLMAP 1)
 endif()
 ### End of OS specific checks
 
 add_subdirectory(mono)
 
 configure_file(cmake/config.h.in config.h)
-configure_file(cmake/eglib-config.h.cmake.in mono/eglib/eglib-config.h)
+configure_file(cmake/eglib-config.h.cmake.in mono/eglib/eglib-config.h)  # TODO: eglib-config.h is not needed, we're using hardcoded eglib-config.hw
index 91ff911..20f40bc 100644 (file)
@@ -74,9 +74,6 @@
   </PropertyGroup>
 
   <PropertyGroup>
-    <CL_MPCount>$(NumberOfCores)</CL_MPCount>
-  </PropertyGroup>
-  <PropertyGroup>
     <!-- Enables Strict mode for Roslyn compiler -->
     <Features>strict;nullablePublicOnly</Features>
   </PropertyGroup>
index 4dec760..a610c55 100644 (file)
@@ -1,3 +1,8 @@
+#ifdef _MSC_VER
+#include <msvc/msvc-win32-support.h>
+#include <msvc/msvc-disabled-warnings.h>
+#endif
+
 /* Define to the full name of this package. */
 #cmakedefine PACKAGE_NAME 1
 
 #cmakedefine HAVE_NULL_GC 1
 
 /* Length of zero length arrays */
-#cmakedefine MONO_ZERO_LEN_ARRAY 1
+#define MONO_ZERO_LEN_ARRAY @MONO_ZERO_LEN_ARRAY@
 
 /* Define to 1 if you have the <signal.h> header file. */
 #cmakedefine HAVE_SIGNAL_H 1
 #cmakedefine HAVE_SETPGID 1
 
 /* Define to 1 if you have the `system' function. */
+#ifdef _MSC_VER
+#if HAVE_WINAPI_FAMILY_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
+#cmakedefine HAVE_SYSTEM 1
+#endif
+#else
 #cmakedefine HAVE_SYSTEM 1
+#endif
 
 /* Define to 1 if you have the `fork' function. */
 #cmakedefine HAVE_FORK 1
 #cmakedefine HAVE_EXECVP 1
 
 /* Name of /dev/random */
-#cmakedefine NAME_DEV_RANDOM "@NAME_DEV_RANDOM@"
+#define NAME_DEV_RANDOM @NAME_DEV_RANDOM@
 
 /* Have /dev/random */
 #cmakedefine HAVE_CRYPT_RNG 1
 #cmakedefine DISABLE_QCALLS 1
 
 /* Have __thread keyword */
-#cmakedefine MONO_KEYWORD_THREAD 1
+#cmakedefine MONO_KEYWORD_THREAD @MONO_KEYWORD_THREAD@
 
 /* tls_model available */
 #cmakedefine HAVE_TLS_MODEL_ATTR 1
 /* Version number of package */
 #define VERSION @VERSION@
 
+/* Full version number of package */
+#define FULL_VERSION @FULL_VERSION@
+
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #cmakedefine HAVE_DLFCN_H 1
 
 
 /* Enable runtime checks of mempool references between metadata images (must set env var MONO_CHECK_MODE=metadata) */
 #cmakedefine ENABLE_CHECKED_BUILD_METADATA 1
+
+#if defined(ENABLE_LLVM) && defined(HOST_WIN32) && defined(TARGET_WIN32) && (!defined(TARGET_AMD64) || !defined(_MSC_VER))
+#error LLVM for host=Windows and target=Windows is only supported on x64 MSVC build.
+#endif
index f0c0943..f7e6e78 100644 (file)
@@ -5,9 +5,15 @@
 include(CheckTypeSize)
 include(CheckStructHasMember)
 include(CheckSymbolExists)
-
-if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
-  set(DARWIN 1)
+include(CheckCCompilerFlag)
+
+# Apple platforms like macOS/iOS allow targeting older operating system versions with a single SDK,
+# the mere presence of a symbol in the SDK doesn't tell us whether the deployment target really supports it.
+# The compiler raises a warning when using an unsupported API, turn that into an error so check_symbol_exists()
+# can correctly identify whether the API is supported on the target.
+check_c_compiler_flag("-Wunguarded-availability" "C_SUPPORTS_WUNGUARDED_AVAILABILITY")
+if(C_SUPPORTS_WUNGUARDED_AVAILABILITY)
+  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unguarded-availability")
 endif()
 
 function(ac_check_headers)
@@ -52,8 +58,8 @@ ac_check_headers (
   sys/mkdev.h sys/types.h sys/stat.h sys/filio.h sys/sockio.h sys/utime.h sys/un.h sys/syscall.h sys/uio.h sys/param.h sys/sysctl.h
   sys/prctl.h sys/socket.h sys/utsname.h sys/select.h sys/inotify.h sys/user.h sys/poll.h sys/wait.h sts/auxv.h sys/resource.h
   sys/event.h sys/ioctl.h sys/errno.h sys/sendfile.h sys/statvfs.h sys/statfs.h sys/mman.h sys/mount.h sys/time.h sys/random.h
-  memory.h strings.h stdint.h unistd.h netdb.h utime.h semaphore.h libproc.h alloca.h ucontext.h pwd.h
-  gnu/lib-names.h netinet/tcp.h netinet/in.h link.h arpa/inet.h unwind.h poll.h grp.h wchar.h linux/magic.h
+  memory.h strings.h string.h stdint.h signal.h inttypes.h stdlib.h unistd.h netdb.h utime.h semaphore.h libproc.h alloca.h ucontext.h pwd.h
+  gnu/lib-names.h netinet/tcp.h netinet/in.h link.h arpa/inet.h complex.h unwind.h poll.h grp.h wchar.h linux/magic.h
   android/legacy_signal_inlines.h android/ndk-version.h execinfo.h pthread.h pthread_np.h net/if.h dirent.h
   CommonCrypto/CommonDigest.h curses.h term.h termios.h dlfcn.h getopt.h pwd.h iconv.h alloca.h
   /usr/include/malloc.h)
@@ -69,7 +75,8 @@ ac_check_funcs (
   gethrtime read_real_time gethostbyname gethostbyname2 getnameinfo getifaddrs if_nametoindex
   access inet_ntop Qp2getifaddrs)
 
-if (NOT DARWIN)
+if(NOT HOST_DARWIN)
+  # getentropy was introduced in macOS 10.12 / iOS 10.0
   ac_check_funcs (getentropy)
 endif()
 
@@ -123,3 +130,37 @@ file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c
 )
 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")
+
+
+if(HOST_WIN32)
+  # checking for this doesn't work for some reason, hardcode result
+  set(HAVE_WINTERNL_H 1)
+  set(HAVE_SIGNAL 1)
+  set(HAVE_CRYPT_RNG 1)
+  set(HAVE_GETADDRINFO 1)
+  set(HAVE_GETNAMEINFO 1)
+  set(HAVE_GETPROTOBYNAME 1)
+  set(HAVE_INET_NTOP 1)
+  set(HAVE_INET_PTON 1)
+  set(HAVE_STRUCT_SOCKADDR_IN6 1)
+  set(HAVE_STRUCT_IP_MREQ 1)
+  set(HAVE_STRTOK_R 1)
+  set(HAVE_EXECVP 0)
+endif()
+
+if(HOST_IOS)
+  set(HAVE_SYSTEM 0)
+  set(HAVE_GETPWUID_R 0)
+  set(HAVE_SYS_USER_H 0)
+  set(HAVE_GETENTROPY 0)
+  if(HOST_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()
+endif()
\ No newline at end of file
index d8bc291..afde59e 100644 (file)
     <Error Condition="'$(TargetsAndroid)' == 'true' and '$(Platform)' != 'x64' and '$(Platform)' != 'x86' and '$(Platform)' != 'arm64' and '$(Platform)' != 'arm'" Text="Error: Invalid platform for $(TargetOS): $(Platform)." />
     <Error Condition="'$(TargetsBrowser)' == 'true' and '$(EMSDK_PATH)' == ''" Text="The EMSDK_PATH environment variable should be set pointing to the emscripten SDK root dir."/>
     <Error Condition="'$(TargetsAndroid)' == 'true' and '$(ANDROID_NDK_ROOT)' == ''" Text="Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root." />
-  </Target>
-
-  <!-- Windows Mono runtime build -->
-  <Target Name="BuildMonoRuntimeWindows" Condition="'$(OS)' == 'Windows_NT'">
+    <Error Condition="'$(OS)' == 'Windows_NT' and ('$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true')" Text="Error: Mono runtime for $(TargetOS) can't be built on Windows." />
 
-    <!-- Sanity checks -->
-    <Error Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'" Text="Error: Mono runtime for $(TargetOS) can't be built on Windows." />
-
-    <ItemGroup>
-      <_MonoBuildParams Include="/p:MONO_BUILD_DIR_PREFIX=&quot;&quot;$(MonoObjDir)&quot;&quot;" />
-      <_MonoBuildParams Include="/p:MONO_ENABLE_NETCORE=true" />
-      <_MonoBuildParams Include="/p:MONO_ENABLE_PERFTRACING=true" />
-      <_MonoBuildParams Include="/p:MONO_USE_STATIC_C_RUNTIME=true" />
-      <_MonoBuildParams Include="/p:CL_MPCount=$([System.Environment]::ProcessorCount)" />
-      <_MonoBuildParams Include="/v:minimal" />
-      <_MonoBuildParams Condition="$(MonoEnableLLVM) == true" Include="/p:MONO_ENABLE_LLVM=true" />
-      <_MonoBuildParams Condition="$(MonoEnableLLVM) == true" Include="/p:MONO_EXTERNAL_LLVM_CONFIG=&quot;&quot;$(MonoLLVMDir)\bin\llvm-config.exe&quot;&quot;" />
-    </ItemGroup>
+    <!-- check if Ninja is available and default to it on Unix platforms -->
+    <Exec Condition="'$(OS)' != 'Windows_NT' and '$(Ninja)' == ''" Command="which ninja" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" StandardOutputImportance="Low" >
+      <Output TaskParameter="ExitCode" PropertyName="_MonoFindNinjaExitCode"/>
+    </Exec>
     <PropertyGroup>
-      <_MonoBuildPlatform Condition="'$(Platform)' == 'x64'">x64</_MonoBuildPlatform>
-      <_MonoBuildPlatform Condition="'$(Platform)' == 'x86'">win32</_MonoBuildPlatform>
-
-      <_MonoBuildCommand>msvc\run-msbuild.bat build $(_MonoBuildPlatform) $(Configuration) sgen &quot;@(_MonoBuildParams, ' ')&quot; msvc\mono-netcore.sln</_MonoBuildCommand>
+      <_MonoUseNinja Condition="'$(Ninja)' == 'true' or '$(_MonoFindNinjaExitCode)' == '0'">true</_MonoUseNinja>
     </PropertyGroup>
-
-    <Message Text="--- Building Mono ---" Importance="High" />
-    <Exec Command="$(_MonoBuildCommand)" IgnoreStandardErrorWarningFormat="true" />
   </Target>
 
   <!-- Copy Mono runtime bits to $(Destination) -->
     <Exec Condition="'$(OS)' != 'Windows_NT'" Command="$(MonoProjectRoot)../tests/run.sh $(CoreClrTestConfig)" ContinueOnError="ErrorAndContinue" />
   </Target>
 
-  <!-- OSX/iOS/tvOS/Android/Linux Mono runtime build -->
-  <Target Name="BuildMonoRuntimeUnix" Condition="'$(OS)' != 'Windows_NT'">
-    <Exec Command="which ninja" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true">
-      <Output TaskParameter="ExitCode" PropertyName="MonoNinjaFound"/>
-    </Exec>
-    <PropertyGroup>
-      <_MonoVerboseArg Condition="'$(MonoVerboseBuild)' == 'true' and '$(MonoNinjaFound)' == '0'">-v</_MonoVerboseArg>
-      <_MonoVerboseArg Condition="'$(MonoVerboseBuild)' == 'true' and '$(MonoNinjaFound)' != '0'">VERBOSE=1</_MonoVerboseArg>
-      <MonoBuildTool Condition="'$(MonoNinjaFound)' == '0'">ninja</MonoBuildTool>
-      <MonoBuildTool Condition="'$(MonoNinjaFound)' != '0'">make -j$([System.Environment]::ProcessorCount)</MonoBuildTool>
-    </PropertyGroup>
+  <!-- Mono runtime build -->
+  <Target Name="BuildMonoRuntime">
     <ItemGroup>
-      <_MonoCMakeArgs Condition="'$(MonoBuildTool)' == 'ninja'" Include="-G Ninja"/>
+      <_MonoCMakeArgs Condition="'$(_MonoUseNinja)' == 'true'" Include="-G Ninja"/>
       <_MonoCMakeArgs Include="-DCMAKE_INSTALL_PREFIX=$(MonoObjDir)out"/>
       <_MonoCMakeArgs Include="-DCMAKE_INSTALL_LIBDIR=lib"/>
       <_MonoCMakeArgs Include="-DCMAKE_BUILD_TYPE=$(Configuration)"/>
       <_MonoBuildEnv Condition="'$(Platform)' == 'arm'" Include="PKG_CONFIG_PATH=$(MonoCrossDir)/usr/lib/arm-linux-gnueabihf/pkgconfig" />
     </ItemGroup>
 
+    <!-- Windows specific options -->
+    <ItemGroup Condition="'$(TargetsWindows)' == 'true'">
+      <_MonoCPPFLAGS Include="-DWIN32" />
+      <_MonoCPPFLAGS Include="-DWIN32_LEAN_AND_MEAN" />
+      <!--<_MonoCPPFLAGS Include="-D_WINDOWS" />--> <!-- set in monow.vcxproj, not sure we really need it -->
+      <_MonoCPPFLAGS Condition="'$(Platform)' == 'x64' or '$(Platform)' == 'arm64'" Include="-DWIN64" />
+      <_MonoCPPFLAGS Condition="'$(Configuration)' == 'Release'" Include="-DNDEBUG" />
+      <_MonoCPPFLAGS Condition="'$(Configuration)' == 'Debug'" Include="-D_DEBUG" />
+      <!-- <_MonoCPPFLAGS Include="-D__default_codegen__" /> --> <!-- doesn't seem to be used -->
+      <_MonoCPPFLAGS Include="-D_CRT_SECURE_NO_WARNINGS" />
+      <_MonoCPPFLAGS Include="-D_CRT_NONSTDC_NO_DEPRECATE" />
+      <!--<_MonoCPPFLAGS Include="-DGC_NOT_DLL" />--> <!-- only used for Boehm -->
+      <_MonoCPPFLAGS Include="-DWIN32_THREADS" />
+      <_MonoCPPFLAGS Include="-DWINVER=0x0601" />
+      <_MonoCPPFLAGS Include="-D_WIN32_WINNT=0x0601" />
+      <_MonoCPPFLAGS Include="-D_WIN32_IE=0x0501" />
+      <_MonoCPPFLAGS Include="-D_UNICODE" />
+      <_MonoCPPFLAGS Include="-DUNICODE" />
+      <_MonoCPPFLAGS Include="-DFD_SETSIZE=1024" />
+      <_MonoCPPFLAGS Include="-DNVALGRIND" />
+    </ItemGroup>
     <!-- OSX specific options -->
     <ItemGroup Condition="'$(TargetsOSX)' == 'true'">
       <_MonoCMakeArgs Include="-DCMAKE_OSX_DEPLOYMENT_TARGET=$(macOSVersionMin)" />
       <_MonoCMakeSysroot Condition="'$(TargetstvOS)' == 'true' and '$(TargetstvOSSimulator)' == 'true'">$(XcodeDir)/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator$(tvOSVersion).sdk</_MonoCMakeSysroot>
       <_MonoCMakeSystemName Condition="'$(TargetsiOS)' == 'true'">iOS</_MonoCMakeSystemName>
       <_MonoCMakeSystemName Condition="'$(TargetstvOS)' == 'true'">tvOS</_MonoCMakeSystemName>
-      <_MonoCMakeVersionMin Condition="'$(TargetstvOS)' == 'true'">$(tvOSVersionMin)</_MonoCMakeVersionMin>
       <_MonoCMakeVersionMin Condition="'$(TargetsiOS)' == 'true'">$(iOSVersionMin)</_MonoCMakeVersionMin>
       <_MonoCMakeVersionMin Condition="'$(TargetstvOS)' == 'true'">$(tvOSVersionMin)</_MonoCMakeVersionMin>
     </PropertyGroup>
       <_MonoCMakeArgs Include="$(_MonoCFLAGSOption)"/>
       <_MonoCMakeArgs Include="$(_MonoCXXFLAGSOption)"/>
     </ItemGroup>
+
+    <PropertyGroup>
+      <_MonoCMakeConfigureCommand>cmake @(_MonoCMakeArgs, ' ') $(MonoProjectRoot)</_MonoCMakeConfigureCommand>
+      <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(_MonoRunInitCompiler)' != 'false' and '$(OS)' != 'Windows_NT'">bash -c 'source $(RepositoryEngineeringDir)native/init-compiler.sh $(Platform) $(MonoCCompiler) &amp;&amp; @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand)'</_MonoCMakeConfigureCommand>
+      <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(_MonoRunInitCompiler)' != 'false' and '$(OS)' == 'Windows_NT'">set __repoRoot=&quot;$(RepoRoot)&quot; &amp;&amp; call &quot;$(RepositoryEngineeringDir)native\init-compiler-and-cmake.cmd&quot; $(Platform) &amp;&amp; @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand)</_MonoCMakeConfigureCommand>
+      <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(_MonoRunInitCompiler)' == 'false'">$(_MonoCCOption) $(_MonoCXXOption) @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand)</_MonoCMakeConfigureCommand>
+      <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' == 'true'">bash -c 'source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcmake $(_MonoCMakeConfigureCommand)'</_MonoCMakeConfigureCommand>
+
+      <_MonoCMakeBuildCommand>cmake --build . --target install --config $(Configuration)</_MonoCMakeBuildCommand>
+      <_MonoCMakeBuildCommand Condition="'$(MonoVerboseBuild)' == 'true'">$(_MonoCMakeBuildCommand) --verbose</_MonoCMakeBuildCommand>
+      <_MonoCMakeBuildCommand Condition="'$(_MonoUseNinja)' != 'true'">$(_MonoCMakeBuildCommand) --parallel $([System.Environment]::ProcessorCount)</_MonoCMakeBuildCommand>
+      <_MonoCMakeBuildCommand Condition="'$(TargetsBrowser)' != 'true' and '$(OS)' != 'Windows_NT'">@(_MonoBuildEnv, ' ') $(_MonoCMakeBuildCommand)</_MonoCMakeBuildCommand>
+      <_MonoCMakeBuildCommand Condition="'$(TargetsBrowser)' != 'true' and '$(OS)' == 'Windows_NT'">set __repoRoot=&quot;$(RepoRoot)&quot; &amp;&amp; call &quot;$(RepositoryEngineeringDir)native\init-compiler-and-cmake.cmd&quot; $(Platform) &amp;&amp; @(_MonoBuildEnv, ' ') $(_MonoCMakeBuildCommand)</_MonoCMakeBuildCommand>
+    </PropertyGroup>
+
     <MakeDir Directories="$(MonoObjDir)" />
-    <Message Text="Running 'cmake @(_MonoCMakeArgs, ' ') $(MonoProjectRoot)' in '$(MonoObjDir)'" Importance="High"/>
-    <!-- cmake -->
-    <Exec Condition="'$(TargetsBrowser)' != 'true' and '$(_MonoRunInitCompiler)' != 'false'" Command="bash -c 'source $(RepositoryEngineeringDir)native/init-compiler.sh $(Platform) $(MonoCCompiler) &amp;&amp; @(_MonoBuildEnv, ' ') cmake @(_MonoCMakeArgs, ' ') $(MonoProjectRoot)'" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)"/>
-    <Exec Condition="'$(TargetsBrowser)' != 'true' and '$(_MonoRunInitCompiler)' == 'false'" Command="$(_MonoCCOption) $(_MonoCXXOption) @(_MonoBuildEnv, ' ') cmake @(_MonoCMakeArgs, ' ') $(MonoProjectRoot)" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)"/>
-    <Exec Condition="'$(TargetsBrowser)' == 'true'" Command="bash -c 'source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emcmake cmake @(_MonoCMakeArgs, ' ') $(MonoProjectRoot)'" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)" />
-    <!-- ninja/make -->
-    <Exec Condition="'$(TargetsBrowser)' != 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Command="@(_MonoBuildEnv, ' ') $(MonoBuildTool) $(_MonoVerboseArg) all install" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)"/>
-    <Exec Condition="'$(TargetsBrowser)' == 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Command="bash -c 'source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; $(MonoBuildTool) $(_MonoVerboseArg) all install'" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)" />
+    <!-- configure -->
+    <Message Text="Running '$(_MonoCMakeConfigureCommand)' in '$(MonoObjDir)'" Importance="High"/>
+    <Exec Command="$(_MonoCMakeConfigureCommand)" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)"/>
+    <!-- build -->
+    <Message Condition="'$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Text="Running '$(_MonoCMakeBuildCommand)' in '$(MonoObjDir)'" Importance="High"/>
+    <Exec Condition="'$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Command="$(_MonoCMakeBuildCommand)" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)"/>
   </Target>
 
   <!-- Build AOT cross compiler (if available) -->
-  <Target Name="BuildMonoCrossUnix" Condition="'$(BuildMonoAOTCrossCompiler)' == 'true'" DependsOnTargets="BuildMonoRuntimeUnix">
-    <Exec Command="which ninja" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true">
-      <Output TaskParameter="ExitCode" PropertyName="MonoNinjaFound"/>
-    </Exec>
-    <PropertyGroup>
-      <MonoBuildTool Condition="'$(MonoNinjaFound)' == '0'">ninja</MonoBuildTool>
-      <MonoBuildTool Condition="'$(MonoNinjaFound)' != '0'">make -j$([System.Environment]::ProcessorCount)</MonoBuildTool>
-    </PropertyGroup>
+  <Target Name="BuildMonoCross" Condition="'$(BuildMonoAOTCrossCompiler)' == 'true'" DependsOnTargets="BuildMonoRuntime">
 
     <!-- iOS specific options -->
     <PropertyGroup Condition="'$(TargetstvOS)' == 'true' or '$(TargetsiOS)' == 'true'">
       <!-- FIXME: Disable for simulator -->
       <MonoUseCrossTool>true</MonoUseCrossTool>
-      <MonoCMakeSysroot Condition="'$(TargetsiOS)' == 'true' and '$(TargetsiOSSimulator)' != 'true'">$(XcodeDir)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$(iOSVersion).sdk</MonoCMakeSysroot>
-      <MonoCMakeSysroot Condition="'$(TargetsiOS)' == 'true' and '$(TargetsiOSSimulator)' == 'true'">$(XcodeDir)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator$(iOSVersion).sdk</MonoCMakeSysroot>
-      <MonoCMakeSysroot Condition="'$(TargetstvOS)' == 'true' and '$(TargetstvOSSimulator)' != 'true'">$(XcodeDir)/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS$(tvOSVersion).sdk</MonoCMakeSysroot>
-      <MonoCMakeSysroot Condition="'$(TargetstvOS)' == 'true' and '$(TargetstvOSSimulator)' == 'true'">$(XcodeDir)/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator$(tvOSVersion).sdk</MonoCMakeSysroot>
+      <MonoAotCMakeSysroot Condition="'$(TargetsiOS)' == 'true' and '$(TargetsiOSSimulator)' != 'true'">$(XcodeDir)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$(iOSVersion).sdk</MonoAotCMakeSysroot>
+      <MonoAotCMakeSysroot Condition="'$(TargetsiOS)' == 'true' and '$(TargetsiOSSimulator)' == 'true'">$(XcodeDir)/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator$(iOSVersion).sdk</MonoAotCMakeSysroot>
+      <MonoAotCMakeSysroot Condition="'$(TargetstvOS)' == 'true' and '$(TargetstvOSSimulator)' != 'true'">$(XcodeDir)/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS$(tvOSVersion).sdk</MonoAotCMakeSysroot>
+      <MonoAotCMakeSysroot Condition="'$(TargetstvOS)' == 'true' and '$(TargetstvOSSimulator)' == 'true'">$(XcodeDir)/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator$(tvOSVersion).sdk</MonoAotCMakeSysroot>
       <MonoAotOffsetsFile>$(MonoObjDir)cross/offsets-$(Platform)-darwin.h</MonoAotOffsetsFile>
       <MonoAotAbi Condition="'$(Platform)' == 'arm64'">aarch64-apple-darwin10</MonoAotAbi>
       <MonoAotAbi Condition="'$(Platform)' == 'arm'">arm-apple-darwin10</MonoAotAbi>
       <MonoAotAbi Condition="'$(Platform)' == 'x86'">i386-apple-darwin10</MonoAotAbi>
       <MonoAotAbi Condition="'$(Platform)' == 'x64'">x86_64-apple-darwin10</MonoAotAbi>
     </PropertyGroup>
+    <ItemGroup Condition="'$(TargetstvOS)' == 'true' or '$(TargetsiOS)' == 'true'">
+      <MonoAOTCMakeArgs Include="-DCMAKE_OSX_DEPLOYMENT_TARGET=$(macOSVersionMin)" />
+    </ItemGroup>
 
     <PropertyGroup Condition="'$(TargetOS)' == 'Linux' and '$(Platform)' == 'arm64'">
       <MonoUseCrossTool>true</MonoUseCrossTool>
 
     <PropertyGroup>
       <MonoLibClang Condition="'$(MonoLibClang)' == ''">$(XcodeDir)/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib</MonoLibClang>
-      <MonoCMakeSysroot Condition="'$(MonoCMakeSysroot)' == ''">$(MonoCrossDir)</MonoCMakeSysroot>
+      <MonoAotCMakeSysroot Condition="'$(MonoAotCMakeSysroot)' == ''">$(MonoCrossDir)</MonoAotCMakeSysroot>
     </PropertyGroup>
     <ItemGroup Condition="'$(MonoUseCrossTool)' == 'true'">
       <MonoAotCrossOffsetsToolParams Include="--abi=$(MonoAotAbi)" />
       <MonoAotCrossOffsetsToolParams Include="--outfile=&quot;$(MonoAotOffsetsFile)&quot;" />
       <MonoAotCrossOffsetsToolParams Include="--libclang=&quot;$(MonoLibClang)&quot;" />
       <MonoAotCrossOffsetsToolParams Condition="'$(MonoAotOffsetsPrefix)' != ''" Include="--prefix=&quot;$(MonoAotOffsetsPrefix)&quot;" />
-      <MonoAotCrossOffsetsToolParams Condition="'$(MonoCMakeSysroot)' != ''" Include="--sysroot=&quot;$(MonoCMakeSysroot)&quot;" />
+      <MonoAotCrossOffsetsToolParams Condition="'$(MonoAotCMakeSysroot)' != ''" Include="--sysroot=&quot;$(MonoAotCMakeSysroot)&quot;" />
       <MonoAotCrossOffsetsToolParams Condition="'$(TargetsBrowser)' == 'true'" Include="--emscripten-sdk=&quot;$(EMSDK_PATH)/upstream/emscripten&quot;" />
     </ItemGroup>
 
-    <PropertyGroup Condition="'$(MonoUseCrossTool)' == 'true'">
-      <MonoAotCrossOffsetsCommand>python3 $(MonoProjectRoot)mono/tools/offsets-tool/offsets-tool.py @(MonoAotCrossOffsetsToolParams, ' ')</MonoAotCrossOffsetsCommand>
-    </PropertyGroup>
-
     <PropertyGroup>
       <_MonoAOTCXXFLAGSOption>-DCMAKE_CXX_FLAGS="@(_MonoAOTCXXFLAGS, ' ')"</_MonoAOTCXXFLAGSOption>
     </PropertyGroup>
-
     <ItemGroup>
       <MonoAOTCMakeArgs Include="-DAOT_TARGET_TRIPLE=$(MonoAotAbi)"/>
-      <MonoAOTCMakeArgs Condition="'$(MonoBuildTool)' == 'ninja'" Include="-G Ninja"/>
+      <MonoAOTCMakeArgs Condition="'$(_MonoUseNinja)' == 'true'" Include="-G Ninja"/>
       <MonoAOTCMakeArgs Include="-DCMAKE_INSTALL_PREFIX=$(MonoObjDir)cross/out"/>
       <MonoAOTCMakeArgs Include="-DCMAKE_BUILD_TYPE=$(Configuration)"/>
       <!-- FIXME: Disable more -->
       <MonoAOTCMakeArgs Include="$(_MonoAOTCXXFLAGSOption)" />
     </ItemGroup>
 
+    <PropertyGroup>
+      <_MonoAotCrossOffsetsCommand Condition="'$(MonoUseCrossTool)' == 'true'">python3 $(MonoProjectRoot)mono/tools/offsets-tool/offsets-tool.py @(MonoAotCrossOffsetsToolParams, ' ')</_MonoAotCrossOffsetsCommand>
+      <_MonoAotCMakeConfigureCommand>cmake @(MonoAOTCMakeArgs, ' ') $(MonoProjectRoot)</_MonoAotCMakeConfigureCommand>
+      <_MonoAotCMakeBuildCommand>cmake --build . --target install --config $(Configuration)</_MonoAotCMakeBuildCommand>
+      <_MonoAotCMakeBuildCommand Condition="'$(MonoVerboseBuild)' == 'true'">$(_MonoAotCMakeBuildCommand) --verbose</_MonoAotCMakeBuildCommand>
+      <_MonoAotCMakeBuildCommand Condition="'$(_MonoUseNinja)' != 'true'">$(_MonoAotCMakeBuildCommand) --parallel $([System.Environment]::ProcessorCount)</_MonoAotCMakeBuildCommand>
+    </PropertyGroup>
+
     <MakeDir Directories="$(MonoObjDir)/cross" />
     <!-- offsets tool -->
-    <Message Condition="'$(MonoUseCrossTool)' == 'true' and !Exists('$(MonoAotOffsetsFile)')" Text="Running '$(MonoAotCrossOffsetsCommand)'" Importance="High" />
-    <Exec Condition="'$(MonoUseCrossTool)' == 'true' and !Exists('$(MonoAotOffsetsFile)')" Command="$(MonoAotCrossOffsetsCommand)" IgnoreStandardErrorWarningFormat="true" />
-    <!-- cmake -->
-    <Message Text="Running 'cmake @(MonoAOTCMakeArgs, ' ') $(MonoProjectRoot)" Importance="High" />
-    <Exec Command="cmake @(MonoAOTCMakeArgs, ' ') $(MonoProjectRoot)" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)/cross"/>
-    <!-- ninja/make -->
-    <Exec Command="$(MonoBuildTool) all install" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)/cross"/>
+    <Message Condition="'$(MonoUseCrossTool)' == 'true' and !Exists('$(MonoAotOffsetsFile)')" Text="Running '$(_MonoAotCrossOffsetsCommand)'" Importance="High" />
+    <Exec Condition="'$(MonoUseCrossTool)' == 'true' and !Exists('$(MonoAotOffsetsFile)')" Command="$(_MonoAotCrossOffsetsCommand)" IgnoreStandardErrorWarningFormat="true" />
+    <!-- configure -->
+    <Message Text="Running '$(_MonoAotCMakeConfigureCommand)' in '$(MonoObjDir)/cross'" Importance="High" />
+    <Exec Command="$(_MonoAotCMakeConfigureCommand)" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)/cross"/>
+    <!-- build -->
+    <Message Text="Running '$(_MonoAotCMakeBuildCommand)' in '$(MonoObjDir)/cross'" Importance="High" />
+    <Exec Command="$(_MonoAotCMakeBuildCommand)" IgnoreStandardErrorWarningFormat="true" WorkingDirectory="$(MonoObjDir)/cross"/>
+  </Target>
+
+  <Target Name="InitializeGenerateRuntimeVersionFile"
+          BeforeTargets="Restore">
+    <MSBuild Projects="$(RepoRoot)eng\empty.csproj"
+             Targets="Restore"/>
+  </Target>
+
+  <Target Name="GenerateMonoVersionFile" DependsOnTargets="InitializeGenerateRuntimeVersionFile">
+    <MSBuild Projects="$(RepoRoot)eng\empty.csproj"
+             Targets="GenerateRuntimeVersionFile"
+             Properties="NativeVersionFile=$(MonoObjDir)_version.h;RuntimeVersionFile=$(MonoObjDir)runtime_version.h" />
+    <MSBuild Condition="'$(BuildMonoAOTCrossCompiler)' == 'true'"
+             Projects="$(RepoRoot)eng\empty.csproj"
+             Targets="GenerateRuntimeVersionFile"
+             Properties="NativeVersionFile=$(MonoObjDir)cross\_version.h;RuntimeVersionFile=$(MonoObjDir)cross\runtime_version.h" />
   </Target>
 
   <!-- General targets -->
-  <Target Name="BuildMono" AfterTargets="Build" DependsOnTargets="CheckEnv;BuildMonoRuntimeUnix;BuildMonoCrossUnix;BuildMonoRuntimeWindows">
+  <Target Name="BuildMono" AfterTargets="Build" DependsOnTargets="CheckEnv;GenerateMonoVersionFile;BuildMonoRuntime;BuildMonoCross">
     <PropertyGroup Condition="'$(BuildMonoAOTCrossCompilerOnly)' != 'true'">
-      <_MonoRuntimeFilePath Condition="'$(TargetsWindows)' == 'true' and '$(Platform)' == 'x64'">$(MonoObjDir)x64\Bin\$(Configuration)\mono-2.0-sgen.dll</_MonoRuntimeFilePath>
-      <_MonoRuntimeFilePath Condition="'$(TargetsWindows)' == 'true' and '$(Platform)' == 'x86'">$(MonoObjDir)Win32\Bin\$(Configuration)\mono-2.0-sgen.dll</_MonoRuntimeFilePath>
+      <_MonoRuntimeFilePath Condition="'$(TargetsWindows)' == 'true'">$(MonoObjDir)out\bin\monosgen-2.0.dll</_MonoRuntimeFilePath>
       <_MonoRuntimeFilePath Condition="'$(TargetsOSX)' == 'true'">$(MonoObjDir)out\lib\libmonosgen-2.0.dylib</_MonoRuntimeFilePath>
       <_MonoRuntimeFilePath Condition="'$(TargetsiOS)' == 'true'">$(MonoObjDir)out\lib\libmonosgen-2.0.dylib</_MonoRuntimeFilePath>
       <_MonoRuntimeFilePath Condition="'$(TargetstvOS)' == 'true'">$(MonoObjDir)out\lib\libmonosgen-2.0.dylib</_MonoRuntimeFilePath>
       <_MonoIncludeInterpStaticFiles Condition="'$(TargetsBrowser)' == 'true'">true</_MonoIncludeInterpStaticFiles>
     </PropertyGroup>
     <PropertyGroup Condition="'$(BuildMonoAOTCrossCompiler)' == 'true'">
-      <_MonoAotCrossFilePath >$(MonoObjDir)cross\out\bin\mono-sgen</_MonoAotCrossFilePath>
+      <_MonoAotCrossFilePath>$(MonoObjDir)cross\out\bin\mono-sgen</_MonoAotCrossFilePath>
     </PropertyGroup>
 
     <!-- Copy Mono runtime files to artifacts directory -->
index 6a1e1c9..817a804 100644 (file)
@@ -1,6 +1,5 @@
 project(mono)
 
-#set(subdirs eglib arch utils cil sgen metadata mini dis profiler)
 set(subdirs mini profiler)
 
 if(ENABLE_PERFTRACING)
index 72d994d..14b653d 100644 (file)
@@ -13,7 +13,7 @@
 #include <glib.h>
 #include "attach.h"
 
-#ifdef HOST_WIN32
+#if defined(HOST_WIN32) && !defined(DISABLE_ATTACH)
 #define DISABLE_ATTACH
 #endif
 #ifndef DISABLE_ATTACH
index 312d813..10c788a 100644 (file)
@@ -26,6 +26,9 @@ include(../eglib/CMakeLists.txt)
 include(../utils/CMakeLists.txt)
 include(../metadata/CMakeLists.txt)
 include(../sgen/CMakeLists.txt)
+if(TARGET_WIN32)  # TODO: hook up HAVE_SYS_ZLIB instead
+  include(../zlib/CMakeLists.txt)
+endif()
 
 if(ENABLE_PERFTRACING)
 
@@ -44,32 +47,35 @@ endif(ENABLE_PERFTRACING)
 
 # ICU
 if(HAVE_SYS_ICU)
-if(STATIC_ICU)
-set(pal_icushim_sources_base
-    pal_icushim_static.c)
-else()
-set(pal_icushim_sources_base
-    pal_icushim.c)
-endif()
+  if(STATIC_ICU)
+    set(pal_icushim_sources_base
+        pal_icushim_static.c)
+  else()
+    set(pal_icushim_sources_base
+        pal_icushim.c)
+  endif()
 
-set(icu_shim_sources_base
-    pal_calendarData.c
-    pal_casing.c
-    pal_collation.c
-    pal_idna.c
-    pal_locale.c
-    pal_localeNumberData.c
-    pal_localeStringData.c
-    pal_normalization.c
-    pal_timeZoneInfo.c
-    entrypoints.c
-    ${pal_icushim_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_CURRENT_SOURCE_DIR}/../../../libraries/Native/Unix/System.Globalization.Native/ -I${CMAKE_CURRENT_SOURCE_DIR}/../../../libraries/Native/Unix/Common/ ${ICU_FLAGS}")
-if(ICU_LIBDIR)
-  set(ICU_LDFLAGS "-L${ICU_LIBDIR}")
-endif()
+  set(icu_shim_sources_base
+      pal_calendarData.c
+      pal_casing.c
+      pal_collation.c
+      pal_idna.c
+      pal_locale.c
+      pal_localeNumberData.c
+      pal_localeStringData.c
+      pal_normalization.c
+      pal_timeZoneInfo.c
+      entrypoints.c
+      ${pal_icushim_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_CURRENT_SOURCE_DIR}/../../../libraries/Native/Unix/System.Globalization.Native/ -I${CMAKE_CURRENT_SOURCE_DIR}/../../../libraries/Native/Unix/Common/ ${ICU_FLAGS}")
+  if(TARGET_WIN32)
+      set_source_files_properties(${icu_shim_sources} PROPERTIES LANGUAGE CXX)
+  endif()
+  if(ICU_LIBDIR)
+    set(ICU_LDFLAGS "-L${ICU_LIBDIR}")
+  endif()
 endif()
 
 #
@@ -88,7 +94,6 @@ set(mini_common_sources
     calls.c
     decompose.c
     mini.h
-    version.h
     optflags-def.h
     jit-icalls.h
     jit-icalls.c
@@ -229,9 +234,11 @@ set(darwin_sources
 
 set(windows_sources
     mini-windows.c
+    mini-windows-tls-callback.c
     mini-windows.h
     mini-windows-dllmain.c
-    mini-windows-dlldac.c)
+    # mini-windows-dlldac.c
+    )
 
 set(posix_sources
     mini-posix.c)
@@ -240,6 +247,8 @@ if(HOST_DARWIN)
 set(os_sources "${darwin_sources};${posix_sources}")
 elseif(HOST_LINUX)
 set(os_sources "${posix_sources}")
+elseif(HOST_WIN32)
+set(os_sources "${windows_sources}")
 endif()
 
 set(interp_sources
@@ -303,9 +312,13 @@ elseif(HOST_ANDROID)
 set(OS_LIBS m dl log)
 elseif(HOST_LINUX)
 set(OS_LIBS pthread m dl)
+elseif(HOST_WIN32)
+set(OS_LIBS bcrypt.lib Mswsock.lib ws2_32.lib psapi.lib version.lib advapi32.lib winmm.lib kernel32.lib)
+set(mini_sources "${mini_sources};${PROJECT_BINARY_DIR}/../../NativeVersion.rc") # this is generated by GenerateMonoVersionFile in mono.proj
 endif()
 
-add_library(monosgen-objects OBJECT "${eglib_sources};${metadata_sources};${utils_sources};${sgen_sources};${icu_shim_sources};${eventpipe_sources};${mini_sources}")
+
+add_library(monosgen-objects OBJECT "${eglib_sources};${metadata_sources};${utils_sources};${sgen_sources};${icu_shim_sources};${eventpipe_sources};${mini_sources};${zlib_sources}")
 add_library(monosgen-static STATIC $<TARGET_OBJECTS:monosgen-objects>)
 set_target_properties(monosgen-static PROPERTIES OUTPUT_NAME monosgen-2.0)
 if(NOT DISABLE_LIBS)
@@ -318,40 +331,27 @@ if(NOT DISABLE_LIBS)
        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)
-  target_link_libraries(monosgen ${OS_LIBS} ${ICONV_LIB} ${LLVM_LIBS} ${ICU_LIBS})
+  add_library(monosgen-shared SHARED $<TARGET_OBJECTS:monosgen-objects> )
+  set_target_properties(monosgen-shared PROPERTIES OUTPUT_NAME monosgen-2.0)
+  if(TARGET_WIN32)
+    # on Windows the import library for the shared monosgen-2.0 library will have the same name as the static library (monosgen-2.0.lib),
+    # to avoid a conflict we rename the import library with the .import.lib suffix
+    set_target_properties(monosgen-shared PROPERTIES IMPORT_SUFFIX ".import.lib")
+  endif()
+  target_link_libraries(monosgen-shared ${OS_LIBS} ${ICONV_LIB} ${LLVM_LIBS} ${ICU_LIBS})
   if(ICU_LDFLAGS)
-    set_property(TARGET monosgen APPEND_STRING PROPERTY LINK_FLAGS ${ICU_LDFLAGS})
+    set_property(TARGET monosgen-shared APPEND_STRING PROPERTY LINK_FLAGS " ${ICU_LDFLAGS}")
   endif()
-  if(TARGET_DARWIN OR TARGET_IOS OR TARGET_TVOS)
-    set_property(TARGET monosgen APPEND_STRING PROPERTY LINK_FLAGS "-Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0")
+  if(TARGET_DARWIN)
+    set_property(TARGET monosgen-shared APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-compatibility_version -Wl,2.0 -Wl,-current_version -Wl,2.0")
   endif()
-  install(TARGETS monosgen LIBRARY)
+  install(TARGETS monosgen-shared LIBRARY)
 endif()
 
 find_package(Python3 COMPONENTS Interpreter)
 
-# FIXME: Always rebuilds, creates non-deterministic builds
-# FIXME: Use the previous format
-#string(TIMESTAMP BUILD_DATE)
-
-#add_custom_command(
-#  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/buildver-sgen.h
-#  COMMAND echo "const char *build_date = \"${BUILD_DATE}\";" > ${CMAKE_CURRENT_BINARY_DIR}/buildver-sgen.h
-#  VERBATIM
-#)
-add_custom_command(
-  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/buildver-sgen.h
-  COMMAND echo "const char *build_date = \"\";" > ${CMAKE_CURRENT_BINARY_DIR}/buildver-sgen.h
-  VERBATIM
-)
-
-add_custom_command(
-  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h
-  COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/gen-version-h.sh ${CMAKE_CURRENT_SOURCE_DIR}/../..
-  VERBATIM
-)
+# don't set build_date, it creates non-deterministic builds
+file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/buildver-sgen.h CONTENT [=[const char *build_date = "";]=])
 
 add_custom_command(
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cpu-amd64.h
@@ -384,11 +384,10 @@ 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_LIB} ${LLVM_LIBS} ${ICU_LIBS})
   if(ICU_LDFLAGS)
-    set_target_properties(mono-sgen PROPERTIES LINK_FLAGS ${ICU_LDFLAGS})
+    set_property(TARGET mono-sgen APPEND_STRING PROPERTY LINK_FLAGS " ${ICU_LDFLAGS}")
   endif()
   install(TARGETS mono-sgen RUNTIME)
 endif()
index ad43071..eb13d2a 100644 (file)
@@ -65,7 +65,6 @@
 
 #include "mini.h"
 #include "seq-points.h"
-#include "version.h"
 #include "debugger-agent.h"
 #include "aot-compiler.h"
 #include "aot-runtime.h"
index 0d01be7..71ec1ed 100644 (file)
@@ -68,7 +68,6 @@
 #include <string.h>
 #include <ctype.h>
 #include <locale.h>
-#include "version.h"
 #include "debugger-agent.h"
 #if TARGET_OSX
 #   include <sys/resource.h>
diff --git a/src/mono/mono/mini/gen-version-h.sh b/src/mono/mono/mini/gen-version-h.sh
deleted file mode 100755 (executable)
index 91e1c13..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-top_srcdir=$1
-if test -d $top_srcdir/.git; then
-       (cd $top_srcdir;
-        LANG=C; export LANG;
-        if test -z "$ghprbPullId"; then
-                branch=`git branch | grep '^\*' | sed 's/(detached from .*/explicit/' | cut -d ' ' -f 2`;
-        else
-                branch="pull-request-$ghprbPullId";
-        fi;
-        version=`git log --no-color --first-parent -n1 --pretty=format:%h`;
-        echo "#define FULL_VERSION \"$branch/$version\"";
-       );
-else
-       echo "#define FULL_VERSION \"tarball\"";
-fi > version.h
-
index 834a60a..ce0b7fa 100644 (file)
@@ -56,7 +56,6 @@
 #include <string.h>
 #include <ctype.h>
 #include "trace.h"
-#include "version.h"
 
 #include "jit-icalls.h"
 
index cfafeb3..c0cd9af 100644 (file)
@@ -77,7 +77,6 @@
 #include <string.h>
 #include <ctype.h>
 #include "trace.h"
-#include "version.h"
 #include "debugger-agent.h"
 #include "mini-runtime.h"
 #include "jit-icalls.h"
index f201d4f..0aaa0b5 100644 (file)
@@ -85,7 +85,9 @@
 #include <string.h>
 #include <ctype.h>
 #include "trace.h"
+#ifndef ENABLE_NETCORE
 #include "version.h"
+#endif
 #include "aot-compiler.h"
 #include "aot-runtime.h"
 #include "llvmonly-runtime.h"
index 12bc4c7..24f1a8b 100644 (file)
@@ -52,7 +52,6 @@
 #include <string.h>
 #include <ctype.h>
 #include "trace.h"
-#include "version.h"
 
 #include "jit-icalls.h"
 
index 3f66854..efd6e0e 100644 (file)
@@ -69,7 +69,6 @@
 #include <string.h>
 #include <ctype.h>
 #include "trace.h"
-#include "version.h"
 #include "ir-emit.h"
 
 #include "jit-icalls.h"
index 2c4c267..058667c 100644 (file)
 #include <mono/utils/mono-logger-internals.h>
 #include <mono/utils/mono-os-mutex.h>
 #include <mono/utils/mono-threads.h>
+#include <mono/utils/mono-proclib.h>
 #include <string.h>
 #include <errno.h>
 #include <stdlib.h>
 #ifndef HOST_WIN32
 #include <sys/socket.h>
+#else
+#define sleep(t)                 Sleep((t) * 1000)
 #endif
 #include <glib.h>
 
@@ -364,7 +367,7 @@ mono_profiler_init_aot (const char *desc)
                if (!aot_profiler.outfile_name)
                        aot_profiler.outfile_name = g_strdup ("output.aotprofile");
                else if (*aot_profiler.outfile_name == '+')
-                       aot_profiler.outfile_name = g_strdup_printf ("%s.%d", aot_profiler.outfile_name + 1, getpid ());
+                       aot_profiler.outfile_name = g_strdup_printf ("%s.%d", aot_profiler.outfile_name + 1, mono_process_current_pid ());
 
                if (*aot_profiler.outfile_name == '|') {
 #ifdef HAVE_POPEN
index 76b5ad4..b88ae82 100644 (file)
@@ -1,15 +1,30 @@
 
 set(utils_win32_sources
+    mono-os-semaphore-win32.c
+    mono-os-wait-win32.c
+    mono-windows-thread-name.c
     os-event-win32.c
-    mono-os-wait-win32.c)
+    w32subset.h)
+
+if(TARGET_WIN32 AND TARGET_AMD64)
+    enable_language(ASM_MASM)
+    set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded         "")
+    set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL      "")
+    set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug    "")
+    set(CMAKE_ASM_MASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "")
+
+    list(APPEND utils_win32_sources win64.asm)
+endif()
 
 set(utils_unix_sources
+    dlmalloc.h
+    dlmalloc.c
     os-event-unix.c)
 
 if(HOST_WIN32)
-set(utils_platform_sources ${utils_win32_sources})
+    set(utils_platform_sources ${utils_win32_sources})
 else()
-set(utils_platform_sources ${utils_unix_sources})
+    set(utils_platform_sources ${utils_unix_sources})
 endif()
 
 set(utils_common_sources
@@ -18,8 +33,6 @@ set(utils_common_sources
     mono-logger.c
     mono-logger-internals.h
     mono-codeman.c
-    dlmalloc.h
-    dlmalloc.c
     mono-counters.c
     mono-compiler.h
     mono-complex.h
@@ -70,6 +83,7 @@ set(utils_common_sources
     mono-string.h
     mono-time.c
     mono-time.h
+    strenc-internals.h
     strenc.h
     strenc.c
     mono-uri.c
@@ -96,6 +110,7 @@ set(utils_common_sources
     mono-counters.h
     mono-digest.h
     mono-error.h
+    mono-forward-internal.h
     mono-machine.h
     mono-math.h
     mono-membar.h
@@ -111,14 +126,14 @@ set(utils_common_sources
     mono-stack-unwinding.h
     hazard-pointer.c
     hazard-pointer.h
+    lifo-semaphore.c
+    lifo-semaphore.h
     lock-free-queue.c
     lock-free-queue.h
     lock-free-alloc.c
     lock-free-alloc.h
     lock-free-array-queue.c
     lock-free-array-queue.h
-    lifo-semaphore.c
-    lifo-semaphore.h
     mono-linked-list-set.c
     mono-linked-list-set.h
     mono-threads.c
@@ -145,6 +160,7 @@ set(utils_common_sources
     mono-utility-thread.c
     mono-utility-thread.h
     mono-tls.h
+    mono-tls-inline.h
     mono-tls.c
     mono-utils-debug.c
     mono-utils-debug.h
@@ -224,12 +240,12 @@ endif()
 addprefix(utils_sources ../utils/ "${utils_platform_sources};${utils_arch_sources};${utils_common_sources}")
 
 set(utils_public_headers_base
-       mono-logger.h
-       mono-error.h
-       mono-forward.h
-       mono-publib.h
-       mono-jemalloc.h
-       mono-dl-fallback.h
-       mono-private-unstable.h
-       mono-counters.h)
+    mono-logger.h
+    mono-error.h
+    mono-forward.h
+    mono-publib.h
+    mono-jemalloc.h
+    mono-dl-fallback.h
+    mono-private-unstable.h
+    mono-counters.h)
 addprefix(utils_public_headers ../utils "${utils_public_headers_base}")
index 38532ee..8dd5ca5 100644 (file)
@@ -129,7 +129,7 @@ backtrace_mutex_trylock (void)
 static void
 backtrace_mutex_unlock (void)
 {
-       return mono_os_mutex_unlock (&backtrace_mutex);
+       mono_os_mutex_unlock (&backtrace_mutex);
 }
 
 static CheckState*
index 67b5269..6f9f380 100644 (file)
@@ -360,7 +360,7 @@ paged_bytes (void)
 // cause a failure when registering counters since the same function address will be used by all three functions. Preventing this method from being inlined
 // will make sure the registered callback functions remains unique.
 #ifdef _MSC_VER
-__declspec(noinline)
+#pragma optimize("", off)
 #endif
 static double
 cpu_load (int kind)
@@ -413,6 +413,9 @@ cpu_load_15min (void)
 {
        return cpu_load (2);
 }
+#ifdef _MSC_VER
+#pragma optimize("", on)
+#endif
 
 #define SYSCOUNTER_TIME (MONO_COUNTER_SYSTEM | MONO_COUNTER_LONG | MONO_COUNTER_TIME | MONO_COUNTER_MONOTONIC | MONO_COUNTER_CALLBACK)
 #define SYSCOUNTER_BYTES (MONO_COUNTER_SYSTEM | MONO_COUNTER_LONG | MONO_COUNTER_BYTES | MONO_COUNTER_VARIABLE | MONO_COUNTER_CALLBACK)
diff --git a/src/mono/mono/zlib/CMakeLists.txt b/src/mono/mono/zlib/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e3c97d8
--- /dev/null
@@ -0,0 +1,26 @@
+set(zlib_sources_base
+    adler32.c
+    compress.c
+    crc32.c
+    uncompr.c
+    deflate.c
+    gzguts.h
+    trees.c
+    zutil.c
+    inflate.c
+    infback.c
+    inftrees.c
+    inffast.c
+    crc32.h
+    deflate.h
+    inffast.h
+    inffixed.h
+    inflate.h
+    inftrees.h
+    trees.h
+    zconf.h
+    zlib.h
+    zutil.h
+)
+
+addprefix(zlib_sources ../zlib  "${zlib_sources_base}")