Merge pull request #24432 from am11/gcc_over_aligned_new
[platform/upstream/coreclr.git] / CMakeLists.txt
1 # Verify minimum required version
2 cmake_minimum_required(VERSION 2.8.12)
3
4 if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
5     cmake_policy(SET CMP0042 NEW)
6 endif()
7
8 # Set the project name
9 project(CoreCLR)
10
11 # Include cmake functions
12 include(functions.cmake)
13
14 # Include global configure settings
15 include(configure.cmake)
16
17 if (WIN32)
18   message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}")
19   message(STATUS "VS_PLATFORM_NAME is ${CMAKE_VS_PLATFORM_NAME}")
20 endif (WIN32)
21
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)
29
30 set(CORECLR_SET_RPATH ON)
31 if(CORECLR_SET_RPATH)
32     # Enable @rpath support for shared libraries.
33     set(MACOSX_RPATH ON)
34 endif(CORECLR_SET_RPATH)
35
36 OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)
37 OPTION(CLR_CMAKE_WARNINGS_ARE_ERRORS "Warnings are errors" ON)
38
39 # Ensure other tools are present
40 if (WIN32)
41     if(CLR_CMAKE_HOST_ARCH STREQUAL arm)
42
43       # Confirm that Windows SDK is present
44       if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
45               message(FATAL_ERROR "Windows SDK is required for the Arm32 build.")
46       else()
47               message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
48       endif()
49
50       # Explicitly specify the assembler to be used for Arm32 compile
51       file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER)
52
53       set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
54       message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
55
56       # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
57       # use ml[64].exe as the assembler.
58       enable_language(ASM)
59     elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm64)
60
61       # Confirm that Windows SDK is present
62       if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
63               message(FATAL_ERROR "Windows SDK is required for the ARM64 build.")
64       else()
65               message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
66       endif()
67
68       # Explicitly specify the assembler to be used for Arm64 compile
69       file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)
70
71       set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
72       message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
73
74       # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
75       # use ml[64].exe as the assembler.
76       enable_language(ASM)
77     else()
78       enable_language(ASM_MASM)
79     endif()
80
81     # Ensure that MC is present
82     find_program(MC mc)
83     if (MC STREQUAL "MC-NOTFOUND")
84         message(FATAL_ERROR "MC not found")
85     endif()
86
87 else (WIN32)
88     enable_language(ASM)
89
90     # Ensure that awk is present
91     find_program(AWK awk)
92     if (AWK STREQUAL "AWK-NOTFOUND")
93         message(FATAL_ERROR "AWK not found")
94     endif()
95
96     # Try to locate the paxctl tool. Failure to find it is not fatal,
97     # but the generated executables won't work on a system where PAX is set
98     # to prevent applications to create executable memory mappings.
99     find_program(PAXCTL paxctl)
100
101     if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
102
103       # Ensure that dsymutil and strip are present
104       find_program(DSYMUTIL dsymutil)
105       if (DSYMUTIL STREQUAL "DSYMUTIL-NOTFOUND")
106           message(FATAL_ERROR "dsymutil not found")
107       endif()
108
109       find_program(STRIP strip)
110       if (STRIP STREQUAL "STRIP-NOTFOUND")
111           message(FATAL_ERROR "strip not found")
112       endif()
113
114     else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
115
116       # Ensure that objcopy is present
117       if (CLR_UNIX_CROSS_BUILD AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
118         if (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
119           find_program(OBJCOPY ${TOOLCHAIN}-objcopy)
120         elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
121           find_program(OBJCOPY objcopy)
122         else()
123           clr_unknown_arch()
124         endif()
125       else()
126         find_program(OBJCOPY objcopy)
127       endif()
128
129       if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND")
130           message(FATAL_ERROR "objcopy not found")
131       endif()
132
133     endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
134 endif(WIN32)
135
136 #----------------------------------------------------
137 # Configure compiler settings for environment
138 #----------------------------------------------------
139 include(configurecompiler.cmake)
140
141 #----------------------------------------------------
142 # Cross target Component build specific configuration
143 #----------------------------------------------------
144 if(CLR_CROSS_COMPONENTS_BUILD)
145   include(crosscomponents.cmake)
146 endif(CLR_CROSS_COMPONENTS_BUILD)
147
148 #-------------------
149 # Enable PGO support
150 #-------------------
151 include(pgosupport.cmake)
152
153 #-----------------------------------------
154 # Add Projects
155 #     - project which require platform header not clr's
156 #     - do not depend on clr's compile definitions
157 #-----------------------------------------
158 if(CLR_CMAKE_PLATFORM_UNIX AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
159     add_subdirectory(src/corefx)
160 endif()
161
162 if(CLR_CMAKE_PLATFORM_UNIX)
163     add_subdirectory(src/ToolBox/SOS/lldbplugin)
164     add_subdirectory(src/pal)
165     add_subdirectory(src/coreclr/hosts)
166     add_subdirectory(src/ildasm/unixcoreclrloader)
167 endif(CLR_CMAKE_PLATFORM_UNIX)
168
169 # Add this subdir. We install the headers for the jit.
170 add_subdirectory(src/pal/prebuilt/inc)
171
172 add_subdirectory(src/debug/debug-pal)
173
174 if(WIN32)
175   add_subdirectory(src/gc/sample)
176 endif()
177
178 # Above projects do not build with these compile options
179 # All of the compiler options are specified in file compileoptions.cmake
180 # Do not add any new options here. They should be added in compileoptions.cmake
181 if(WIN32)
182   add_compile_options(/FIWarningControl.h) # force include of WarningControl.h
183   add_compile_options(/Zl) # omit default library name in .OBJ
184 endif(WIN32)
185
186 #------------------------------
187 # Add Test Directory
188 #------------------------------
189 if(CLR_CMAKE_BUILD_TESTS)
190   add_subdirectory(tests)
191 endif(CLR_CMAKE_BUILD_TESTS)
192
193 #--------------------------------
194 # Definition directives
195 #  - all clr specific compile definitions should be included in this file
196 #  - all clr specific feature variable should also be added in this file
197 #----------------------------------
198 include(clrdefinitions.cmake)
199
200 #-------------------------------------
201 # Include directory directives
202 #-------------------------------------
203 # Include the basic prebuilt headers - required for getting fileversion resource details.
204 include_directories("src/pal/prebuilt/inc")
205 include_directories("bin/obj")
206
207 if(FEATURE_STANDALONE_GC)
208   add_definitions(-DFEATURE_STANDALONE_GC)
209   add_subdirectory(src/gc)
210 endif(FEATURE_STANDALONE_GC)
211
212 if (CLR_CMAKE_PLATFORM_UNIX)
213   include_directories("src/pal/inc")
214   include_directories("src/pal/inc/rt")
215   include_directories("src/pal/src/safecrt")
216 endif (CLR_CMAKE_PLATFORM_UNIX)
217
218 #------------------------------
219 # Add Product Directory
220 #------------------------------
221 add_subdirectory(src)
222
223 include(definitionsconsistencycheck.cmake)