From 2f9f0301c89abbf5171b2da560cf372f566dcfa7 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Mon, 18 Dec 2023 09:25:31 +0100 Subject: [PATCH] cmake: add RE_LIBS config and add atomic check --- CMakeLists.txt | 48 ++-------------------------- cmake/re-config.cmake | 73 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dca56d73..c6c6a392b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -607,50 +607,6 @@ if(USE_REM) endif() -############################################################################## -# -# Linking LIBS -# - -set(LINKLIBS Threads::Threads ${RESOLV_LIBRARY}) - -if(BACKTRACE_FOUND) - list(APPEND LINKLIBS ${Backtrace_LIBRARIES}) -endif() - -if(ZLIB_FOUND) - list(APPEND LINKLIBS ZLIB::ZLIB) -endif() - -if(USE_OPENSSL) - list(APPEND LINKLIBS OpenSSL::SSL OpenSSL::Crypto) -endif() - -if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - list(APPEND LINKLIBS - "-framework SystemConfiguration" "-framework CoreFoundation" - ) -endif() - -if(WIN32) - list(APPEND LINKLIBS - qwave - iphlpapi - wsock32 - ws2_32 - dbghelp - ) -else() - list(APPEND LINKLIBS m) -endif() - -if(UNIX) - list(APPEND LINKLIBS - ${CMAKE_DL_LIBS} - ) -endif() - - ############################################################################## # # Main target object @@ -675,7 +631,7 @@ target_include_directories(re-objs PRIVATE if(LIBRE_BUILD_SHARED) list(APPEND RE_INSTALL_TARGETS re-shared) add_library(re-shared SHARED $) - target_link_libraries(re-shared PRIVATE ${LINKLIBS}) + target_link_libraries(re-shared PRIVATE ${RE_LIBS}) set_target_properties(re-shared PROPERTIES VERSION ${PROJECT_SOVERSION}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) set_target_properties(re-shared PROPERTIES SOVERSION ${PROJECT_SOVERSION}) @@ -692,7 +648,7 @@ endif() if(LIBRE_BUILD_STATIC) list(APPEND RE_INSTALL_TARGETS re) add_library(re STATIC $) - target_link_libraries(re PUBLIC ${LINKLIBS}) + target_link_libraries(re PUBLIC ${RE_LIBS}) target_include_directories(re PUBLIC $ ) diff --git a/cmake/re-config.cmake b/cmake/re-config.cmake index 6dc0ad8b6..b9c09a84d 100644 --- a/cmake/re-config.cmake +++ b/cmake/re-config.cmake @@ -2,6 +2,7 @@ include(CheckIncludeFile) include(CheckFunctionExists) include(CheckSymbolExists) include(CheckTypeSize) +include(CheckCSourceCompiles) option(USE_MBEDTLS "Enable MbedTLS" OFF) @@ -214,3 +215,75 @@ if(NOT ${CMAKE_BUILD_TYPE} MATCHES "[Rr]el") set(CMAKE_ENABLE_EXPORTS ON) endif() endif() + + +############################################################################## +# +# Linking LIBS +# + +set(RE_LIBS Threads::Threads ${RESOLV_LIBRARY}) + +if(BACKTRACE_FOUND) + list(APPEND RE_LIBS ${Backtrace_LIBRARIES}) +endif() + +if(ZLIB_FOUND) + list(APPEND RE_LIBS ZLIB::ZLIB) +endif() + +if(USE_OPENSSL) + list(APPEND RE_LIBS OpenSSL::SSL OpenSSL::Crypto) +endif() + +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + list(APPEND RE_LIBS + "-framework SystemConfiguration" "-framework CoreFoundation" + ) +endif() + +if(WIN32) + list(APPEND RE_LIBS + qwave + iphlpapi + wsock32 + ws2_32 + dbghelp + ) +else() + list(APPEND RE_LIBS m) +endif() + +if(UNIX) + list(APPEND RE_LIBS + ${CMAKE_DL_LIBS} + ) +endif() + + +############################################################################## +# +# Testing Atomic +# + +set(ATOMIC_TEST_CODE " + #include + #include + int main() { + atomic_int_least64_t x; + atomic_store(&x, 1); + x--; + return atomic_load(&x); + }") + +check_c_source_compiles("${ATOMIC_TEST_CODE}" atomic_test) + +if(NOT atomic_test) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} atomic) + check_c_source_compiles("${ATOMIC_TEST_CODE}" atomic_test_lib) + if(NOT atomic_test_lib) + message(FATAL_ERROR "No builtin or libatomic support") + else() + list(APPEND RE_LIBS atomic) + endif() +endif()