1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00

Fix static linking on macOS

This commit is contained in:
Michael 2019-08-17 12:33:07 +01:00
parent 2a09d4914a
commit 429284aedc
No known key found for this signature in database
GPG key ID: 2D51757B47E2434C
2 changed files with 41 additions and 29 deletions

View file

@ -164,35 +164,7 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
# not supported on Solaris - system libraries are not available as archives
# LTO is supported only for native builds
if(STATIC_LINK_RUNTIME)
if (NOT SOLARIS)
if(NOT CMAKE_CROSSCOMPILING)
add_compile_options(-static -flto)
else()
add_compile_options(-static)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
link_libraries( -static -static-libstdc++ -pthread -flto )
elseif(NOT CMAKE_CROSSCOMPILING)
# this is messing with release builds
add_compile_options(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0)
set(CMAKE_AR "gcc-ar")
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "true")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_FINISH "true")
link_libraries( -flto -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive )
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive" )
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
endif()
else()
link_libraries( -static-libstdc++ -static-libgcc )
endif()
endif(STATIC_LINK_RUNTIME)
include(cmake/static_link.cmake)
if(USE_NETNS)
add_definitions(-DNETNS=1)

40
cmake/static_link.cmake Normal file
View file

@ -0,0 +1,40 @@
if(NOT STATIC_LINK_RUNTIME)
return()
endif()
# not supported on Solaris - system libraries are not available as archives
# LTO is supported only for native builds
if(SOLARIS)
link_libraries( -static-libstdc++ -static-libgcc )
return()
endif()
if(NOT CMAKE_CROSSCOMPILING)
add_compile_options(-static -flto)
else()
add_compile_options(-static)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(APPLE)
link_libraries( -flto)
else()
link_libraries( -static -static-libstdc++ -pthread -flto )
endif()
return()
endif()
if(NOT CMAKE_CROSSCOMPILING)
# this is messing with release builds
add_compile_options(-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0)
set(CMAKE_AR "gcc-ar")
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "true")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_FINISH "true")
link_libraries( -flto -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive )
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive" )
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
endif()