2020-04-10 11:41:22 +08:00
|
|
|
cmake_minimum_required(VERSION 3.13.4)
|
2019-10-05 01:30:54 +08:00
|
|
|
|
2021-04-05 01:13:19 +08:00
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
2022-02-03 13:03:27 +08:00
|
|
|
# Default to C++17
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
|
2020-01-27 13:50:27 +08:00
|
|
|
# Use old version of target_sources command which converts the source
|
|
|
|
# file paths to full paths.
|
|
|
|
cmake_policy(SET CMP0076 OLD)
|
2021-10-26 04:29:14 +08:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
|
2019-10-05 01:30:54 +08:00
|
|
|
|
2021-03-20 12:50:48 +08:00
|
|
|
# The top-level sourse and binary directories.
|
2019-10-05 01:30:54 +08:00
|
|
|
set(LIBC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
2021-03-20 12:50:48 +08:00
|
|
|
set(LIBC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
2019-10-05 01:30:54 +08:00
|
|
|
# The top-level directory in which libc is being built.
|
|
|
|
set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
|
|
|
# Path libc/scripts directory.
|
|
|
|
set(LIBC_BUILD_SCRIPTS_DIR "${LIBC_SOURCE_DIR}/utils/build_scripts")
|
|
|
|
|
|
|
|
set(LIBC_TARGET_OS ${CMAKE_SYSTEM_NAME})
|
|
|
|
string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS)
|
|
|
|
|
2021-05-05 23:52:42 +08:00
|
|
|
# Defines LIBC_TARGET_ARCHITECTURE and associated macros.
|
|
|
|
include(LLVMLibCArchitectures)
|
2021-07-28 01:14:18 +08:00
|
|
|
include(LLVMLibCCheckMPFR)
|
2019-10-05 01:30:54 +08:00
|
|
|
|
2021-05-10 15:53:48 +08:00
|
|
|
# Flags to pass down to the compiler while building the libc functions.
|
|
|
|
set(LIBC_COMPILE_OPTIONS_DEFAULT "" CACHE STRING "Architecture to tell clang to optimize for (e.g. -march=... or -mcpu=...)")
|
|
|
|
|
2020-05-22 08:39:03 +08:00
|
|
|
# Check --print-resource-dir to find the compiler resource dir if this flag
|
|
|
|
# is supported by the compiler.
|
|
|
|
execute_process(
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
COMMAND ${CMAKE_CXX_COMPILER} --print-resource-dir
|
|
|
|
RESULT_VARIABLE COMMAND_RETURN_CODE
|
|
|
|
OUTPUT_VARIABLE COMPILER_RESOURCE_DIR
|
|
|
|
)
|
|
|
|
# Retrieve the host compiler's resource dir.
|
|
|
|
if(COMMAND_RETURN_CODE EQUAL 0)
|
|
|
|
set(COMPILER_RESOURCE_DIR
|
|
|
|
"${COMPILER_RESOURCE_DIR}" CACHE PATH "path to compiler resource dir"
|
|
|
|
)
|
2020-05-29 05:52:39 +08:00
|
|
|
message(STATUS "Set COMPILER_RESOURCE_DIR to "
|
|
|
|
"${COMPILER_RESOURCE_DIR} using --print-resource-dir")
|
2020-05-22 08:39:03 +08:00
|
|
|
else()
|
|
|
|
set(COMPILER_RESOURCE_DIR OFF)
|
|
|
|
message(STATUS "COMPILER_RESOURCE_DIR not set
|
|
|
|
--print-resource-dir not supported by host compiler")
|
|
|
|
endif()
|
|
|
|
|
2021-05-03 16:39:26 +08:00
|
|
|
option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc" OFF)
|
|
|
|
|
2021-01-22 14:55:12 +08:00
|
|
|
option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" OFF)
|
2022-02-08 00:46:09 +08:00
|
|
|
|
|
|
|
if(LLVM_LIBC_CLANG_TIDY)
|
|
|
|
set(LLVM_LIBC_ENABLE_LINTING ON)
|
2021-05-03 16:39:26 +08:00
|
|
|
endif()
|
2022-02-08 00:46:09 +08:00
|
|
|
|
2020-04-17 08:40:36 +08:00
|
|
|
if(LLVM_LIBC_ENABLE_LINTING)
|
2022-02-08 00:46:09 +08:00
|
|
|
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
set(LLVM_LIBC_ENABLE_LINTING OFF)
|
|
|
|
message(WARNING "C++ compiler is not clang++, linting with be disabled.")
|
2020-04-17 08:40:36 +08:00
|
|
|
else()
|
2022-02-08 00:46:09 +08:00
|
|
|
if (NOT LLVM_LIBC_CLANG_TIDY)
|
|
|
|
find_program(LLVM_LIBC_CLANG_TIDY NAMES clang-tidy)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(LLVM_LIBC_CLANG_TIDY)
|
|
|
|
# Check clang-tidy major version.
|
|
|
|
execute_process(COMMAND ${LLVM_LIBC_CLANG_TIDY} "--version"
|
|
|
|
OUTPUT_VARIABLE CLANG_TIDY_OUTPUT)
|
|
|
|
string(REGEX MATCH "[0-9]+" CLANG_TIDY_VERSION "${CLANG_TIDY_OUTPUT}")
|
|
|
|
string(REGEX MATCH "[0-9]+" CLANG_MAJOR_VERSION
|
|
|
|
"${CMAKE_CXX_COMPILER_VERSION}")
|
|
|
|
if(NOT CLANG_TIDY_VERSION EQUAL CLANG_MAJOR_VERSION)
|
|
|
|
set(LLVM_LIBC_ENABLE_LINTING OFF)
|
|
|
|
message(WARNING "
|
|
|
|
'clang-tidy' (version ${CLANG_TIDY_VERSION}) is not the same as
|
|
|
|
'clang' (version ${CLANG_MAJOR_VERSION}). Linting will
|
|
|
|
be disabled.
|
|
|
|
|
|
|
|
The path to the clang-tidy binary can be set manually by passing
|
|
|
|
-DLLVM_LIBC_CLANG_TIDY=<path/to/clang-tidy> to CMake.")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "
|
|
|
|
Linting is enabled but 'clang-tidy' is not found!
|
|
|
|
|
|
|
|
The path to the clang-tidy binary can be set manually by passing
|
|
|
|
-DLLVM_LIBC_CLANG_TIDY=<path/to/clang-tidy> to CMake.
|
|
|
|
|
|
|
|
To disable linting set LLVM_LIBC_ENABLE_LINTING to OFF
|
|
|
|
(pass -DLLVM_LIBC_ENABLE_LINTING=OFF to cmake).")
|
|
|
|
endif()
|
2020-04-17 08:40:36 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-07-22 06:17:15 +08:00
|
|
|
option(LLVM_LIBC_INCLUDE_SCUDO "Include the SCUDO standalone as the allocator for LLVM libc" OFF)
|
|
|
|
if(LLVM_LIBC_INCLUDE_SCUDO)
|
|
|
|
if (NOT "compiler-rt" IN_LIST LLVM_ENABLE_PROJECTS)
|
|
|
|
message(FATAL_ERROR "SCUDO cannot be included without adding compiler-rt to LLVM_ENABLE_PROJECTS")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2022-01-29 08:27:34 +08:00
|
|
|
option(LIBC_INCLUDE_DOCS "Build the libc documentation." ${LLVM_INCLUDE_DOCS})
|
|
|
|
|
2019-10-05 01:30:54 +08:00
|
|
|
include(CMakeParseArguments)
|
[libc] Adding memcpy implementation for x86_64
Summary:
The patch is not ready yet and is here to discuss a few options:
- How do we customize the implementation? (i.e. how to define `kRepMovsBSize`),
- How do we specify custom compilation flags? (We'd need `-fno-builtin-memcpy` to be passed in),
- How do we build? We may want to test in debug but build the libc with `-march=native` for instance,
- Clang has a brand new builtin `__builtin_memcpy_inline` which makes the implementation easy and efficient, but:
- If we compile with `gcc` or `msvc` we can't use it, resorting on less efficient code generation,
- With gcc we can use `__builtin_memcpy` but then we'd need a postprocess step to check that the final assembly do not contain call to `memcpy` (unlikely but allowed),
- For msvc we'd need to resort on the compiler optimization passes.
Reviewers: sivachandra, abrachet
Subscribers: mgorny, MaskRay, tschuett, libc-commits, courbet
Tags: #libc-project
Differential Revision: https://reviews.llvm.org/D74397
2020-02-11 20:37:02 +08:00
|
|
|
include(LLVMLibCCheckCpuFeatures)
|
[libc] Implement FLAGS option for generating all combinations for targets.
Add FLAGS option for add_header_library, add_object_library,
add_entrypoint_object, and add_libc_unittest.
In general, a flag is a string provided for supported functions under the
multi-valued option `FLAGS`. It should be one of the following forms:
FLAG_NAME
FLAG_NAME__NO
FLAG_NAME__ONLY
A target will inherit all the flags of its upstream dependency.
When we create a target `TARGET_NAME` with a flag using (add_header_library,
add_object_library, ...), its behavior will depend on the flag form as follow:
- FLAG_NAME: The following 2 targets will be generated:
`TARGET_NAME` that has `FLAG_NAME` in its `FLAGS` property.
`TARGET_NAME.__NO_FLAG_NAME` that depends on `DEP.__NO_FLAG_NAME` if
`TARGET_NAME` depends on `DEP` and `DEP` has `FLAG_NAME` in its `FLAGS`
property.
- FLAG_NAME__ONLY: Only generate 1 target `TARGET_NAME` that has `FLAG_NAME`
in its `FLAGS` property.
- FLAG_NAME__NO: Only generate 1 target `TARGET_NAME.__NO_FLAG_NAME` that
depends on `DEP.__NO_FLAG_NAME` if `DEP` is in its DEPENDS list and `DEP`
has `FLAG_NAME` in its `FLAGS` property.
To show all the targets generated, pass SHOW_INTERMEDIATE_OBJECTS=ON to cmake.
To show all the targets' dependency and flags, pass
`SHOW_INTERMEDIATE_OBJECTS=DEPS` to cmake.
To completely disable a flag FLAG_NAME expansion, set the variable
`SKIP_FLAG_EXPANSION_FLAG_NAME=TRUE`.
Reviewed By: michaelrj, sivachandra
Differential Revision: https://reviews.llvm.org/D125174
2022-05-09 01:45:40 +08:00
|
|
|
include(LLVMLibCRules)
|
2019-10-05 01:30:54 +08:00
|
|
|
|
2021-06-30 04:27:28 +08:00
|
|
|
if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt")
|
|
|
|
set(entrypoint_file "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt")
|
|
|
|
elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/entrypoints.txt")
|
|
|
|
set(entrypoint_file "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/entrypoints.txt")
|
|
|
|
else()
|
2022-01-20 02:34:03 +08:00
|
|
|
message(FATAL_ERROR "entrypoints.txt file for the target platform '${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}' not found.")
|
2021-06-30 04:27:28 +08:00
|
|
|
endif()
|
|
|
|
include(${entrypoint_file})
|
|
|
|
|
|
|
|
if(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt")
|
|
|
|
include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt")
|
|
|
|
elseif(EXISTS "${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/headers.txt")
|
2021-10-26 04:26:20 +08:00
|
|
|
include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/headers.txt")
|
2021-06-30 04:27:28 +08:00
|
|
|
endif()
|
2020-06-09 15:31:48 +08:00
|
|
|
|
|
|
|
set(TARGET_ENTRYPOINT_NAME_LIST "")
|
2021-02-24 13:19:05 +08:00
|
|
|
foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
|
2020-06-09 15:31:48 +08:00
|
|
|
string(FIND ${entrypoint} "." last_dot_loc REVERSE)
|
|
|
|
if(${last_dot_loc} EQUAL -1)
|
|
|
|
message(FATAL "Invalid entrypoint target name ${entrypoint}; Expected a '.' "
|
|
|
|
"(dot) in the name.")
|
|
|
|
endif()
|
|
|
|
math(EXPR name_loc "${last_dot_loc} + 1")
|
|
|
|
string(SUBSTRING ${entrypoint} ${name_loc} -1 entrypoint_name)
|
|
|
|
list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name})
|
|
|
|
endforeach()
|
|
|
|
|
2021-03-12 07:25:24 +08:00
|
|
|
if(LLVM_LIBC_FULL_BUILD)
|
|
|
|
# We need to set up hdrgen first since other targets depend on it.
|
|
|
|
add_subdirectory(utils/LibcTableGenUtil)
|
|
|
|
add_subdirectory(utils/HdrGen)
|
|
|
|
endif()
|
2021-01-22 14:55:12 +08:00
|
|
|
|
2022-08-17 04:27:31 +08:00
|
|
|
set(LIBC_TARGET)
|
|
|
|
set(LIBC_COMPONENT)
|
|
|
|
set(LIBC_INSTALL_DEPENDS)
|
|
|
|
set(LIBC_INSTALL_TARGET)
|
|
|
|
if(LLVM_LIBC_FULL_BUILD)
|
|
|
|
set(LIBC_TARGET c)
|
|
|
|
set(LIBC_COMPONENT libc)
|
|
|
|
set(LIBC_INSTALL_DEPENDS "c;libc-headers")
|
|
|
|
set(LIBC_INSTALL_TARGET install-libc)
|
|
|
|
else()
|
|
|
|
set(LIBC_TARGET llvmlibc)
|
|
|
|
set(LIBC_COMPONENT llvmlibc)
|
|
|
|
set(LIBC_INSTALL_DEPENDS llvmlibc)
|
|
|
|
set(LIBC_INSTALL_TARGET install-llvmlibc)
|
|
|
|
endif()
|
|
|
|
|
2020-10-13 01:03:19 +08:00
|
|
|
add_subdirectory(include)
|
|
|
|
add_subdirectory(config)
|
2020-03-05 07:45:51 +08:00
|
|
|
add_subdirectory(src)
|
2019-11-06 03:40:26 +08:00
|
|
|
add_subdirectory(utils)
|
2020-01-04 04:00:45 +08:00
|
|
|
|
2021-03-12 07:25:24 +08:00
|
|
|
if(LLVM_LIBC_FULL_BUILD)
|
|
|
|
# The loader can potentially depend on the library components so add it
|
|
|
|
# after the library implementation directories.
|
|
|
|
add_subdirectory(loader)
|
|
|
|
endif()
|
2020-03-19 03:46:33 +08:00
|
|
|
|
2020-01-04 04:00:45 +08:00
|
|
|
# The lib and test directories are added at the very end as tests
|
|
|
|
# and libraries potentially draw from the components present in all
|
|
|
|
# of the other directories.
|
|
|
|
add_subdirectory(lib)
|
2020-03-23 13:50:16 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
|
|
|
add_subdirectory(test)
|
|
|
|
add_subdirectory(fuzzing)
|
|
|
|
endif()
|
2020-06-16 04:54:53 +08:00
|
|
|
|
2022-03-25 21:21:20 +08:00
|
|
|
if(LIBC_INCLUDE_BENCHMARKS)
|
|
|
|
add_subdirectory(benchmarks)
|
|
|
|
endif()
|
2022-01-29 08:27:34 +08:00
|
|
|
|
|
|
|
if (LIBC_INCLUDE_DOCS)
|
|
|
|
add_subdirectory(docs)
|
|
|
|
endif()
|
2022-08-17 04:27:31 +08:00
|
|
|
|
|
|
|
add_llvm_install_targets(
|
|
|
|
${LIBC_INSTALL_TARGET}
|
|
|
|
DEPENDS ${LIBC_INSTALL_DEPENDS}
|
|
|
|
COMPONENT ${LIBC_COMPONENT}
|
|
|
|
)
|