2019-08-28 20:49:37 +00:00
|
|
|
# Set standard, system and compiler libraries explicitly.
|
|
|
|
# This is intended for more control of what we are linking.
|
|
|
|
|
|
|
|
set (DEFAULT_LIBS "-nodefaultlibs")
|
|
|
|
|
2024-11-10 00:25:25 +00:00
|
|
|
# We need builtins from Clang
|
2024-08-13 08:30:31 +00:00
|
|
|
execute_process (COMMAND
|
|
|
|
${CMAKE_CXX_COMPILER} --target=${CMAKE_CXX_COMPILER_TARGET} --print-libgcc-file-name --rtlib=compiler-rt
|
|
|
|
OUTPUT_VARIABLE BUILTINS_LIBRARY
|
|
|
|
COMMAND_ERROR_IS_FATAL ANY
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2021-11-24 12:43:09 +00:00
|
|
|
|
2024-05-07 18:58:19 +00:00
|
|
|
# Apparently, in clang-19, the UBSan support library for C++ was moved out into ubsan_standalone_cxx.a, so we have to include both.
|
|
|
|
if (SANITIZE STREQUAL undefined)
|
|
|
|
string(REPLACE "builtins.a" "ubsan_standalone_cxx.a" EXTRA_BUILTINS_LIBRARY "${BUILTINS_LIBRARY}")
|
|
|
|
endif ()
|
2024-04-10 00:12:02 +00:00
|
|
|
|
2024-05-07 18:58:19 +00:00
|
|
|
if (NOT EXISTS "${BUILTINS_LIBRARY}")
|
|
|
|
set (BUILTINS_LIBRARY "-lgcc")
|
2019-08-28 20:49:37 +00:00
|
|
|
endif ()
|
|
|
|
|
2020-07-15 11:16:00 +00:00
|
|
|
if (OS_ANDROID)
|
2020-12-15 19:59:07 +00:00
|
|
|
# pthread and rt are included in libc
|
2024-04-10 00:12:02 +00:00
|
|
|
set (DEFAULT_LIBS "${DEFAULT_LIBS} ${BUILTINS_LIBRARY} ${EXTRA_BUILTINS_LIBRARY} ${COVERAGE_OPTION} -lc -lm -ldl")
|
2021-10-15 23:07:13 +00:00
|
|
|
elseif (USE_MUSL)
|
2024-04-10 00:12:02 +00:00
|
|
|
set (DEFAULT_LIBS "${DEFAULT_LIBS} ${BUILTINS_LIBRARY} ${EXTRA_BUILTINS_LIBRARY} ${COVERAGE_OPTION} -static -lc")
|
2020-07-15 11:16:00 +00:00
|
|
|
else ()
|
2024-04-10 00:12:02 +00:00
|
|
|
set (DEFAULT_LIBS "${DEFAULT_LIBS} ${BUILTINS_LIBRARY} ${EXTRA_BUILTINS_LIBRARY} ${COVERAGE_OPTION} -lc -lm -lrt -lpthread -ldl")
|
2020-07-15 11:16:00 +00:00
|
|
|
endif ()
|
2019-08-30 16:50:43 +00:00
|
|
|
|
|
|
|
message(STATUS "Default libraries: ${DEFAULT_LIBS}")
|
|
|
|
|
2019-08-28 20:49:37 +00:00
|
|
|
set(CMAKE_CXX_STANDARD_LIBRARIES ${DEFAULT_LIBS})
|
|
|
|
set(CMAKE_C_STANDARD_LIBRARIES ${DEFAULT_LIBS})
|
|
|
|
|
|
|
|
# Unfortunately '-pthread' doesn't work with '-nodefaultlibs'.
|
|
|
|
# Just make sure we have pthreads at all.
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
2022-11-15 16:53:24 +00:00
|
|
|
include (cmake/unwind.cmake)
|
|
|
|
include (cmake/cxx.cmake)
|
|
|
|
|
2020-07-15 11:16:00 +00:00
|
|
|
if (NOT OS_ANDROID)
|
2021-10-15 23:07:13 +00:00
|
|
|
if (NOT USE_MUSL)
|
|
|
|
# Our compatibility layer doesn't build under Android, many errors in musl.
|
|
|
|
add_subdirectory(base/glibc-compatibility)
|
|
|
|
endif ()
|
2020-10-26 01:54:35 +00:00
|
|
|
add_subdirectory(base/harmful)
|
2020-07-15 11:16:00 +00:00
|
|
|
endif ()
|
|
|
|
|
2023-08-23 17:46:19 +00:00
|
|
|
link_libraries(global-group)
|
|
|
|
|
2019-08-28 20:49:37 +00:00
|
|
|
target_link_libraries(global-group INTERFACE
|
|
|
|
-Wl,--start-group
|
|
|
|
$<TARGET_PROPERTY:global-libs,INTERFACE_LINK_LIBRARIES>
|
|
|
|
-Wl,--end-group
|
|
|
|
)
|