From 53f12f98a1153631f8ef3c98791980fd80672f87 Mon Sep 17 00:00:00 2001 From: "oana.stanoi" Date: Tue, 8 Aug 2023 15:18:38 +0200 Subject: [PATCH 1/2] Link with "msvcr[n]" available on the system, instead of a specific hardcoded dependency --- BackwardConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BackwardConfig.cmake b/BackwardConfig.cmake index 7f6b3cb..e66533e 100644 --- a/BackwardConfig.cmake +++ b/BackwardConfig.cmake @@ -210,7 +210,7 @@ if(WIN32) set(CMAKE_EXE_LINKER_FLAGS "-Wl,--pdb= ") add_compile_options(-gcodeview) else() - set(MINGW_MSVCR_LIBRARY "msvcr90$<$:d>" CACHE STRING "Mingw MSVC runtime import library") + find_library(MINGW_MSVCR_LIBRARY ucrtbase msvcr140 msvcr120 msvcr110 msvcr100 msvcr90 REQUIRED DOC "Mingw MSVC runtime import library") list(APPEND _BACKWARD_LIBRARIES ${MINGW_MSVCR_LIBRARY}) endif() endif() From 53b0e05d4b1e90ef50c47f56b567cbb287b01d76 Mon Sep 17 00:00:00 2001 From: Giuseppe Corbelli Date: Fri, 26 Jan 2024 15:39:49 +0100 Subject: [PATCH 2/2] Link with ucrtbase/msvcr* available on the system Use check_cxx_source_compiles() to find the most recent linkable ucrtbase/msvcr. Linking of ucrtbase/msvcr is enabled regardless of the -gcodeview support, as the two concepts do not overlap. --- BackwardConfig.cmake | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/BackwardConfig.cmake b/BackwardConfig.cmake index e66533e..995b17a 100644 --- a/BackwardConfig.cmake +++ b/BackwardConfig.cmake @@ -209,11 +209,27 @@ if(WIN32) if(SUPPORT_WINDOWS_DEBUG_INFO) set(CMAKE_EXE_LINKER_FLAGS "-Wl,--pdb= ") add_compile_options(-gcodeview) - else() - find_library(MINGW_MSVCR_LIBRARY ucrtbase msvcr140 msvcr120 msvcr110 msvcr100 msvcr90 REQUIRED DOC "Mingw MSVC runtime import library") - list(APPEND _BACKWARD_LIBRARIES ${MINGW_MSVCR_LIBRARY}) endif() - endif() + # Look for _set_abort_behavior in a few msvcr implementations starting from most recent one + include(CheckCXXSourceCompiles) + include(CMakePushCheckState) + set(src_set_abort_behavior "#include \nint main(int argc, char* argv[]) { _set_abort_behavior(0, 0); return 0;}\n") + set(_MSVCR_LIBRARIES ucrtbase msvcr140 msvcr120 msvcr110 msvcr100 msvcr90) + foreach(_MSVCR_LIBRARY ${_MSVCR_LIBRARIES}) + cmake_push_check_state(RESET) + set(CMAKE_REQUIRED_LIBRARIES ${_MSVCR_LIBRARY}) + check_cxx_source_compiles("${src_set_abort_behavior}" _MSVCR_FOUND_LIBRARY) + if(_MSVCR_FOUND_LIBRARY) + set(MINGW_MSVCR_LIBRARY ${_MSVCR_LIBRARY} CACHE STRING "Mingw MSVC runtime import library") + list(APPEND _BACKWARD_LIBRARIES ${MINGW_MSVCR_LIBRARY}) + break() + endif() + cmake_pop_check_state() + endforeach() + if(NOT _MSVCR_FOUND_LIBRARY) + message(FATAL_ERROR "At least one of the import libraries ${_MSVCR_LIBRARIES} should be available ") + endif() + endif() endif() set(BACKWARD_INCLUDE_DIR