From 2f9f0301c89abbf5171b2da560cf372f566dcfa7 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Mon, 18 Dec 2023 09:25:31 +0100 Subject: [PATCH 1/5] 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() From 3cd88088d9ffccef9d1524ed1789f2e15a2fbc1d Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Mon, 18 Dec 2023 09:53:34 +0100 Subject: [PATCH 2/5] test c11 flag --- cmake/re-config.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/re-config.cmake b/cmake/re-config.cmake index b9c09a84d..6c106f2e5 100644 --- a/cmake/re-config.cmake +++ b/cmake/re-config.cmake @@ -266,6 +266,10 @@ endif() # Testing Atomic # +if(NOT WIN32) + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -std=c11) +endif() + set(ATOMIC_TEST_CODE " #include #include From 73013d993443096288ca5ba1e1d0bac98661550b Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Mon, 18 Dec 2023 13:28:18 +0100 Subject: [PATCH 3/5] replace with c++ atomic check --- cmake/re-config.cmake | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/cmake/re-config.cmake b/cmake/re-config.cmake index 6c106f2e5..0b13e2c57 100644 --- a/cmake/re-config.cmake +++ b/cmake/re-config.cmake @@ -2,7 +2,7 @@ include(CheckIncludeFile) include(CheckFunctionExists) include(CheckSymbolExists) include(CheckTypeSize) -include(CheckCSourceCompiles) +include(CheckCXXSourceCompiles) option(USE_MBEDTLS "Enable MbedTLS" OFF) @@ -266,21 +266,20 @@ endif() # Testing Atomic # -if(NOT WIN32) - set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -std=c11) -endif() +enable_language(CXX) 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) + #include + #include + std::atomic n8 (0); // riscv64 + std::atomic 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) From cc33f883daa8bb82d04e37f626f346b06641d8f7 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Mon, 18 Dec 2023 13:29:41 +0100 Subject: [PATCH 4/5] ci/musl: add g++ --- .github/workflows/musl.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/musl.yml b/.github/workflows/musl.yml index 58eb63f96..b2e51f464 100644 --- a/.github/workflows/musl.yml +++ b/.github/workflows/musl.yml @@ -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: | From bfcd8101b015298c8b41832375fab3b0b80a81b5 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Thu, 21 Dec 2023 17:18:16 +0100 Subject: [PATCH 5/5] fix cxx_source --- cmake/re-config.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/re-config.cmake b/cmake/re-config.cmake index 0b13e2c57..68c0c80cd 100644 --- a/cmake/re-config.cmake +++ b/cmake/re-config.cmake @@ -283,7 +283,7 @@ check_cxx_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) + check_cxx_source_compiles("${ATOMIC_TEST_CODE}" atomic_test_lib) if(NOT atomic_test_lib) message(FATAL_ERROR "No builtin or libatomic support") else()