Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix broken static builds #1290

Merged
merged 8 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmake/FindOpus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ endif()

if(OPUS_LIBRARIES)
if(OPUS_USE_STATIC_LIBS)
find_library(LIBM NAMES "libm.a" "libm.tbd")
# on linux with glibc you CANT statically link libm without statically linking all of glibc. DONT DO IT.
#find_library(LIBM NAMES "libm.a" "libm.tbd")
else()
find_library(LIBM NAMES m)
endif()
Expand Down
1 change: 1 addition & 0 deletions include/dpp/isa/fallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
************************************************************************************/
#pragma once

#include <dpp/export.h>
#include <numeric>
#include <cstdint>
#include <limits>
Expand Down
98 changes: 68 additions & 30 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ STRING(REPLACE "AVX" "" AVX_TYPE ${AVX_TYPE})
add_compile_definitions(AVX_TYPE=${AVX_TYPE})
add_compile_options(${AVX_FLAG})

if(NOT BUILD_SHARED_LIBS)
if(UNIX)
message("-- Building ${Green}static${ColourReset} library.")

if(UNIX AND NOT APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
message("-- INFO: Changed lib suffix to ${CMAKE_FIND_LIBRARY_SUFFIXES}")
endif()

set(OPENSSL_USE_STATIC_LIBS TRUE)
set(OPUS_USE_STATIC_LIBS TRUE)

else()
message(WARNING "-- Building of static library not supported on non UNIX systems.")
endif()
else()
message("-- Building ${Green}dynamic${ColourReset} library.")
endif()



if(WIN32 AND NOT MINGW)
# Fake an ssl version number to satisfy MLSPP
set(OPENSSL_VERSION "1.1.1f")
Expand Down Expand Up @@ -109,21 +130,6 @@ if (UNIX)
endif()
endif()

if(NOT BUILD_SHARED_LIBS)
if(UNIX)
message("-- Building static library.")

if(UNIX AND NOT APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()

set(OPENSSL_USE_STATIC_LIBS ON)
set(OPUS_USE_STATIC_LIBS TRUE)
else()
message(WARNING "-- Building of static library not supported on non UNIX systems.")
endif()
endif()

if (BUILD_VOICE_SUPPORT)
if (MINGW OR NOT WIN32)
include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/FindOpus.cmake")
Expand Down Expand Up @@ -151,6 +157,7 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if(MINGW OR NOT WIN32)
find_package(ZLIB REQUIRED)
message("-- ZLIB: ${Green}${ZLIB_LIBRARIES}${ColourReset}")
endif(MINGW OR NOT WIN32)

if(APPLE)
Expand All @@ -162,6 +169,9 @@ if(APPLE)
find_package(OpenSSL REQUIRED)
else()
if(MINGW OR NOT WIN32)
if(NOT BUILD_SHARED_LIBS)
set(OPENSSL_USE_STATIC_LIBS TRUE)
endif()
find_package(OpenSSL REQUIRED)
endif()
endif()
Expand Down Expand Up @@ -274,23 +284,35 @@ foreach (fullmodname ${subdirlist})
endif ()
endif()

if (HAVE_VOICE)
# Private statically linked dependencies
target_link_libraries(${modname} PRIVATE
mlspp
mls_vectors
bytes
tls_syntax
hpke
)
endif()

if (HAVE_VOICE)
target_link_libraries(${modname} PUBLIC ${OPUS_LIBRARIES})
include_directories(${OPUS_INCLUDE_DIRS})
endif()
endforeach()

if (HAVE_VOICE)
# Private statically linked dependencies
if(NOT BUILD_SHARED_LIBS AND NOT APPLE)
target_link_libraries(dpp PRIVATE
mlspp.a
mls_vectors.a
bytes.a
tls_syntax.a
hpke.a
)
message("-- INFO: Linking static dependencies")
else()
target_link_libraries(dpp PRIVATE
mlspp
mls_vectors
bytes
tls_syntax
hpke
)
message("-- INFO: Linking dynamic dependencies")
endif()
endif()

target_compile_features(dpp PUBLIC cxx_std_17)
target_compile_features(dpp PRIVATE cxx_constexpr)
target_compile_features(dpp PRIVATE cxx_auto_type)
Expand Down Expand Up @@ -367,6 +389,22 @@ if(DPP_FORMATTERS)
target_compile_definitions(dpp PUBLIC DPP_FORMATTERS)
endif()

if (NOT BUILD_SHARED_LIBS)
add_library(dppstatic STATIC
$<TARGET_OBJECTS:dpp>
$<TARGET_OBJECTS:hpke>
$<TARGET_OBJECTS:tls_syntax>
$<TARGET_OBJECTS:mls_vectors>
$<TARGET_OBJECTS:mlspp>
$<TARGET_OBJECTS:bytes>
)
if (HAVE_VOICE)
target_link_libraries(dppstatic ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} ${OPUS_LIBRARIES} -static-libgcc -static-libstdc++)
else()
target_link_libraries(dppstatic ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES})
endif()
endif()

if (DPP_BUILD_TEST)
enable_testing(${CMAKE_CURRENT_SOURCE_DIR}/..)
file(GLOB testnamelist "${CMAKE_CURRENT_SOURCE_DIR}/../src/*")
Expand All @@ -385,11 +423,11 @@ if (DPP_BUILD_TEST)
if (MSVC)
target_compile_options(${testname} PRIVATE /utf-8)
endif()
set (static_if_needed "")
if(NOT BUILD_SHARED_LIBS)
set (static_if_needed "-static")
if(BUILD_SHARED_LIBS)
target_link_libraries(${testname} PUBLIC ${modname})
else()
target_link_libraries(${testname} PUBLIC dppstatic)
endif()
target_link_libraries(${testname} PUBLIC ${modname} ${static_if_needed})
endif()
endforeach()
add_test(
Expand Down
Loading