1 cmake_minimum_required(VERSION 3.13.4)
3 # Use old version of target_sources command which converts the source
4 # file paths to full paths.
5 cmake_policy(SET CMP0076 OLD)
6 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
8 # The top-level source directory of libc.
9 set(LIBC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
10 # The top-level directory in which libc is being built.
11 set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
13 # Path libc/scripts directory.
14 set(LIBC_BUILD_SCRIPTS_DIR "${LIBC_SOURCE_DIR}/utils/build_scripts")
17 set(LIBC_TARGET_OS ${CMAKE_SYSTEM_NAME})
18 string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS)
20 set(LIBC_TARGET_MACHINE ${CMAKE_SYSTEM_PROCESSOR})
22 # Check --print-resource-dir to find the compiler resource dir if this flag
23 # is supported by the compiler.
25 OUTPUT_STRIP_TRAILING_WHITESPACE
26 COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
27 RESULT_VARIABLE COMMAND_RETURN_CODE
28 OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
30 # Retrieve the host compiler's resource dir.
31 if(COMMAND_RETURN_CODE EQUAL 0)
32 set(COMPILER_RESOURCE_DIR
33 "${COMPILER_RESOURCE_DIR}" CACHE PATH "path to compiler resource dir"
35 message(STATUS "Set COMPILER_RESOURCE_DIR to "
36 "${COMPILER_RESOURCE_DIR} using --print-resource-dir")
38 set(COMPILER_RESOURCE_DIR OFF)
39 message(STATUS "COMPILER_RESOURCE_DIR not set
40 --print-resource-dir not supported by host compiler")
43 option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" ON)
44 if(LLVM_LIBC_ENABLE_LINTING)
45 if("clang-tools-extra" IN_LIST LLVM_ENABLE_PROJECTS
46 AND "clang" IN_LIST LLVM_ENABLE_PROJECTS)
47 add_custom_target(lint-libc)
50 'clang' and 'clang-tools-extra' are required in LLVM_ENABLE_PROJECTS to
51 lint llvm-libc. The linting step performs important checks to help prevent
52 the introduction of subtle bugs, but it may increase build times.
54 To disable linting set LLVM_LIBC_ENABLE_LINTING to OFF
55 (pass -DLLVM_LIBC_ENABLE_LINTING=OFF to cmake).")
59 Linting for libc is currently disabled.
61 This is not recommended, to enable set LLVM_LIBC_ENABLE_LINTING to ON
62 (pass -DLLVM_LIBC_ENABLE_LINTING=ON to cmake).")
65 include(CMakeParseArguments)
66 include(LLVMLibCRules)
67 include(LLVMLibCCheckCpuFeatures)
69 include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/entrypoints.txt")
70 include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/headers.txt")
72 set(TARGET_ENTRYPOINT_NAME_LIST "")
73 foreach(entrypoint IN LISTS TARGET_LIBC_ENTRYPOINTS TARGET_LIBM_ENTRYPOINTS)
74 string(FIND ${entrypoint} "." last_dot_loc REVERSE)
75 if(${last_dot_loc} EQUAL -1)
76 message(FATAL "Invalid entrypoint target name ${entrypoint}; Expected a '.' "
79 math(EXPR name_loc "${last_dot_loc} + 1")
80 string(SUBSTRING ${entrypoint} ${name_loc} -1 entrypoint_name)
81 list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name})
84 add_subdirectory(include)
85 add_subdirectory(config)
87 add_subdirectory(utils)
89 # The loader can potentially depend on the library components so add it
90 # after the library implementation directories.
91 add_subdirectory(loader)
93 # The lib and test directories are added at the very end as tests
94 # and libraries potentially draw from the components present in all
95 # of the other directories.
97 if(LLVM_INCLUDE_TESTS)
98 add_subdirectory(test)
99 add_subdirectory(fuzzing)
102 add_subdirectory(benchmarks)