diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -22,6 +22,9 @@ # Defines LIBC_TARGET_ARCHITECTURE and associated macros. include(LLVMLibCArchitectures) +# 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=...)") + # Check --print-resource-dir to find the compiler resource dir if this flag # is supported by the compiler. execute_process( diff --git a/libc/cmake/modules/LLVMLibCLibraryRules.cmake b/libc/cmake/modules/LLVMLibCLibraryRules.cmake --- a/libc/cmake/modules/LLVMLibCLibraryRules.cmake +++ b/libc/cmake/modules/LLVMLibCLibraryRules.cmake @@ -81,10 +81,8 @@ STATIC ${objects} ) - set_target_properties( - ${target_name} - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + set_target_properties(${target_name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + target_compile_options(${target_name} PRIVATE ${LIBC_COMPILE_OPTIONS_DEFAULT} ) endfunction(add_entrypoint_library) @@ -112,18 +110,10 @@ SHARED ${obj_files} ) - set_target_properties(${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - - target_link_libraries( - ${target_name} - -nostdlib -lc -lm - ) - - set_target_properties( - ${target_name} - PROPERTIES - LINKER_LANGUAGE "C" - ) + set_target_properties(${target_name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + target_link_libraries(${target_name} -nostdlib -lc -lm) + set_target_properties(${target_name} PROPERTIES LINKER_LANGUAGE "C") + target_compile_options(${target_name} PRIVATE ${LIBC_COMPILE_OPTIONS_DEFAULT}) endfunction(add_redirector_library) set(HDR_LIBRARY_TARGET_TYPE "HDR_LIBRARY") diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake --- a/libc/cmake/modules/LLVMLibCObjectRules.cmake +++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake @@ -37,6 +37,10 @@ ${LIBC_SOURCE_DIR} ${LIBC_BUILD_DIR} ) + target_compile_options( + ${fq_target_name} + PRIVATE ${LIBC_COMPILE_OPTIONS_DEFAULT} + ) if(ADD_OBJECT_COMPILE_OPTIONS) target_compile_options( ${fq_target_name} @@ -148,7 +152,7 @@ message(FATAL_ERROR "`add_entrypoint_object` rule requires HDRS to be specified.") endif() - set(common_compile_options -fpie ${LLVM_CXX_STD_default} -ffreestanding ${ADD_ENTRYPOINT_OBJ_COMPILE_OPTIONS}) + set(common_compile_options -fpie ${LLVM_CXX_STD_default} -ffreestanding ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ADD_ENTRYPOINT_OBJ_COMPILE_OPTIONS}) set(internal_target_name ${fq_target_name}.__internal__) set(include_dirs ${LIBC_BUILD_DIR}/include ${LIBC_SOURCE_DIR} ${LIBC_BUILD_DIR}) get_fq_deps_list(fq_deps_list ${ADD_ENTRYPOINT_OBJ_DEPENDS}) @@ -277,6 +281,6 @@ ) target_compile_options( ${target_name} - BEFORE PRIVATE -fPIC + BEFORE PRIVATE -fPIC ${LIBC_COMPILE_OPTIONS_DEFAULT} ) endfunction(add_redirector_object) diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -127,6 +127,10 @@ ${LIBC_BUILD_DIR} ${LIBC_BUILD_DIR}/include ) + target_compile_options( + ${fq_target_name} + PRIVATE ${LIBC_COMPILE_OPTIONS_DEFAULT} + ) if(LIBC_UNITTEST_COMPILE_OPTIONS) target_compile_options( ${fq_target_name}