Merge pull request #19334 from CarolEidt/Fix19243
[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.cpp")
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 that python is present
40 find_program(PYTHON NAMES python2.7 python2 python)
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/")
43 endif()
44
45 # Ensure other tools are present
46 if (WIN32)
47     if(CLR_CMAKE_HOST_ARCH STREQUAL arm)
48
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.")
52       else()
53               message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
54       endif()
55
56       # Explicitly specify the assembler to be used for Arm32 compile
57       if($ENV{__VSVersion} STREQUAL "vs2015")
58         file(TO_CMAKE_PATH "$ENV{VCINSTALLDIR}\\bin\\x86_arm\\armasm.exe" CMAKE_ASM_COMPILER)
59       else()
60         file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER)
61       endif()
62
63       set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
64       message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
65
66       # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
67       # use ml[64].exe as the assembler.
68       enable_language(ASM)
69     elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm64)
70
71       # Confirm that Windows SDK is present
72       if(NOT DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION OR CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION STREQUAL "" )
73               message(FATAL_ERROR "Windows SDK is required for the ARM64 build.")
74       else()
75               message("Using Windows SDK version ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
76       endif()
77
78       # Explicitly specify the assembler to be used for Arm64 compile
79       file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)
80
81       set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
82       message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
83
84       # Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
85       # use ml[64].exe as the assembler.
86       enable_language(ASM)
87     else()
88       enable_language(ASM_MASM)
89     endif()
90
91     # Ensure that MC is present
92     find_program(MC mc)
93     if (MC STREQUAL "MC-NOTFOUND")
94         message(FATAL_ERROR "MC not found")
95     endif()
96
97 else (WIN32)
98     enable_language(ASM)
99
100     # Ensure that awk is present
101     find_program(AWK awk)
102     if (AWK STREQUAL "AWK-NOTFOUND")
103         message(FATAL_ERROR "AWK not found")
104     endif()
105
106     # Try to locate the paxctl tool. Failure to find it is not fatal,
107     # but the generated executables won't work on a system where PAX is set
108     # to prevent applications to create executable memory mappings.
109     find_program(PAXCTL paxctl)
110
111     if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
112
113       # Ensure that dsymutil and strip are present
114       find_program(DSYMUTIL dsymutil)
115       if (DSYMUTIL STREQUAL "DSYMUTIL-NOTFOUND")
116           message(FATAL_ERROR "dsymutil not found")
117       endif()
118
119       find_program(STRIP strip)
120       if (STRIP STREQUAL "STRIP-NOTFOUND")
121           message(FATAL_ERROR "strip not found")
122       endif()
123
124     else (CMAKE_SYSTEM_NAME STREQUAL Darwin)
125
126       # Ensure that objcopy is present
127       if (CLR_UNIX_CROSS_BUILD AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
128         if (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
129           find_program(OBJCOPY ${TOOLCHAIN}-objcopy)
130         elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
131           find_program(OBJCOPY objcopy)
132         else()
133           clr_unknown_arch()
134         endif()
135       else()
136         find_program(OBJCOPY objcopy)
137       endif()
138
139       if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND")
140           message(FATAL_ERROR "objcopy not found")
141       endif()
142
143     endif (CMAKE_SYSTEM_NAME STREQUAL Darwin)
144 endif(WIN32)
145
146 #----------------------------------------------------
147 # Configure compiler settings for environment
148 #----------------------------------------------------
149 include(configurecompiler.cmake)
150
151 #----------------------------------------------------
152 # Cross target Component build specific configuration
153 #----------------------------------------------------
154 if(CLR_CROSS_COMPONENTS_BUILD)
155   include(crosscomponents.cmake)
156 endif(CLR_CROSS_COMPONENTS_BUILD)
157
158 #-------------------
159 # Enable PGO support
160 #-------------------
161 include(pgosupport.cmake)
162
163 #-----------------------------------------
164 # Add Projects
165 #     - project which require platform header not clr's
166 #     - do not depend on clr's compile definitions
167 #-----------------------------------------
168 if(CLR_CMAKE_PLATFORM_UNIX AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
169     add_subdirectory(src/corefx)
170 endif()
171
172 if(CLR_CMAKE_PLATFORM_UNIX)
173     add_subdirectory(src/ToolBox/SOS/lldbplugin)
174     add_subdirectory(src/pal)
175     add_subdirectory(src/coreclr/hosts)
176     add_subdirectory(src/ildasm/unixcoreclrloader)
177 endif(CLR_CMAKE_PLATFORM_UNIX)
178
179 # Add this subdir. We install the headers for the jit.
180 add_subdirectory(src/pal/prebuilt/inc)
181
182 add_subdirectory(src/debug/debug-pal)
183
184 if(WIN32)
185   add_subdirectory(src/gc/sample)
186 endif()
187
188 # Above projects do not build with these compile options
189 # All of the compiler options are specified in file compileoptions.cmake
190 # Do not add any new options here. They should be added in compileoptions.cmake
191 if(WIN32)
192   add_compile_options(/FIWarningControl.h) # force include of WarningControl.h
193   add_compile_options(/Zl) # omit default library name in .OBJ
194 endif(WIN32)
195
196 #------------------------------
197 # Add Test Directory
198 #------------------------------
199 if(CLR_CMAKE_BUILD_TESTS)
200   add_subdirectory(tests)
201 endif(CLR_CMAKE_BUILD_TESTS)
202
203 #--------------------------------
204 # Definition directives
205 #  - all clr specific compile definitions should be included in this file
206 #  - all clr specific feature variable should also be added in this file
207 #----------------------------------
208 include(clrdefinitions.cmake)
209
210 #-------------------------------------
211 # Include directory directives
212 #-------------------------------------
213 # Include the basic prebuilt headers - required for getting fileversion resource details.
214 include_directories("src/pal/prebuilt/inc")
215 include_directories("bin/obj")
216
217 if(FEATURE_STANDALONE_GC)
218   add_definitions(-DFEATURE_STANDALONE_GC)
219   add_subdirectory(src/gc)
220 endif(FEATURE_STANDALONE_GC)
221
222 if (CLR_CMAKE_PLATFORM_UNIX)
223   include_directories("src/pal/inc")
224   include_directories("src/pal/inc/rt")
225   include_directories("src/pal/src/safecrt")
226 endif (CLR_CMAKE_PLATFORM_UNIX)
227
228 # Microsoft.Dotnet.BuildTools.Coreclr version
229 set(BuildToolsVersion "1.0.4-prerelease")
230 set(BuildToolsDir "${CLR_CMAKE_PACKAGES_DIR}/Microsoft.DotNet.BuildTools.CoreCLR/${BuildToolsVersion}")
231
232 #------------------------------
233 # Add Product Directory
234 #------------------------------
235 add_subdirectory(src)
236
237 include(definitionsconsistencycheck.cmake)