diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 97d484421..fe43174c1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32) -if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" AND NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") +if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" AND NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}" AND NOT "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}") # On MinGW with internal libraries, link the standard library statically target_link_options(SRB2SDL2 PRIVATE "-static") endif() @@ -285,3 +285,27 @@ if((CMAKE_COMPILER_IS_GNUCC) AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)) ) endif() endif() + +# copy DLLs to bin/ directory if building internal shared on windows +if("${CMAKE_SYSTEM_NAME}" STREQUAL Windows AND NOT "${SRB2_CONFIG_INTERNAL_LIBRARIES}" AND "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}") + set(ADDITIONAL_DLLS "") + if("${CMAKE_C_COMPILER_ID}" STREQUAL GNU) + # also copy implicitly linked system libraries + get_filename_component(MINGW_BIN_PATH ${CMAKE_CXX_COMPILER} PATH) + list(APPEND ADDITIONAL_DLLS + "libgcc_s_dw2-1.dll" + "libstdc++-6.dll" + "libwinpthread-1.dll" + ) + list(TRANSFORM ADDITIONAL_DLLS PREPEND "${MINGW_BIN_PATH}/") + endif() + add_custom_command(TARGET SRB2SDL2 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + ${ADDITIONAL_DLLS} + + $ + COMMAND_EXPAND_LISTS + COMMENT "Copying runtime DLLs" + ) +endif()