@@ -3,8 +3,10 @@ set(GLFW3_STATIC_INIT ON)
33
44set (LIBRW_STATIC_RUNTIME_DEFAULT ON )
55
6+ option (LIBRW_INSTALL_RUNTIME_DEPS "Install runtime dependencies of executables" OFF )
7+
68function (librw_platform_target TARGET )
7- cmake_parse_arguments (LPT "PROVIDES_WINMAIN" "" "" ${ARGN} )
9+ cmake_parse_arguments (LPT "INSTALL; PROVIDES_WINMAIN" "" "" ${ARGN} )
810 get_target_property (TARGET_TYPE "${TARGET} " TYPE )
911
1012 if (MINGW)
@@ -21,4 +23,41 @@ function(librw_platform_target TARGET)
2123 set_target_properties (${TARGET} PROPERTIES
2224 VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:${TARGET} >"
2325 )
26+
27+ if (LIBRW_INSTALL_RUNTIME_DEPS)
28+ # Copy runtime dependencies (glfw3/SDL2 library + gcc runtime libraries)
29+ if (LPT_INSTALL AND TARGET_TYPE MATCHES "^EXECUTABLE$" )
30+ cmake_minimum_required (VERSION 3.14)
31+ # FIXME: Once CMake 3.21 becomes common, replace with `install(RUNTIME_DEPENDENCY_SET)`
32+ set (install_code [=[
33+ set(runtime_extra_directories)
34+ execute_process(COMMAND uname OUTPUT_VARIABLE uname OUTPUT_VARIABLE uname_out RESULT_VARIABLE uname_res)
35+ if(uname_res EQUAL 0)
36+ string(STRIP "${uname_out}" uname_out)
37+ if (uname_out MATCHES "^(MINGW|mingw)(32|64)" AND DEFINED ENV{MSYSTEM_PREFIX})
38+ execute_process(COMMAND cygpath -m "$ENV{MSYSTEM_PREFIX}/bin" OUTPUT_VARIABLE cygpath_out RESULT_VARIABLE cygpath_res)
39+ if(cygpath_res EQUAL 0)
40+ string(STRIP "${cygpath_out}" cygpath_out)
41+ list(APPEND runtime_extra_directories "${cygpath_out}")
42+ endif()
43+ endif()
44+ endif()
45+
46+ file(GET_RUNTIME_DEPENDENCIES
47+ RESOLVED_DEPENDENCIES_VAR var
48+ UNRESOLVED_DEPENDENCIES_VAR unvar
49+ EXECUTABLES $<TARGET_FILE:__TARGET__>
50+ DIRECTORIES ${runtime_extra_directories}
51+ )
52+ file(COPY ${var} DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/__CMAKE_INSTALL_BINDIR__
53+ FILES_MATCHING
54+ REGEX ".*(lib)?(GLFW|glfw|SDL2|sdl2).*\\.dll$"
55+ REGEX ".*lib(gcc|stdc\\+\\+|winpthread).*\\.dll$"
56+ )
57+ ]=])
58+ string (REPLACE __TARGET__ "${TARGET} " install_code ${install_code} )
59+ string (REPLACE __CMAKE_INSTALL_BINDIR__ "${CMAKE_INSTALL_BINDIR} " install_code ${install_code} )
60+ install (CODE "${install_code} " )
61+ endif ()
62+ endif ()
2463endfunction ()
0 commit comments