[NFC] Fix call to lldb RegisterValue constructor
[lldb.git] / libc / CMakeLists.txt
1 cmake_minimum_required(VERSION 3.13.4)
2
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")
7
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})
12
13 # Path libc/scripts directory.
14 set(LIBC_BUILD_SCRIPTS_DIR "${LIBC_SOURCE_DIR}/utils/build_scripts")
15
16
17 set(LIBC_TARGET_OS ${CMAKE_SYSTEM_NAME})
18 string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS)
19
20 set(LIBC_TARGET_MACHINE ${CMAKE_SYSTEM_PROCESSOR})
21
22 # Check --print-resource-dir to find the compiler resource dir if this flag
23 # is supported by the compiler.
24 execute_process(
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
29 )
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"
34   )
35   message(STATUS "Set COMPILER_RESOURCE_DIR to "
36                  "${COMPILER_RESOURCE_DIR} using --print-resource-dir")
37 else()
38   set(COMPILER_RESOURCE_DIR OFF)
39   message(STATUS "COMPILER_RESOURCE_DIR not set
40                   --print-resource-dir not supported by host compiler")
41 endif()
42
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)
48   else()
49     message(FATAL_ERROR "
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.
53
54       To disable linting set LLVM_LIBC_ENABLE_LINTING to OFF
55       (pass -DLLVM_LIBC_ENABLE_LINTING=OFF to cmake).")
56   endif()
57 else()
58   message(WARNING "
59     Linting for libc is currently disabled.
60
61     This is not recommended, to enable set LLVM_LIBC_ENABLE_LINTING to ON
62     (pass -DLLVM_LIBC_ENABLE_LINTING=ON to cmake).")
63 endif()
64
65 include(CMakeParseArguments)
66 include(LLVMLibCRules)
67 include(LLVMLibCCheckCpuFeatures)
68
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")
71
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 '.' "
77                   "(dot) in the name.")
78   endif()
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})
82 endforeach()
83
84 add_subdirectory(include)
85 add_subdirectory(config)
86 add_subdirectory(src)
87 add_subdirectory(utils)
88
89 # The loader can potentially depend on the library components so add it
90 # after the library implementation directories.
91 add_subdirectory(loader)
92
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.
96 add_subdirectory(lib)
97 if(LLVM_INCLUDE_TESTS)
98   add_subdirectory(test)
99   add_subdirectory(fuzzing)
100 endif()
101
102 add_subdirectory(benchmarks)