Skip to content

Commit

Permalink
cmake: add RE_LIBS config and add atomic check (#1029)
Browse files Browse the repository at this point in the history
* cmake: add RE_LIBS config and add atomic check

* test c11 flag

* replace with c++ atomic check

* ci/musl: add g++

* fix cxx_source
  • Loading branch information
sreimers authored Dec 23, 2023
1 parent 1d23051 commit cf425b3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/musl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v3
- name: install devel tools
run: |
apk add musl-dev git cmake gcc make binutils openssl-dev linux-headers zlib-dev ninja
apk add musl-dev git cmake gcc g++ make binutils openssl-dev linux-headers zlib-dev ninja
- name: make
run: |
Expand Down
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
76 changes: 76 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(CheckCXXSourceCompiles)

option(USE_MBEDTLS "Enable MbedTLS" OFF)

Expand Down Expand Up @@ -214,3 +215,78 @@ 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
#

enable_language(CXX)

set(ATOMIC_TEST_CODE "
#include <atomic>
#include <cstdint>
std::atomic<uint8_t> n8 (0); // riscv64
std::atomic<uint64_t> n64 (0); // armel, mipsel, powerpc
int main() {
++n8;
++n64;
return 0;
}")

check_cxx_source_compiles("${ATOMIC_TEST_CODE}" atomic_test)

if(NOT atomic_test)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} atomic)
check_cxx_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 cf425b3

Please sign in to comment.