Refactor native build to remove the compiler-override files (#23897)
[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 if (NOT WIN32)
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.")
11 endif()
12
13 # Set the project name
14 project(CoreCLR)
15
16 # Include cmake functions
17 include(functions.cmake)
18
19 # Verify that LTCG/LTO is available
20 include(configure.cmake)
21
22 if (WIN32)
23   message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}")
24   message(STATUS "VS_PLATFORM_NAME is ${CMAKE_VS_PLATFORM_NAME}")
25 endif (WIN32)
26
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)
34
35 set(CORECLR_SET_RPATH ON)
36 if(CORECLR_SET_RPATH)
37     # Enable @rpath support for shared libraries.
38     set(MACOSX_RPATH ON)
39 endif(CORECLR_SET_RPATH)
40
41 OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)
42 OPTION(CLR_CMAKE_WARNINGS_ARE_ERRORS "Warnings are errors" ON)
43
44 # Ensure other tools are present
45 if (WIN32)
46     if(CLR_CMAKE_HOST_ARCH STREQUAL arm)
47
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.")
51       else()
52               message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
53       endif()
54
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)
57
58       set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
59       message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
60
61       # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
62       # use ml[64].exe as the assembler.
63       enable_language(ASM)
64     elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm64)
65
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.")
69       else()
70               message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
71       endif()
72
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)
75
76       set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
77       message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
78
79       # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
80       # use ml[64].exe as the assembler.
81       enable_language(ASM)
82     else()
83       enable_language(ASM_MASM)
84     endif()
85
86     # Ensure that MC is present
87     find_program(MC mc)
88     if (MC STREQUAL "MC-NOTFOUND")
89         message(FATAL_ERROR "MC not found")
90     endif()
91
92 else (WIN32)
93     enable_language(ASM)
94
95     # Ensure that awk is present
96     find_program(AWK awk)
97     if (AWK STREQUAL "AWK-NOTFOUND")
98         message(FATAL_ERROR "AWK not found")
99     endif()
100
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)
105
106     if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
107
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")
112       endif()
113
114       find_program(STRIP strip)
115       if (STRIP STREQUAL "STRIP-NOTFOUND")
116           message(FATAL_ERROR "strip not found")
117       endif()
118
119     else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
120
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)
127         else()
128           clr_unknown_arch()
129         endif()
130       else()
131         find_program(OBJCOPY objcopy)
132       endif()
133
134       if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND")
135           message(FATAL_ERROR "objcopy not found")
136       endif()
137
138     endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
139 endif(WIN32)
140
141 #----------------------------------------------------
142 # Configure compiler settings for environment
143 #----------------------------------------------------
144 include(configurecompiler.cmake)
145
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)
152
153 #-------------------
154 # Enable PGO support
155 #-------------------
156 include(pgosupport.cmake)
157
158 #-----------------------------------------
159 # Add Projects
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)
165 endif()
166
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)
173
174 # Add this subdir. We install the headers for the jit.
175 add_subdirectory(src/pal/prebuilt/inc)
176
177 add_subdirectory(src/debug/debug-pal)
178
179 if(WIN32)
180   add_subdirectory(src/gc/sample)
181 endif()
182
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
186 if(WIN32)
187   add_compile_options(/FIWarningControl.h) # force include of WarningControl.h
188   add_compile_options(/Zl) # omit default library name in .OBJ
189 endif(WIN32)
190
191 #------------------------------
192 # Add Test Directory
193 #------------------------------
194 if(CLR_CMAKE_BUILD_TESTS)
195   add_subdirectory(tests)
196 endif(CLR_CMAKE_BUILD_TESTS)
197
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)
204
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")
211
212 if(FEATURE_STANDALONE_GC)
213   add_definitions(-DFEATURE_STANDALONE_GC)
214   add_subdirectory(src/gc)
215 endif(FEATURE_STANDALONE_GC)
216
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)
222
223 #------------------------------
224 # Add Product Directory
225 #------------------------------
226 add_subdirectory(src)
227
228 include(definitionsconsistencycheck.cmake)