Skip to content

Commit

Permalink
cmake: add RE_LIBS config and add atomic check
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Dec 18, 2023
1 parent f708648 commit 2f9f030
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 46 deletions.
48 changes: 2 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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_OBJECTS:re-objs>)
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})
Expand All @@ -692,7 +648,7 @@ endif()
if(LIBRE_BUILD_STATIC)
list(APPEND RE_INSTALL_TARGETS re)
add_library(re STATIC $<TARGET_OBJECTS:re-objs>)
target_link_libraries(re PUBLIC ${LINKLIBS})
target_link_libraries(re PUBLIC ${RE_LIBS})
target_include_directories(re PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
Expand Down
73 changes: 73 additions & 0 deletions cmake/re-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include(CheckIncludeFile)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckTypeSize)
include(CheckCSourceCompiles)

option(USE_MBEDTLS "Enable MbedTLS" OFF)

Expand Down Expand Up @@ -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 <stdatomic.h>
#include <stdint.h>
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()

0 comments on commit 2f9f030

Please sign in to comment.