···204204# Let consumers of msvcrt have the right defines
205205target_compile_definitions(libmsvcrt INTERFACE _DLL __USE_CRTIMP)
206206207207-# Embed msvcrtex into libmsvcrt
208208-target_sources(libmsvcrt PRIVATE $<TARGET_OBJECTS:msvcrtex>)
207207+# Link libmsvcrt to msvcrtex
208208+target_link_libraries(libmsvcrt INTERFACE msvcrtex)
209209210210# Link GCC stack protector lib
211211if (STACK_PROTECTOR)
+1-1
dll/win32/ucrtbase/CMakeLists.txt
···4242)
43434444# Implicitly link to vcstartup
4545-target_link_libraries(libucrtbase vcstartup)
4545+target_link_libraries(libucrtbase INTERFACE vcstartup)
46464747if(MSVC)
4848 target_link_libraries(ucrtbase runtmchk)
···443443 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} native-spec2def)
444444445445 # With this, we let DLLTOOL create an import library
446446+ # Note: previously we re-archived the import library created by dlltool into
447447+ # a thin archive ('ar crT'). This is broken with binutils 2.40+ (bug #31614)
448448+ # and leads to a linker crash. The new method of using an IMPORTED library
449449+ # avoids this. It does no longer allow to embed new object files into the
450450+ # import libraries, but this is replaced by linking the additinal libraries
451451+ # to the import library.
446452 set(LIBRARY_PRIVATE_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_libname}.dir)
447453 add_custom_command(
448454 OUTPUT ${LIBRARY_PRIVATE_DIR}/${_libname}.a
449455 # ar just puts stuff into the archive, without looking twice. Just delete the lib, we're going to rebuild it anyway
450450- COMMAND ${CMAKE_COMMAND} -E rm -f $<TARGET_FILE:${_libname}>
456456+ COMMAND ${CMAKE_COMMAND} -E rm -f ${LIBRARY_PRIVATE_DIR}/${_libname}.a
451457 COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def --kill-at --output-lib=${_libname}.a -t ${_libname}
452458 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
453459 WORKING_DIRECTORY ${LIBRARY_PRIVATE_DIR})
454460455455- # We create a static library with the importlib thus created as object. AR will extract the obj files and archive it again as a thin lib
456456- set_source_files_properties(
457457- ${LIBRARY_PRIVATE_DIR}/${_libname}.a
458458- PROPERTIES
459459- EXTERNAL_OBJECT TRUE)
460460- _add_library(${_libname} STATIC EXCLUDE_FROM_ALL
461461- ${LIBRARY_PRIVATE_DIR}/${_libname}.a)
462462- set_target_properties(${_libname}
463463- PROPERTIES
464464- LINKER_LANGUAGE "C"
465465- PREFIX "")
461461+ # Create a custom target for the import library generation
462462+ add_custom_target(${_libname}_implib_target DEPENDS ${LIBRARY_PRIVATE_DIR}/${_libname}.a)
463463+464464+ # Create an IMPORTED library that references the dlltool output
465465+ _add_library(${_libname} STATIC IMPORTED GLOBAL)
466466+ set_target_properties(${_libname} PROPERTIES IMPORTED_LOCATION ${LIBRARY_PRIVATE_DIR}/${_libname}.a)
467467+ add_dependencies(${_libname} ${_libname}_implib_target)
466468467469 # Do the same with delay-import libs
468470 set(LIBRARY_PRIVATE_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_libname}_delayed.dir)
469471 add_custom_command(
470472 OUTPUT ${LIBRARY_PRIVATE_DIR}/${_libname}_delayed.a
471473 # ar just puts stuff into the archive, without looking twice. Just delete the lib, we're going to rebuild it anyway
472472- COMMAND ${CMAKE_COMMAND} -E rm -f $<TARGET_FILE:${_libname}_delayed>
474474+ COMMAND ${CMAKE_COMMAND} -E rm -f ${LIBRARY_PRIVATE_DIR}/${_libname}_delayed.a
473475 COMMAND ${CMAKE_DLLTOOL} --def ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def --kill-at --output-delaylib=${_libname}_delayed.a -t ${_libname}_delayed
474476 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_libname}_implib.def
475477 WORKING_DIRECTORY ${LIBRARY_PRIVATE_DIR})
476478477477- # We create a static library with the importlib thus created. AR will extract the obj files and archive it again as a thin lib
478478- set_source_files_properties(
479479- ${LIBRARY_PRIVATE_DIR}/${_libname}_delayed.a
480480- PROPERTIES
481481- EXTERNAL_OBJECT TRUE)
482482- _add_library(${_libname}_delayed STATIC EXCLUDE_FROM_ALL
483483- ${LIBRARY_PRIVATE_DIR}/${_libname}_delayed.a)
484484- set_target_properties(${_libname}_delayed
485485- PROPERTIES
486486- LINKER_LANGUAGE "C"
487487- PREFIX "")
479479+ # Create a custom target for the delay-import library generation
480480+ add_custom_target(${_libname}_delayed_implib_target DEPENDS ${LIBRARY_PRIVATE_DIR}/${_libname}_delayed.a)
481481+482482+ # Create an IMPORTED library for delay-import
483483+ _add_library(${_libname}_delayed STATIC IMPORTED GLOBAL)
484484+ set_target_properties(${_libname}_delayed PROPERTIES IMPORTED_LOCATION ${LIBRARY_PRIVATE_DIR}/${_libname}_delayed.a)
485485+ add_dependencies(${_libname}_delayed ${_libname}_delayed_implib_target)
488486endfunction()
489487490488function(spec2def _dllname _spec_file)