Files
FluidSimCpp/cmake/MinGWRuntime.cmake

34 lines
1.4 KiB
CMake

# Keep standalone GCC executables runnable without modifying the user's PATH.
if(NOT MINGW OR NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
return()
endif()
get_filename_component(compiler_directory "${CMAKE_CXX_COMPILER}" DIRECTORY)
set(runtime_dlls)
foreach(runtime_names
"libgcc_s_seh-1.dll|libgcc_s_dw2-1.dll|libgcc_s_sjlj-1.dll"
"libstdc++-6.dll"
"libwinpthread-1.dll")
string(REPLACE "|" ";" runtime_names "${runtime_names}")
find_file(runtime_dll NAMES ${runtime_names}
PATHS "${compiler_directory}" NO_DEFAULT_PATH NO_CACHE)
if(NOT runtime_dll)
message(FATAL_ERROR "Cannot find MinGW runtime ${runtime_names} in ${compiler_directory}")
endif()
list(APPEND runtime_dlls "${runtime_dll}")
unset(runtime_dll)
endforeach()
# This file is included after all project executables have been declared.
get_property(project_targets DIRECTORY PROPERTY BUILDSYSTEM_TARGETS)
foreach(project_target IN LISTS project_targets)
get_target_property(target_type "${project_target}" TYPE)
if(target_type STREQUAL "EXECUTABLE")
add_custom_command(TARGET "${project_target}" POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different
${runtime_dlls} "$<TARGET_FILE_DIR:${project_target}>"
COMMENT "Copying MinGW runtime DLLs for ${project_target}"
VERBATIM)
endif()
endforeach()