From 7259b5eb7ac291f00cc989a44c5fe4964759efaf Mon Sep 17 00:00:00 2001 From: Michel Zou Date: Fri, 30 Oct 2020 10:44:24 +0100 Subject: CMake: Add an option to opt-out static libgcc With sjlj exception model, statically link to libgcc/libstdc++ prevents exceptions to be caught from other dynamic libraries. --- CMakeLists.txt | 2 ++ c++/examples/CMakeLists.txt | 4 ++-- c++/src/CMakeLists.txt | 2 +- c++/test/CMakeLists.txt | 2 +- config/cmake/cacheinit.cmake | 2 ++ release_docs/INSTALL_CMake.txt | 1 + release_docs/RELEASE.txt | 7 +++++++ 7 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0eebad..dc2cf1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -578,6 +578,8 @@ if (WIN32 OR MINGW) add_compile_definitions (_BIND_TO_CURRENT_VCLIBS_VERSION=1 _CRT_SECURE_NO_WARNINGS _CONSOLE) endif () +option (HDF5_MINGW_STATIC_GCC_LIBS "Statically link libgcc/libstdc++" OFF) + if (MSVC) set (CMAKE_MFC_FLAG 0) set (WIN_COMPILE_FLAGS "") diff --git a/c++/examples/CMakeLists.txt b/c++/examples/CMakeLists.txt index 3035841..c50315f 100644 --- a/c++/examples/CMakeLists.txt +++ b/c++/examples/CMakeLists.txt @@ -41,7 +41,7 @@ foreach (example ${examples}) else () TARGET_C_PROPERTIES (cpp_ex_${example} SHARED) target_link_libraries (cpp_ex_${example} PRIVATE ${HDF5_CPP_LIBSH_TARGET} ${HDF5_LIBSH_TARGET}) - if (MINGW) + if (MINGW AND HDF5_MINGW_STATIC_GCC_LIBS) target_link_options (${HDF5_CPP_LIBSH_TARGET} PRIVATE -static-libgcc -static-libstdc++ ) @@ -66,7 +66,7 @@ foreach (example ${tutr_examples}) else () TARGET_C_PROPERTIES (cpp_ex_${example} SHARED) target_link_libraries (cpp_ex_${example} PRIVATE ${HDF5_CPP_LIBSH_TARGET} ${HDF5_LIBSH_TARGET}) - if (MINGW) + if (MINGW AND HDF5_MINGW_STATIC_GCC_LIBS) target_link_options (${HDF5_CPP_LIBSH_TARGET} PRIVATE -static-libgcc -static-libstdc++ ) diff --git a/c++/src/CMakeLists.txt b/c++/src/CMakeLists.txt index 04822cf..de2306e 100644 --- a/c++/src/CMakeLists.txt +++ b/c++/src/CMakeLists.txt @@ -117,7 +117,7 @@ if (BUILD_SHARED_LIBS) target_link_libraries (${HDF5_CPP_LIBSH_TARGET} PUBLIC ${HDF5_LIBSH_TARGET} ) - if (MINGW) + if (MINGW AND HDF5_MINGW_STATIC_GCC_LIBS) target_link_options (${HDF5_CPP_LIBSH_TARGET} PRIVATE -static-libgcc -static-libstdc++ ) diff --git a/c++/test/CMakeLists.txt b/c++/test/CMakeLists.txt index 550b7ea..1255e39 100644 --- a/c++/test/CMakeLists.txt +++ b/c++/test/CMakeLists.txt @@ -49,7 +49,7 @@ if (NOT BUILD_SHARED_LIBS) else () TARGET_C_PROPERTIES (cpp_testhdf5 SHARED) target_link_libraries (cpp_testhdf5 PRIVATE ${HDF5_CPP_LIBSH_TARGET} ${HDF5_LIBSH_TARGET} ${HDF5_TEST_LIBSH_TARGET}) - if (MINGW) + if (MINGW AND HDF5_MINGW_STATIC_GCC_LIBS) target_link_options (${HDF5_CPP_LIBSH_TARGET} PRIVATE -static-libgcc -static-libstdc++ ) diff --git a/config/cmake/cacheinit.cmake b/config/cmake/cacheinit.cmake index f8ab3a2..71c8b4a 100644 --- a/config/cmake/cacheinit.cmake +++ b/config/cmake/cacheinit.cmake @@ -40,6 +40,8 @@ set (HDF5_ENABLE_ALL_WARNINGS ON CACHE BOOL "Enable all warnings" FORCE) set (HDF_TEST_EXPRESS "2" CACHE STRING "Control testing framework (0-3)" FORCE) +set (HDF5_MINGW_STATIC_GCC_LIBS ON CACHE BOOL "Statically link libgcc/libstdc++" FORCE) + set (HDF5_ALLOW_EXTERNAL_SUPPORT "NO" CACHE STRING "Allow External Library Building (NO GIT TGZ)" FORCE) set_property (CACHE HDF5_ALLOW_EXTERNAL_SUPPORT PROPERTY STRINGS NO GIT TGZ) diff --git a/release_docs/INSTALL_CMake.txt b/release_docs/INSTALL_CMake.txt index ed27bb2..89d3ac0 100644 --- a/release_docs/INSTALL_CMake.txt +++ b/release_docs/INSTALL_CMake.txt @@ -778,6 +778,7 @@ HDF5_WANT_DATA_ACCURACY "IF data accuracy is guaranteed during data conve HDF5_WANT_DCONV_EXCEPTION "exception handling functions is checked during data conversions" ON HDF5_ENABLE_THREADSAFE "Enable Threadsafety" OFF HDF5_MSVC_NAMING_CONVENTION "Use MSVC Naming conventions for Shared Libraries" OFF +HDF5_MINGW_STATIC_GCC_LIBS "Statically link libgcc/libstdc++" OFF if (APPLE) HDF5_BUILD_WITH_INSTALL_NAME "Build with library install_name set to the installation path" OFF if (CMAKE_BUILD_TYPE MATCHES Debug) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 70af053..43356527 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -54,6 +54,13 @@ New Features when using a MinGW toolchain (xan - 2020/10/30) + + - CMake option to statically link gcc libs with MinGW + + HDF5_MINGW_STATIC_GCC_LIBS allows to statically link libg/libstdc++ + with the MinGW toolchain + + (xan - 2020/10/30) - CMake option to build the HDF filter plugins project as an external project -- cgit v0.12