CMake: Add helper to ensure vcpkg DLLs are copied to the output dir

The BUILD_RPATH/INSTALL_RPATH CMake infrastructure is not supported
on Windows, but we want to ensure Ladybird executables are runnable
after the build phase so there can be an efficient dev loop.
lagom_copy_runtime_dlls() can be used by executable targets so all
their dependent dlls are copied to their output directory in their
post build step.
This commit is contained in:
ayeteadoe 2025-08-07 11:08:13 -07:00 committed by Andrew Kaster
parent 3df8e00d91
commit 9ec1643d88
Notes: github-actions[bot] 2025-08-23 22:05:49 +00:00
3 changed files with 16 additions and 11 deletions

View file

@ -18,6 +18,18 @@ function(lagom_generate_export_header name fs_name)
generate_export_header(${name} EXPORT_MACRO_NAME ${fs_name_upper}_API EXPORT_FILE_NAME "Export.h")
endfunction()
function(lagom_copy_runtime_dlls target_name)
if (WIN32 AND BUILD_SHARED_LIBS)
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_if_different
$<TARGET_RUNTIME_DLLS:${target_name}>
$<TARGET_FILE_DIR:${target_name}>
COMMAND_EXPAND_LISTS
)
endif()
endfunction()
function(lagom_lib target_name fs_name)
cmake_parse_arguments(LAGOM_LIBRARY "EXPLICIT_SYMBOL_EXPORT" "LIBRARY_TYPE" "SOURCES;LIBS" ${ARGN})
string(REPLACE "Lib" "" library ${target_name})
@ -80,6 +92,7 @@ function(lagom_test source)
endif()
add_executable(${LAGOM_TEST_NAME} ${source})
target_link_libraries(${LAGOM_TEST_NAME} PRIVATE AK LibCore LibFileSystem LibTest ${LAGOM_TEST_CUSTOM_MAIN} ${LAGOM_TEST_LIBS})
lagom_copy_runtime_dlls(${LAGOM_TEST_NAME})
if (WIN32)
target_include_directories(${LAGOM_TEST_NAME} PRIVATE ${PTHREAD_INCLUDE_DIR})
@ -117,6 +130,7 @@ function(ladybird_bin name)
add_executable(${name} ${SOURCES} ${GENERATED_SOURCES})
add_executable(Lagom::${name} ALIAS ${name})
target_link_libraries(${name} PUBLIC GenericClangPlugin)
lagom_copy_runtime_dlls(${name})
install(
TARGETS ${target_name}
EXPORT LagomTargets

View file

@ -9,6 +9,7 @@ set(SOURCES
add_executable(test-web ${SOURCES})
add_dependencies(test-web ladybird_build_resource_files ImageDecoder RequestServer WebContent WebWorker)
target_link_libraries(test-web PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)
lagom_copy_runtime_dlls(test-web)
if (APPLE)
target_compile_definitions(test-web PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")
@ -16,13 +17,6 @@ elseif (WIN32)
target_link_libraries(test-web PRIVATE LibDevTools)
find_package(pthread REQUIRED)
target_include_directories(test-web PRIVATE $<BUILD_INTERFACE:${PTHREAD_INCLUDE_DIR}>)
add_custom_command(TARGET test-web POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_if_different
$<TARGET_RUNTIME_DLLS:test-web>
$<TARGET_FILE_DIR:test-web>
COMMAND_EXPAND_LISTS
)
endif()
# FIXME: Increase support for building targets on Windows

View file

@ -15,6 +15,7 @@ target_sources(ladybird PRIVATE
ladybird.qrc
)
target_link_libraries(ladybird PRIVATE Qt::Core Qt::Gui Qt::Widgets)
lagom_copy_runtime_dlls(ladybird)
create_ladybird_bundle(ladybird)
if (WIN32)
@ -29,10 +30,6 @@ qt_deploy_runtime_dependencies(
")
add_custom_command(TARGET ladybird POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_if_different
$<TARGET_RUNTIME_DLLS:ladybird>
$<TARGET_FILE_DIR:ladybird>
COMMAND ${CMAKE_COMMAND}
-P ${ladybird_deploy_script}
COMMAND_EXPAND_LISTS