From ce212c911c8634fb9ccd9944b00dcd6c2b28d516 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 30 Oct 2018 09:24:39 -0700 Subject: Add a cmake option to static-link winpthread --- CMakeLists.txt | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d483aa0a..076291e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,17 +345,19 @@ int main() }" HAVE_STATIC_LIBGCC_SWITCH ) - if(HAVE_STATIC_LIBGCC_SWITCH) - SET(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc) - endif() set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES}) unset(OLD_REQUIRED_LIBRARIES) + + if(NOT HAVE_STATIC_LIBGCC_SWITCH) + message(FATAL_ERROR "Cannot static link libgcc") + endif() + set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc) endif() - option(ALSOFT_STATIC_STDCXX "Static link libstdc++ with -static-libstdc++" OFF) + option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF) if(ALSOFT_STATIC_STDCXX) set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libstdc++) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state") check_cxx_source_compiles( "#include int main() @@ -364,11 +366,36 @@ int main() }" HAVE_STATIC_LIBSTDCXX_SWITCH ) - if(HAVE_STATIC_LIBSTDCXX_SWITCH) - SET(LINKER_FLAGS ${LINKER_FLAGS} -static-libstdc++) - endif() set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES}) unset(OLD_REQUIRED_LIBRARIES) + + if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH) + message(FATAL_ERROR "Cannot static link libstdc++") + endif() + set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state") + endif() + + if(WIN32) + option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF) + if(ALSOFT_STATIC_WINPTHREAD) + set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state") + check_cxx_source_compiles( +"#include +int main() +{ + return 0; +}" + HAVE_STATIC_LIBWINPTHREAD_SWITCH + ) + set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES}) + unset(OLD_REQUIRED_LIBRARIES) + + if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH) + message(FATAL_ERROR "Cannot static link libwinpthread") + endif() + set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state") + endif() endif() ENDIF() @@ -1437,7 +1464,7 @@ ELSE() TARGET_COMPILE_DEFINITIONS(OpenAL PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS}) TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS} $<$:${CXX_FLAGS}>) - TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${LINKER_FLAGS} ${COMMON_LIB}) + TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${COMMON_LIB} ${LINKER_FLAGS}) SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME}) IF(TARGET build_version) @@ -1464,7 +1491,7 @@ TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET} PRIVATE "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc" ${INC_PATHS}) TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS} $<$:${CXX_FLAGS}>) TARGET_LINK_LIBRARIES(${IMPL_TARGET} - PRIVATE ${LINKER_FLAGS} ${COMMON_LIB} ${EXTRA_LIBS} ${MATH_LIB}) + PRIVATE ${COMMON_LIB} ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB}) IF(TARGET build_version) ADD_DEPENDENCIES(${IMPL_TARGET} build_version) ENDIF() -- cgit v1.2.3