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)
9 set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -std=c++11" CACHE STRING "Flags used by the compiler during all build types.")
10 set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -std=c11" CACHE STRING "Flags used by the compiler during all build types.")
13 # Set the project name
16 # Include cmake functions
17 include(functions.cmake)
19 # Verify that LTCG/LTO is available
20 include(configure.cmake)
23 message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}")
24 message(STATUS "VS_PLATFORM_NAME is ${CMAKE_VS_PLATFORM_NAME}")
27 # Set commonly used directory names
28 set(CLR_DIR ${CMAKE_CURRENT_SOURCE_DIR})
29 set(VM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/vm)
30 set(GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/inc)
31 set(GENERATED_EVENTING_DIR ${CMAKE_CURRENT_BINARY_DIR}/Eventing)
32 set(VERSION_FILE_PATH "${CMAKE_BINARY_DIR}/version.c")
33 set(PAL_REDEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/dlls/mscordac/palredefines.S)
35 set(CORECLR_SET_RPATH ON)
37 # Enable @rpath support for shared libraries.
39 endif(CORECLR_SET_RPATH)
41 OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)
42 OPTION(CLR_CMAKE_WARNINGS_ARE_ERRORS "Warnings are errors" ON)
44 # Ensure other tools are present
46 if(CLR_CMAKE_HOST_ARCH STREQUAL arm)
48 # Confirm that Windows SDK is present
49 if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
50 message(FATAL_ERROR "Windows SDK is required for the Arm32 build.")
52 message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
55 # Explicitly specify the assembler to be used for Arm32 compile
56 file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER)
58 set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
59 message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
61 # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
62 # use ml[64].exe as the assembler.
64 elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm64)
66 # Confirm that Windows SDK is present
67 if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
68 message(FATAL_ERROR "Windows SDK is required for the ARM64 build.")
70 message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
73 # Explicitly specify the assembler to be used for Arm64 compile
74 file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)
76 set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
77 message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
79 # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
80 # use ml[64].exe as the assembler.
83 enable_language(ASM_MASM)
86 # Ensure that MC is present
88 if (MC STREQUAL "MC-NOTFOUND")
89 message(FATAL_ERROR "MC not found")
95 # Ensure that awk is present
97 if (AWK STREQUAL "AWK-NOTFOUND")
98 message(FATAL_ERROR "AWK not found")
101 # Try to locate the paxctl tool. Failure to find it is not fatal,
102 # but the generated executables won't work on a system where PAX is set
103 # to prevent applications to create executable memory mappings.
104 find_program(PAXCTL paxctl)
106 if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
108 # Ensure that dsymutil and strip are present
109 find_program(DSYMUTIL dsymutil)
110 if (DSYMUTIL STREQUAL "DSYMUTIL-NOTFOUND")
111 message(FATAL_ERROR "dsymutil not found")
114 find_program(STRIP strip)
115 if (STRIP STREQUAL "STRIP-NOTFOUND")
116 message(FATAL_ERROR "strip not found")
119 else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
121 # Ensure that objcopy is present
122 if (CLR_UNIX_CROSS_BUILD AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
123 if (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
124 find_program(OBJCOPY ${TOOLCHAIN}-objcopy)
125 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
126 find_program(OBJCOPY objcopy)
131 find_program(OBJCOPY objcopy)
134 if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND")
135 message(FATAL_ERROR "objcopy not found")
138 endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
141 #----------------------------------------------------
142 # Configure compiler settings for environment
143 #----------------------------------------------------
144 include(configurecompiler.cmake)
146 #----------------------------------------------------
147 # Cross target Component build specific configuration
148 #----------------------------------------------------
149 if(CLR_CROSS_COMPONENTS_BUILD)
150 include(crosscomponents.cmake)
151 endif(CLR_CROSS_COMPONENTS_BUILD)
156 include(pgosupport.cmake)
158 #-----------------------------------------
160 # - project which require platform header not clr's
161 # - do not depend on clr's compile definitions
162 #-----------------------------------------
163 if(CLR_CMAKE_PLATFORM_UNIX AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
164 add_subdirectory(src/corefx)
167 if(CLR_CMAKE_PLATFORM_UNIX)
168 add_subdirectory(src/ToolBox/SOS/lldbplugin)
169 add_subdirectory(src/pal)
170 add_subdirectory(src/coreclr/hosts)
171 add_subdirectory(src/ildasm/unixcoreclrloader)
172 endif(CLR_CMAKE_PLATFORM_UNIX)
174 # Add this subdir. We install the headers for the jit.
175 add_subdirectory(src/pal/prebuilt/inc)
177 add_subdirectory(src/debug/debug-pal)
180 add_subdirectory(src/gc/sample)
183 # Above projects do not build with these compile options
184 # All of the compiler options are specified in file compileoptions.cmake
185 # Do not add any new options here. They should be added in compileoptions.cmake
187 add_compile_options(/FIWarningControl.h) # force include of WarningControl.h
188 add_compile_options(/Zl) # omit default library name in .OBJ
191 #------------------------------
193 #------------------------------
194 if(CLR_CMAKE_BUILD_TESTS)
195 add_subdirectory(tests)
196 endif(CLR_CMAKE_BUILD_TESTS)
198 #--------------------------------
199 # Definition directives
200 # - all clr specific compile definitions should be included in this file
201 # - all clr specific feature variable should also be added in this file
202 #----------------------------------
203 include(clrdefinitions.cmake)
205 #-------------------------------------
206 # Include directory directives
207 #-------------------------------------
208 # Include the basic prebuilt headers - required for getting fileversion resource details.
209 include_directories("src/pal/prebuilt/inc")
210 include_directories("bin/obj")
212 if(FEATURE_STANDALONE_GC)
213 add_definitions(-DFEATURE_STANDALONE_GC)
214 add_subdirectory(src/gc)
215 endif(FEATURE_STANDALONE_GC)
217 if (CLR_CMAKE_PLATFORM_UNIX)
218 include_directories("src/pal/inc")
219 include_directories("src/pal/inc/rt")
220 include_directories("src/pal/src/safecrt")
221 endif (CLR_CMAKE_PLATFORM_UNIX)
223 #------------------------------
224 # Add Product Directory
225 #------------------------------
226 add_subdirectory(src)
228 include(definitionsconsistencycheck.cmake)