comparison libc/CMakeLists.txt @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 5f17cb93ff66
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
1 cmake_minimum_required(VERSION 3.13.4) 1 cmake_minimum_required(VERSION 3.13.4)
2
3 # Default to C++17
4 set(CMAKE_CXX_STANDARD 17)
2 5
3 # Use old version of target_sources command which converts the source 6 # Use old version of target_sources command which converts the source
4 # file paths to full paths. 7 # file paths to full paths.
5 cmake_policy(SET CMP0076 OLD) 8 cmake_policy(SET CMP0076 OLD)
6 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") 9 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
7 10
8 # The top-level sourse and binary directories. 11 # The top-level sourse and binary directories.
9 set(LIBC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 12 set(LIBC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
10 set(LIBC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) 13 set(LIBC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
11 # The top-level directory in which libc is being built. 14 # The top-level directory in which libc is being built.
12 set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) 15 set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
13 16
14 # Path libc/scripts directory. 17 # Path libc/scripts directory.
15 set(LIBC_BUILD_SCRIPTS_DIR "${LIBC_SOURCE_DIR}/utils/build_scripts") 18 set(LIBC_BUILD_SCRIPTS_DIR "${LIBC_SOURCE_DIR}/utils/build_scripts")
16 19
17 set(LIBC_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Define libc destination prefix.")
18
19 set(LIBC_TARGET_OS ${CMAKE_SYSTEM_NAME}) 20 set(LIBC_TARGET_OS ${CMAKE_SYSTEM_NAME})
20 string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS) 21 string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS)
21 22
22 # Defines LIBC_TARGET_ARCHITECTURE and associated macros. 23 # Defines LIBC_TARGET_ARCHITECTURE and associated macros.
23 include(LLVMLibCArchitectures) 24 include(LLVMLibCArchitectures)
25 include(LLVMLibCCheckMPFR)
24 26
25 # Flags to pass down to the compiler while building the libc functions. 27 # Flags to pass down to the compiler while building the libc functions.
26 set(LIBC_COMPILE_OPTIONS_DEFAULT "" CACHE STRING "Architecture to tell clang to optimize for (e.g. -march=... or -mcpu=...)") 28 set(LIBC_COMPILE_OPTIONS_DEFAULT "" CACHE STRING "Architecture to tell clang to optimize for (e.g. -march=... or -mcpu=...)")
27 29
28 # Check --print-resource-dir to find the compiler resource dir if this flag 30 # Check --print-resource-dir to find the compiler resource dir if this flag
45 message(STATUS "COMPILER_RESOURCE_DIR not set 47 message(STATUS "COMPILER_RESOURCE_DIR not set
46 --print-resource-dir not supported by host compiler") 48 --print-resource-dir not supported by host compiler")
47 endif() 49 endif()
48 50
49 option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc" OFF) 51 option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc" OFF)
50 52 option(LLVM_LIBC_IMPLEMENTATION_DEFINED_TEST_BEHAVIOR "Build LLVM libc tests assuming our implementation-defined behavior" ON)
51 option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" OFF) 53 option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" OFF)
52 if(LLVM_LIBC_ENABLE_LINTING AND (NOT LLVM_LIBC_FULL_BUILD)) 54
53 message(FATAL_ERROR "Cannot enable linting when full libc build is not enabled.") 55 if(LLVM_LIBC_CLANG_TIDY)
54 endif() 56 set(LLVM_LIBC_ENABLE_LINTING ON)
57 endif()
58
55 if(LLVM_LIBC_ENABLE_LINTING) 59 if(LLVM_LIBC_ENABLE_LINTING)
56 if("clang-tools-extra" IN_LIST LLVM_ENABLE_PROJECTS 60 if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
57 AND "clang" IN_LIST LLVM_ENABLE_PROJECTS) 61 set(LLVM_LIBC_ENABLE_LINTING OFF)
58 add_custom_target(lint-libc) 62 message(WARNING "C++ compiler is not clang++, linting with be disabled.")
59 else() 63 else()
60 message(FATAL_ERROR " 64 if (NOT LLVM_LIBC_CLANG_TIDY)
61 'clang' and 'clang-tools-extra' are required in LLVM_ENABLE_PROJECTS to 65 find_program(LLVM_LIBC_CLANG_TIDY NAMES clang-tidy)
62 lint llvm-libc. The linting step performs important checks to help prevent 66 endif()
63 the introduction of subtle bugs, but it may increase build times. 67
64 68 if(LLVM_LIBC_CLANG_TIDY)
65 To disable linting set LLVM_LIBC_ENABLE_LINTING to OFF 69 # Check clang-tidy major version.
66 (pass -DLLVM_LIBC_ENABLE_LINTING=OFF to cmake).") 70 execute_process(COMMAND ${LLVM_LIBC_CLANG_TIDY} "--version"
71 OUTPUT_VARIABLE CLANG_TIDY_OUTPUT)
72 string(REGEX MATCH "[0-9]+" CLANG_TIDY_VERSION "${CLANG_TIDY_OUTPUT}")
73 string(REGEX MATCH "[0-9]+" CLANG_MAJOR_VERSION
74 "${CMAKE_CXX_COMPILER_VERSION}")
75 if(NOT CLANG_TIDY_VERSION EQUAL CLANG_MAJOR_VERSION)
76 set(LLVM_LIBC_ENABLE_LINTING OFF)
77 message(WARNING "
78 'clang-tidy' (version ${CLANG_TIDY_VERSION}) is not the same as
79 'clang' (version ${CLANG_MAJOR_VERSION}). Linting will
80 be disabled.
81
82 The path to the clang-tidy binary can be set manually by passing
83 -DLLVM_LIBC_CLANG_TIDY=<path/to/clang-tidy> to CMake.")
84 endif()
85 else()
86 message(FATAL_ERROR "
87 Linting is enabled but 'clang-tidy' is not found!
88
89 The path to the clang-tidy binary can be set manually by passing
90 -DLLVM_LIBC_CLANG_TIDY=<path/to/clang-tidy> to CMake.
91
92 To disable linting set LLVM_LIBC_ENABLE_LINTING to OFF
93 (pass -DLLVM_LIBC_ENABLE_LINTING=OFF to cmake).")
94 endif()
67 endif() 95 endif()
68 elseif(LLVM_LIBC_FULL_BUILD) 96 endif()
69 message(WARNING " 97
70 Linting for libc is currently disabled. 98 option(LLVM_LIBC_INCLUDE_SCUDO "Include the SCUDO standalone as the allocator for LLVM libc" OFF)
71 99 if(LLVM_LIBC_INCLUDE_SCUDO)
72 This is not recommended, to enable set LLVM_LIBC_ENABLE_LINTING to ON 100 if (NOT "compiler-rt" IN_LIST LLVM_ENABLE_PROJECTS)
73 (pass -DLLVM_LIBC_ENABLE_LINTING=ON to cmake).") 101 message(FATAL_ERROR "SCUDO cannot be included without adding compiler-rt to LLVM_ENABLE_PROJECTS")
74 endif() 102 endif()
103 endif()
104
105 option(LIBC_INCLUDE_DOCS "Build the libc documentation." ${LLVM_INCLUDE_DOCS})
75 106
76 include(CMakeParseArguments) 107 include(CMakeParseArguments)
108 include(LLVMLibCCheckCpuFeatures)
77 include(LLVMLibCRules) 109 include(LLVMLibCRules)
78 include(LLVMLibCCheckCpuFeatures)
79 110
80 if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt") 111 if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt")
81 set(entrypoint_file "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt") 112 set(entrypoint_file "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt")
82 elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/entrypoints.txt") 113 elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/entrypoints.txt")
83 set(entrypoint_file "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/entrypoints.txt") 114 set(entrypoint_file "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/entrypoints.txt")
84 else() 115 else()
85 message(FATAL_ERROR "entrypoints.txt file for the target platform not found.") 116 message(FATAL_ERROR "entrypoints.txt file for the target platform '${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}' not found.")
86 endif() 117 endif()
87 include(${entrypoint_file}) 118 include(${entrypoint_file})
88 119
89 if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt") 120 if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt")
90 include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt") 121 include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt")
91 elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/headers.txt") 122 elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/headers.txt")
92 include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}//headers.txt") 123 include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/headers.txt")
93 endif() 124 endif()
94 125
95 set(TARGET_ENTRYPOINT_NAME_LIST "") 126 set(TARGET_ENTRYPOINT_NAME_LIST "")
96 foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS) 127 foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
97 string(FIND ${entrypoint} "." last_dot_loc REVERSE) 128 string(FIND ${entrypoint} "." last_dot_loc REVERSE)
108 # We need to set up hdrgen first since other targets depend on it. 139 # We need to set up hdrgen first since other targets depend on it.
109 add_subdirectory(utils/LibcTableGenUtil) 140 add_subdirectory(utils/LibcTableGenUtil)
110 add_subdirectory(utils/HdrGen) 141 add_subdirectory(utils/HdrGen)
111 endif() 142 endif()
112 143
144 set(LIBC_TARGET)
145 set(LIBC_COMPONENT)
146 set(LIBC_INSTALL_DEPENDS)
147 set(LIBC_INSTALL_TARGET)
148 if(LLVM_LIBC_FULL_BUILD)
149 set(LIBC_TARGET libc)
150 set(LIBC_COMPONENT libc)
151 set(LIBC_INSTALL_DEPENDS "libc;install-libc-headers;libc-startup")
152 set(LIBC_INSTALL_TARGET install-libc)
153 set(LIBC_ARCHIVE_NAME c)
154 else()
155 set(LIBC_TARGET llvmlibc)
156 set(LIBC_COMPONENT llvmlibc)
157 set(LIBC_INSTALL_DEPENDS llvmlibc)
158 set(LIBC_INSTALL_TARGET install-llvmlibc)
159 set(LIBC_ARCHIVE_NAME llvmlibc)
160 endif()
161
113 add_subdirectory(include) 162 add_subdirectory(include)
114 add_subdirectory(config) 163 add_subdirectory(config)
115 add_subdirectory(src) 164 add_subdirectory(src)
116 add_subdirectory(utils) 165 add_subdirectory(utils)
117 166
128 if(LLVM_INCLUDE_TESTS) 177 if(LLVM_INCLUDE_TESTS)
129 add_subdirectory(test) 178 add_subdirectory(test)
130 add_subdirectory(fuzzing) 179 add_subdirectory(fuzzing)
131 endif() 180 endif()
132 181
133 add_subdirectory(benchmarks) 182 if(LIBC_INCLUDE_BENCHMARKS)
183 add_subdirectory(benchmarks)
184 endif()
185
186 if (LIBC_INCLUDE_DOCS)
187 add_subdirectory(docs)
188 endif()
189
190
191 if(LLVM_LIBC_FULL_BUILD)
192 add_llvm_install_targets(
193 install-libc-headers
194 DEPENDS libc-headers
195 COMPONENT libc-headers
196 )
197 endif()
198
199 add_llvm_install_targets(
200 ${LIBC_INSTALL_TARGET}
201 DEPENDS ${LIBC_INSTALL_DEPENDS}
202 COMPONENT ${LIBC_COMPONENT}
203 )