1 # Verify minimum required version
2 cmake_minimum_required(VERSION 3.5.1)
4 cmake_policy(SET CMP0042 NEW)
9 # Include cmake functions
10 include(functions.cmake)
12 # Verify that LTCG/LTO is available
13 include(configure.cmake)
16 message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}")
17 message(STATUS "VS_PLATFORM_NAME is ${CMAKE_VS_PLATFORM_NAME}")
20 # Set commonly used directory names
21 set(CLR_DIR ${CMAKE_CURRENT_SOURCE_DIR})
22 set(VM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/vm)
23 set(GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/inc)
24 set(GENERATED_EVENTING_DIR ${CMAKE_CURRENT_BINARY_DIR}/Eventing)
25 set(VERSION_FILE_PATH "${CMAKE_BINARY_DIR}/version.c")
26 set(PAL_REDEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/dlls/mscordac/palredefines.S)
28 set(CORECLR_SET_RPATH ON)
30 # Enable @rpath support for shared libraries.
32 endif(CORECLR_SET_RPATH)
34 OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)
35 OPTION(CLR_CMAKE_WARNINGS_ARE_ERRORS "Warnings are errors" ON)
37 # Ensure other tools are present
39 if(CLR_CMAKE_HOST_ARCH STREQUAL arm)
41 # Confirm that Windows SDK is present
42 if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
43 message(FATAL_ERROR "Windows SDK is required for the Arm32 build.")
45 message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
48 # Explicitly specify the assembler to be used for Arm32 compile
49 file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER)
51 set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
52 message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
54 # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
55 # use ml[64].exe as the assembler.
57 elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm64)
59 # Confirm that Windows SDK is present
60 if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
61 message(FATAL_ERROR "Windows SDK is required for the ARM64 build.")
63 message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
66 # Explicitly specify the assembler to be used for Arm64 compile
67 file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)
69 set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
70 message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
72 # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
73 # use ml[64].exe as the assembler.
76 enable_language(ASM_MASM)
79 # Ensure that MC is present
81 if (MC STREQUAL "MC-NOTFOUND")
82 message(FATAL_ERROR "MC not found")
88 # Ensure that awk is present
90 if (AWK STREQUAL "AWK-NOTFOUND")
91 message(FATAL_ERROR "AWK not found")
94 # Try to locate the paxctl tool. Failure to find it is not fatal,
95 # but the generated executables won't work on a system where PAX is set
96 # to prevent applications to create executable memory mappings.
97 find_program(PAXCTL paxctl)
99 if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
101 # Ensure that dsymutil and strip are present
102 find_program(DSYMUTIL dsymutil)
103 if (DSYMUTIL STREQUAL "DSYMUTIL-NOTFOUND")
104 message(FATAL_ERROR "dsymutil not found")
107 find_program(STRIP strip)
108 if (STRIP STREQUAL "STRIP-NOTFOUND")
109 message(FATAL_ERROR "strip not found")
112 else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
114 # Ensure that objcopy is present
115 if (CLR_UNIX_CROSS_BUILD AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
116 if (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
117 find_program(OBJCOPY ${TOOLCHAIN}-objcopy)
118 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
119 find_program(OBJCOPY objcopy)
124 find_program(OBJCOPY objcopy)
127 if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND")
128 message(FATAL_ERROR "objcopy not found")
131 endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
134 #----------------------------------------------------
135 # Configure compiler settings for environment
136 #----------------------------------------------------
137 include(configurecompiler.cmake)
139 #----------------------------------------------------
140 # Cross target Component build specific configuration
141 #----------------------------------------------------
142 if(CLR_CROSS_COMPONENTS_BUILD)
143 include(crosscomponents.cmake)
144 endif(CLR_CROSS_COMPONENTS_BUILD)
149 include(pgosupport.cmake)
151 #-----------------------------------------
153 # - project which require platform header not clr's
154 # - do not depend on clr's compile definitions
155 #-----------------------------------------
156 if(CLR_CMAKE_PLATFORM_UNIX AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
157 add_subdirectory(src/corefx)
160 if(CLR_CMAKE_PLATFORM_UNIX)
161 add_subdirectory(src/ToolBox/SOS/lldbplugin)
162 add_subdirectory(src/pal)
163 add_subdirectory(src/coreclr/hosts)
164 add_subdirectory(src/ildasm/unixcoreclrloader)
165 endif(CLR_CMAKE_PLATFORM_UNIX)
167 # Add this subdir. We install the headers for the jit.
168 add_subdirectory(src/pal/prebuilt/inc)
170 add_subdirectory(src/debug/debug-pal)
173 add_subdirectory(src/gc/sample)
176 # Above projects do not build with these compile options
177 # All of the compiler options are specified in file compileoptions.cmake
178 # Do not add any new options here. They should be added in compileoptions.cmake
180 add_compile_options(/FIWarningControl.h) # force include of WarningControl.h
181 add_compile_options(/Zl) # omit default library name in .OBJ
184 #------------------------------
186 #------------------------------
187 if(CLR_CMAKE_BUILD_TESTS)
188 add_subdirectory(tests)
189 endif(CLR_CMAKE_BUILD_TESTS)
191 #--------------------------------
192 # Definition directives
193 # - all clr specific compile definitions should be included in this file
194 # - all clr specific feature variable should also be added in this file
195 #----------------------------------
196 include(clrdefinitions.cmake)
198 #-------------------------------------
199 # Include directory directives
200 #-------------------------------------
201 # Include the basic prebuilt headers - required for getting fileversion resource details.
202 include_directories("src/pal/prebuilt/inc")
203 include_directories("bin/obj")
205 if(FEATURE_STANDALONE_GC)
206 add_definitions(-DFEATURE_STANDALONE_GC)
207 add_subdirectory(src/gc)
208 endif(FEATURE_STANDALONE_GC)
210 if (CLR_CMAKE_PLATFORM_UNIX)
211 include_directories("src/pal/inc")
212 include_directories("src/pal/inc/rt")
213 include_directories("src/pal/src/safecrt")
214 endif (CLR_CMAKE_PLATFORM_UNIX)
216 #------------------------------
217 # Add Product Directory
218 #------------------------------
219 add_subdirectory(src)
221 include(definitionsconsistencycheck.cmake)