1 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
2 cmake_minimum_required(VERSION 3.13.4)
3 if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
5 "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
6 "minimum version of CMake required to build LLVM will become 3.20.0, and "
7 "using an older CMake will become an error. Please upgrade your CMake to "
8 "at least 3.20.0 now to avoid issues in the future!")
11 set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
12 project(CompilerRTCRT C)
13 set(COMPILER_RT_STANDALONE_BUILD TRUE)
14 set(COMPILER_RT_CRT_STANDALONE_BUILD TRUE)
16 set(COMPILER_RT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../..")
18 set(LLVM_COMMON_CMAKE_UTILS "${COMPILER_RT_SOURCE_DIR}/../cmake")
20 # Add path for custom modules
21 list(INSERT CMAKE_MODULE_PATH 0
22 "${COMPILER_RT_SOURCE_DIR}/cmake"
23 "${COMPILER_RT_SOURCE_DIR}/cmake/Modules"
24 "${LLVM_COMMON_CMAKE_UTILS}"
25 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
28 include(base-config-ix)
29 include(CompilerRTUtils)
32 construct_compiler_rt_default_triple()
34 include(SetPlatformToolchainTools)
35 include(AddCompilerRT)
38 include(crt-config-ix)
40 if(COMPILER_RT_HAS_CRT)
41 add_compiler_rt_component(crt)
43 include(CheckSectionExists)
44 check_section_exists(".init_array" COMPILER_RT_HAS_INITFINI_ARRAY
45 SOURCE "volatile int x;\n__attribute__((constructor)) void f(void) {x = 0;}\nint main(void) { return 0; }\n")
47 append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 CRT_CFLAGS)
48 append_list_if(COMPILER_RT_HAS_INITFINI_ARRAY -DCRT_HAS_INITFINI_ARRAY CRT_CFLAGS)
49 append_list_if(COMPILER_RT_CRT_USE_EH_FRAME_REGISTRY -DEH_USE_FRAME_REGISTRY CRT_CFLAGS)
50 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC CRT_CFLAGS)
51 append_list_if(COMPILER_RT_HAS_WNO_PEDANTIC -Wno-pedantic CRT_CFLAGS)
52 if (COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
53 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full CRT_CFLAGS)
56 foreach(arch ${CRT_SUPPORTED_ARCH})
57 add_compiler_rt_runtime(clang_rt.crtbegin
60 SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtbegin.c
63 add_compiler_rt_runtime(clang_rt.crtend
66 SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtend.c