35 changes: 5 additions & 30 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ function(create_libc_unittest fq_target_name)
libc.test.UnitTest.ErrnoSetterMatcher)
list(REMOVE_DUPLICATES fq_deps_list)

_get_common_test_compile_options(compile_options "${LIBC_UNITTEST_FLAGS}")
list(APPEND compile_options ${LIBC_UNITTEST_COMPILE_OPTIONS})

if(SHOW_INTERMEDIATE_OBJECTS)
message(STATUS "Adding unit test ${fq_target_name}")
if(${SHOW_INTERMEDIATE_OBJECTS} STREQUAL "DEPS")
Expand Down Expand Up @@ -181,22 +184,8 @@ function(create_libc_unittest fq_target_name)
)
target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
target_compile_options(
${fq_build_target_name}
PRIVATE -fpie ${LIBC_COMPILE_OPTIONS_DEFAULT}
)
if(LLVM_LIBC_FULL_BUILD)
target_compile_options(
${fq_build_target_name}
PRIVATE -ffreestanding -fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables
)
endif()
if(LIBC_UNITTEST_COMPILE_OPTIONS)
target_compile_options(
${fq_build_target_name}
PRIVATE ${LIBC_UNITTEST_COMPILE_OPTIONS}
)
endif()
target_compile_options(${fq_build_target_name} PRIVATE ${compile_options})

if(NOT LIBC_UNITTEST_CXX_STANDARD)
set(LIBC_UNITTEST_CXX_STANDARD ${CMAKE_CXX_STANDARD})
endif()
Expand Down Expand Up @@ -530,20 +519,6 @@ function(add_integration_test test_name)
add_dependencies(${INTEGRATION_TEST_SUITE} ${fq_target_name})
endfunction(add_integration_test)

set(LIBC_HERMETIC_TEST_COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_DEFAULT}
-fpie -ffreestanding -fno-exceptions -fno-rtti)
# The GPU build requires overriding the default CMake triple and architecture.
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS
-nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
--target=${LIBC_GPU_TARGET_TRIPLE}
-mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE})
list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS
-nogpulib ${nvptx_options} -fno-use-cxa-atexit --target=${LIBC_GPU_TARGET_TRIPLE})
endif()

# Rule to add a hermetic test. A hermetic test is one whose executable is fully
# statically linked and consists of pieces drawn only from LLVM's libc. Nothing,
# including the startup objects, come from the system libc.
Expand Down
5 changes: 3 additions & 2 deletions libc/test/UnitTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ function(add_unittest_framework_library name)
${TEST_LIB_HDRS}
)
target_include_directories(${lib} PUBLIC ${LIBC_SOURCE_DIR})
target_compile_options(${lib} PRIVATE -fno-exceptions -fno-rtti)
list(APPEND compile_options -fno-exceptions -fno-rtti)
if(TARGET libc.src.time.clock)
target_compile_definitions(${lib} PRIVATE TARGET_SUPPORTS_CLOCK)
endif()
if(LIBC_COMPILER_HAS_FIXED_POINT)
target_compile_options(${lib} PUBLIC -ffixed-point)
list(APPEND compile_options -ffixed-point)
endif()
target_compile_options(${lib} PUBLIC ${compile_options})
endforeach()
target_include_directories(${name}.hermetic PRIVATE ${LIBC_BUILD_DIR}/include)
target_compile_options(${name}.hermetic
Expand Down