From 42f1abd7e917ca56de2faed1c8b7e190294ccbb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Fri, 22 Apr 2022 23:03:58 +0300 Subject: [PATCH] mdbx-cmake: fix/refine `--allow-multiple-definition` as workaround for `std::filesystem` and LCC < 1.25.23 --- CMakeLists.txt | 2 +- cmake/compiler.cmake | 13 +++++++++++++ test/CMakeLists.txt | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 56a89392..2ddc192b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -621,7 +621,7 @@ macro(libmdbx_setup_libs TARGET MODE) target_link_libraries(${TARGET} ${MODE} log) endif() if(LIBCXX_FILESYSTEM AND MDBX_BUILD_CXX) - if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.26.0 + if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.25.23 AND NOT CMAKE_VERSION VERSION_LESS 3.13) target_link_options(${TARGET} PUBLIC "-Wl,--allow-multiple-definition") endif() diff --git a/cmake/compiler.cmake b/cmake/compiler.cmake index c893867d..17c468b7 100644 --- a/cmake/compiler.cmake +++ b/cmake/compiler.cmake @@ -913,6 +913,8 @@ macro(probe_libcxx_filesystem) include(CheckCXXSourceCompiles) cmake_push_check_state() set(stdfs_probe_save_libraries ${CMAKE_REQUIRED_LIBRARIES}) + set(stdfs_probe_save_flags ${CMAKE_REQUIRED_FLAGS}) + set(stdfs_probe_save_link_options ${CMAKE_REQUIRED_LINK_OPTIONS}) unset(stdfs_probe_clear_cxx_standard) if(NOT DEFINED CMAKE_CXX_STANDARD) list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_14 HAS_CXX14) @@ -927,6 +929,13 @@ macro(probe_libcxx_filesystem) endif() set(stdfs_probe_clear_cxx_standard ON) endif() + if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.25.23) + if(CMAKE_VERSION VERSION_LESS 3.14) + set(CMAKE_REQUIRED_FLAGS ${stdfs_probe_save_flags} "-Wl,--allow-multiple-definition") + else() + set(CMAKE_REQUIRED_LINK_OPTIONS ${stdfs_probe_save_link_options} "-Wl,--allow-multiple-definition") + endif() + endif() set(stdfs_probe_code [[ #if defined(__SIZEOF_INT128__) && !defined(__GLIBCXX_TYPE_INT_N_0) && defined(__clang__) && __clang_major__ < 4 @@ -994,11 +1003,15 @@ macro(probe_libcxx_filesystem) endif() endif() + set(CMAKE_REQUIRED_LINK_OPTIONS ${stdfs_probe_save_link_options}) + set(CMAKE_REQUIRED_FLAGS ${stdfs_probe_save_flags}) set(CMAKE_REQUIRED_LIBRARIES ${stdfs_probe_save_libraries}) if(stdfs_probe_clear_cxx_standard) unset(CMAKE_CXX_STANDARD) endif() unset(stdfs_probe_clear_cxx_standard) + unset(stdfs_probe_save_link_options) + unset(stdfs_probe_save_flags) unset(stdfs_probe_save_libraries) unset(stdfs_probe_code) unset(stdfs_probe_rc) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d3f3b38e..5e7066e1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -47,7 +47,7 @@ set_target_properties(mdbx_test PROPERTIES target_setup_options(mdbx_test) if(NOT MDBX_BUILD_CXX AND LIBCXX_FILESYSTEM) - if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.26.0 + if(CMAKE_COMPILER_IS_ELBRUSCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1.25.23 AND NOT CMAKE_VERSION VERSION_LESS 3.13) target_link_options(mdbx_test PRIVATE "-Wl,--allow-multiple-definition") endif()