Set vtable offset as contained
[platform/upstream/coreclr.git] / CMakeLists.txt
1 # Verify minimum required version
2 cmake_minimum_required(VERSION 3.5.1)
3
4 cmake_policy(SET CMP0042 NEW)
5
6 # Set the project name
7 project(CoreCLR)
8
9 # Include cmake functions
10 include(functions.cmake)
11
12 # Verify that LTCG/LTO is available
13 include(configure.cmake)
14
15 if (WIN32)
16   message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}")
17   message(STATUS "VS_PLATFORM_NAME is ${CMAKE_VS_PLATFORM_NAME}")
18 endif (WIN32)
19
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)
27
28 set(CORECLR_SET_RPATH ON)
29 if(CORECLR_SET_RPATH)
30     # Enable @rpath support for shared libraries.
31     set(MACOSX_RPATH ON)
32 endif(CORECLR_SET_RPATH)
33
34 OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)
35 OPTION(CLR_CMAKE_WARNINGS_ARE_ERRORS "Warnings are errors" ON)
36
37 # Ensure other tools are present
38 if (WIN32)
39     if(CLR_CMAKE_HOST_ARCH STREQUAL arm)
40
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.")
44       else()
45               message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
46       endif()
47
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)
50
51       set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
52       message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
53
54       # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
55       # use ml[64].exe as the assembler.
56       enable_language(ASM)
57     elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm64)
58
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.")
62       else()
63               message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
64       endif()
65
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)
68
69       set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
70       message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
71
72       # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
73       # use ml[64].exe as the assembler.
74       enable_language(ASM)
75     else()
76       enable_language(ASM_MASM)
77     endif()
78
79     # Ensure that MC is present
80     find_program(MC mc)
81     if (MC STREQUAL "MC-NOTFOUND")
82         message(FATAL_ERROR "MC not found")
83     endif()
84
85 else (WIN32)
86     enable_language(ASM)
87
88     # Ensure that awk is present
89     find_program(AWK awk)
90     if (AWK STREQUAL "AWK-NOTFOUND")
91         message(FATAL_ERROR "AWK not found")
92     endif()
93
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)
98
99     if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
100
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")
105       endif()
106
107       find_program(STRIP strip)
108       if (STRIP STREQUAL "STRIP-NOTFOUND")
109           message(FATAL_ERROR "strip not found")
110       endif()
111
112     else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
113
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)
120         else()
121           clr_unknown_arch()
122         endif()
123       else()
124         find_program(OBJCOPY objcopy)
125       endif()
126
127       if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND")
128           message(FATAL_ERROR "objcopy not found")
129       endif()
130
131     endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
132 endif(WIN32)
133
134 #----------------------------------------------------
135 # Configure compiler settings for environment
136 #----------------------------------------------------
137 include(configurecompiler.cmake)
138
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)
145
146 #-------------------
147 # Enable PGO support
148 #-------------------
149 include(pgosupport.cmake)
150
151 #-----------------------------------------
152 # Add Projects
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)
158 endif()
159
160 if(CLR_CMAKE_PLATFORM_UNIX)
161     add_subdirectory(src/pal)
162     add_subdirectory(src/coreclr/hosts)
163     add_subdirectory(src/ildasm/unixcoreclrloader)
164 endif(CLR_CMAKE_PLATFORM_UNIX)
165
166 # Add this subdir. We install the headers for the jit.
167 add_subdirectory(src/pal/prebuilt/inc)
168
169 add_subdirectory(src/debug/debug-pal)
170
171 if(WIN32)
172   add_subdirectory(src/gc/sample)
173 endif()
174
175 # Above projects do not build with these compile options
176 # All of the compiler options are specified in file compileoptions.cmake
177 # Do not add any new options here. They should be added in compileoptions.cmake
178 if(WIN32)
179   add_compile_options(/FIWarningControl.h) # force include of WarningControl.h
180   add_compile_options(/Zl) # omit default library name in .OBJ
181 endif(WIN32)
182
183 #------------------------------
184 # Add Test Directory
185 #------------------------------
186 if(CLR_CMAKE_BUILD_TESTS)
187   add_subdirectory(tests)
188 endif(CLR_CMAKE_BUILD_TESTS)
189
190 #--------------------------------
191 # Definition directives
192 #  - all clr specific compile definitions should be included in this file
193 #  - all clr specific feature variable should also be added in this file
194 #----------------------------------
195 include(clrdefinitions.cmake)
196
197 #-------------------------------------
198 # Include directory directives
199 #-------------------------------------
200 # Include the basic prebuilt headers - required for getting fileversion resource details.
201 include_directories("src/pal/prebuilt/inc")
202 include_directories("bin/obj")
203
204 if(FEATURE_STANDALONE_GC)
205   add_definitions(-DFEATURE_STANDALONE_GC)
206   add_subdirectory(src/gc)
207 endif(FEATURE_STANDALONE_GC)
208
209 if (CLR_CMAKE_PLATFORM_UNIX)
210   include_directories("src/pal/inc")
211   include_directories("src/pal/inc/rt")
212   include_directories("src/pal/src/safecrt")
213 endif (CLR_CMAKE_PLATFORM_UNIX)
214
215 #------------------------------
216 # Add Product Directory
217 #------------------------------
218 add_subdirectory(src)
219
220 include(definitionsconsistencycheck.cmake)