2020-04-09 20:41:22 -07:00
|
|
|
cmake_minimum_required(VERSION 3.13.4)
|
2019-10-04 17:30:54 +00:00
|
|
|
|
2020-01-26 21: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)
|
2019-10-04 17:30:54 +00:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
|
|
|
|
|
|
|
|
# The top-level source directory of libc.
|
|
|
|
set(LIBC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
set(LIBC_TARGET_MACHINE ${CMAKE_SYSTEM_PROCESSOR})
|
|
|
|
|
2020-05-21 17:39:03 -07: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-28 14:52:39 -07:00
|
|
|
message(STATUS "Set COMPILER_RESOURCE_DIR to "
|
|
|
|
"${COMPILER_RESOURCE_DIR} using --print-resource-dir")
|
2020-05-21 17:39:03 -07:00
|
|
|
else()
|
|
|
|
set(COMPILER_RESOURCE_DIR OFF)
|
|
|
|
message(STATUS "COMPILER_RESOURCE_DIR not set
|
|
|
|
--print-resource-dir not supported by host compiler")
|
|
|
|
endif()
|
|
|
|
|
2020-04-16 17:40:36 -07:00
|
|
|
option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" ON)
|
|
|
|
if(LLVM_LIBC_ENABLE_LINTING)
|
|
|
|
if("clang-tools-extra" IN_LIST LLVM_ENABLE_PROJECTS
|
|
|
|
AND "clang" IN_LIST LLVM_ENABLE_PROJECTS)
|
|
|
|
add_custom_target(lint-libc)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "
|
2020-05-21 03:07:52 +00:00
|
|
|
'clang' and 'clang-tools-extra' are required in LLVM_ENABLE_PROJECTS to
|
2020-04-16 17:40:36 -07:00
|
|
|
lint llvm-libc. The linting step performs important checks to help prevent
|
|
|
|
the introduction of subtle bugs, but it may increase build times.
|
|
|
|
|
|
|
|
To disable linting set LLVM_LIBC_ENABLE_LINTING to OFF
|
|
|
|
(pass -DLLVM_LIBC_ENABLE_LINTING=OFF to cmake).")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(WARNING "
|
|
|
|
Linting for libc is currently disabled.
|
|
|
|
|
|
|
|
This is not recommended, to enable set LLVM_LIBC_ENABLE_LINTING to ON
|
|
|
|
(pass -DLLVM_LIBC_ENABLE_LINTING=ON to cmake).")
|
|
|
|
endif()
|
|
|
|
|
2019-10-04 17:30:54 +00:00
|
|
|
include(CMakeParseArguments)
|
|
|
|
include(LLVMLibCRules)
|
[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 13:37:02 +01:00
|
|
|
include(LLVMLibCCheckCpuFeatures)
|
2019-10-04 17:30:54 +00:00
|
|
|
|
2019-12-04 23:17:14 -08:00
|
|
|
add_subdirectory(include)
|
2020-03-04 15:45:51 -08:00
|
|
|
add_subdirectory(config)
|
|
|
|
add_subdirectory(src)
|
2019-11-05 11:40:26 -08:00
|
|
|
add_subdirectory(utils)
|
2020-01-03 12:00:45 -08:00
|
|
|
|
2020-03-18 12:46:33 -07:00
|
|
|
# The loader can potentially depend on the library components so add it
|
|
|
|
# after the library implementation directories.
|
|
|
|
add_subdirectory(loader)
|
|
|
|
|
2020-01-03 12: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 01:50:16 -04:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
|
|
|
add_subdirectory(test)
|
|
|
|
add_subdirectory(fuzzing)
|
|
|
|
endif()
|