Skip to content

Commit

Permalink
Link with ucrtbase/msvcr* available on the system
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Giuseppe Corbelli committed Jan 26, 2024
1 parent 53f12f9 commit 53b0e05
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions BackwardConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdlib.h>\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
Expand Down

0 comments on commit 53b0e05

Please sign in to comment.