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