From 822575c6b15777da7c279596aa76ae9e8f392d73 Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Thu, 7 Aug 2025 19:06:36 +0300 Subject: feat(build): Add MUSL detection and conditional linking This commit introduces the ability to detect if the project is being built with the MUSL C library. A new variable `MUSL` is set to `ON` if MUSL is detected, and `OFF` otherwise. This is achieved by checking the output of `ldd --version`. The `accel-pppd/ctrl/pppoe/CMakeLists.txt` file is updated to conditionally link the `connlimit` library only when building with MUSL. Signed-off-by: Denys Fedoryshchenko --- CMakeLists.txt | 15 +++++++++++++++ accel-pppd/ctrl/pppoe/CMakeLists.txt | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b606898a..9a3ff73b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,21 @@ IF (NOT DEFINED LIB_SUFFIX) ENDIF (ARCH STREQUAL x86_64) ENDIF (NOT DEFINED LIB_SUFFIX) +# Set flag if we are building with MUSL +IF (CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_C_COMPILER_ID STREQUAL GNU) + execute_process( + COMMAND sh -c "ldd --version 2>&1 || true" + OUTPUT_VARIABLE LDD_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if (LDD_VERSION MATCHES "[Mm]usl") + set(MUSL ON) + else () + set(MUSL OFF) + endif () + message(STATUS "Building with MUSL: ${MUSL}") +ENDIF (CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_C_COMPILER_ID STREQUAL GNU) + #color console example message(FATAL_ERROR "${Esc}[31m Red Text ${Esc}[m Restore Normal Text") string(ASCII 27 Esc) diff --git a/accel-pppd/ctrl/pppoe/CMakeLists.txt b/accel-pppd/ctrl/pppoe/CMakeLists.txt index fd4f9a36..b6f4a98f 100644 --- a/accel-pppd/ctrl/pppoe/CMakeLists.txt +++ b/accel-pppd/ctrl/pppoe/CMakeLists.txt @@ -13,7 +13,12 @@ SET(sources ${sources} tr101.c) ENDIF(RADIUS) ADD_LIBRARY(pppoe SHARED ${sources}) -TARGET_LINK_LIBRARIES(pppoe vlan-mon connlimit) +# if MUSL is set then we need to link with the connlimit library +IF (MUSL) + TARGET_LINK_LIBRARIES(pppoe vlan-mon connlimit) +ELSE (MUSL) + TARGET_LINK_LIBRARIES(pppoe vlan-mon) +ENDIF (MUSL) set_property(TARGET pppoe PROPERTY CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set_property(TARGET pppoe PROPERTY INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/accel-ppp) -- cgit v1.2.3