1 # Verify minimum required version
2 cmake_minimum_required(VERSION 2.8.12)
4 if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
5 cmake_policy(SET CMP0042 NEW)
11 # Include cmake functions
12 include(functions.cmake)
14 # Include global configure settings
15 include(configure.cmake)
18 message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}")
19 message(STATUS "VS_PLATFORM_NAME is ${CMAKE_VS_PLATFORM_NAME}")
22 # Set commonly used directory names
23 set(CLR_DIR ${CMAKE_CURRENT_SOURCE_DIR})
24 set(VM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/vm)
25 set(GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/inc)
26 set(GENERATED_EVENTING_DIR ${CMAKE_CURRENT_BINARY_DIR}/Eventing)
27 set(VERSION_FILE_PATH "${CMAKE_BINARY_DIR}/version.c")
28 set(PAL_REDEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/dlls/mscordac/palredefines.S)
30 set(CORECLR_SET_RPATH ON)
32 # Enable @rpath support for shared libraries.
34 endif(CORECLR_SET_RPATH)
36 OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)
37 OPTION(CLR_CMAKE_WARNINGS_ARE_ERRORS "Warnings are errors" ON)
39 # Ensure that python is present
40 find_program(PYTHON NAMES python3 python2 python py)
41 if (PYTHON STREQUAL "PYTHON-NOTFOUND")
42 message(FATAL_ERROR "PYTHON not found: Please install Python 2.7.9 or later from https://www.python.org/downloads/")
45 # Ensure other tools are present
47 if(CLR_CMAKE_HOST_ARCH STREQUAL arm)
49 # Confirm that Windows SDK is present
50 if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
51 message(FATAL_ERROR "Windows SDK is required for the Arm32 build.")
53 message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
56 # Explicitly specify the assembler to be used for Arm32 compile
57 file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER)
59 set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
60 message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
62 # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
63 # use ml[64].exe as the assembler.
65 elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm64)
67 # Confirm that Windows SDK is present
68 if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
69 message(FATAL_ERROR "Windows SDK is required for the ARM64 build.")
71 message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
74 # Explicitly specify the assembler to be used for Arm64 compile
75 file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)
77 set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
78 message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
80 # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
81 # use ml[64].exe as the assembler.
84 enable_language(ASM_MASM)
87 # Ensure that MC is present
89 if (MC STREQUAL "MC-NOTFOUND")
90 message(FATAL_ERROR "MC not found")
96 # Ensure that awk is present
98 if (AWK STREQUAL "AWK-NOTFOUND")
99 message(FATAL_ERROR "AWK not found")
102 # Try to locate the paxctl tool. Failure to find it is not fatal,
103 # but the generated executables won't work on a system where PAX is set
104 # to prevent applications to create executable memory mappings.
105 find_program(PAXCTL paxctl)
107 if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
109 # Ensure that dsymutil and strip are present
110 find_program(DSYMUTIL dsymutil)
111 if (DSYMUTIL STREQUAL "DSYMUTIL-NOTFOUND")
112 message(FATAL_ERROR "dsymutil not found")
115 find_program(STRIP strip)
116 if (STRIP STREQUAL "STRIP-NOTFOUND")
117 message(FATAL_ERROR "strip not found")
120 else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
122 # Ensure that objcopy is present
123 if (CLR_UNIX_CROSS_BUILD AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
124 if (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
125 find_program(OBJCOPY ${TOOLCHAIN}-objcopy)
126 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
127 find_program(OBJCOPY objcopy)
132 find_program(OBJCOPY objcopy)
135 if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND")
136 message(FATAL_ERROR "objcopy not found")
139 endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
142 #----------------------------------------------------
143 # Configure compiler settings for environment
144 #----------------------------------------------------
145 include(configurecompiler.cmake)
147 #----------------------------------------------------
148 # Cross target Component build specific configuration
149 #----------------------------------------------------
150 if(CLR_CROSS_COMPONENTS_BUILD)
151 include(crosscomponents.cmake)
152 endif(CLR_CROSS_COMPONENTS_BUILD)
157 include(pgosupport.cmake)
159 #-----------------------------------------
161 # - project which require platform header not clr's
162 # - do not depend on clr's compile definitions
163 #-----------------------------------------
164 if(CLR_CMAKE_PLATFORM_UNIX AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
165 add_subdirectory(src/corefx)
168 if(CLR_CMAKE_PLATFORM_UNIX)
169 add_subdirectory(src/ToolBox/SOS/lldbplugin)
170 add_subdirectory(src/pal)
171 add_subdirectory(src/coreclr/hosts)
172 add_subdirectory(src/ildasm/unixcoreclrloader)
173 endif(CLR_CMAKE_PLATFORM_UNIX)
175 # Add this subdir. We install the headers for the jit.
176 add_subdirectory(src/pal/prebuilt/inc)
178 add_subdirectory(src/debug/debug-pal)
181 add_subdirectory(src/gc/sample)
184 # Above projects do not build with these compile options
185 # All of the compiler options are specified in file compileoptions.cmake
186 # Do not add any new options here. They should be added in compileoptions.cmake
188 add_compile_options(/FIWarningControl.h) # force include of WarningControl.h
189 add_compile_options(/Zl) # omit default library name in .OBJ
192 #------------------------------
194 #------------------------------
195 if(CLR_CMAKE_BUILD_TESTS)
196 add_subdirectory(tests)
197 endif(CLR_CMAKE_BUILD_TESTS)
199 #--------------------------------
200 # Definition directives
201 # - all clr specific compile definitions should be included in this file
202 # - all clr specific feature variable should also be added in this file
203 #----------------------------------
204 include(clrdefinitions.cmake)
206 #-------------------------------------
207 # Include directory directives
208 #-------------------------------------
209 # Include the basic prebuilt headers - required for getting fileversion resource details.
210 include_directories("src/pal/prebuilt/inc")
211 include_directories("bin/obj")
213 if(FEATURE_STANDALONE_GC)
214 add_definitions(-DFEATURE_STANDALONE_GC)
215 add_subdirectory(src/gc)
216 endif(FEATURE_STANDALONE_GC)
218 if (CLR_CMAKE_PLATFORM_UNIX)
219 include_directories("src/pal/inc")
220 include_directories("src/pal/inc/rt")
221 include_directories("src/pal/src/safecrt")
222 endif (CLR_CMAKE_PLATFORM_UNIX)
224 # Microsoft.Dotnet.BuildTools.Coreclr version
225 set(BuildToolsVersion "1.0.4-prerelease")
226 set(BuildToolsDir "${CLR_CMAKE_PACKAGES_DIR}/Microsoft.DotNet.BuildTools.CoreCLR/${BuildToolsVersion}")
228 #------------------------------
229 # Add Product Directory
230 #------------------------------
231 add_subdirectory(src)
233 include(definitionsconsistencycheck.cmake)