Skip to content

Commit 9ec1643

Browse files
ayeteadoeADKaster
authored andcommitted
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.
1 parent 3df8e00 commit 9ec1643

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

Meta/CMake/targets.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ function(lagom_generate_export_header name fs_name)
1818
generate_export_header(${name} EXPORT_MACRO_NAME ${fs_name_upper}_API EXPORT_FILE_NAME "Export.h")
1919
endfunction()
2020

21+
function(lagom_copy_runtime_dlls target_name)
22+
if (WIN32 AND BUILD_SHARED_LIBS)
23+
add_custom_command(TARGET ${target_name} POST_BUILD
24+
COMMAND ${CMAKE_COMMAND}
25+
-E copy_if_different
26+
$<TARGET_RUNTIME_DLLS:${target_name}>
27+
$<TARGET_FILE_DIR:${target_name}>
28+
COMMAND_EXPAND_LISTS
29+
)
30+
endif()
31+
endfunction()
32+
2133
function(lagom_lib target_name fs_name)
2234
cmake_parse_arguments(LAGOM_LIBRARY "EXPLICIT_SYMBOL_EXPORT" "LIBRARY_TYPE" "SOURCES;LIBS" ${ARGN})
2335
string(REPLACE "Lib" "" library ${target_name})
@@ -80,6 +92,7 @@ function(lagom_test source)
8092
endif()
8193
add_executable(${LAGOM_TEST_NAME} ${source})
8294
target_link_libraries(${LAGOM_TEST_NAME} PRIVATE AK LibCore LibFileSystem LibTest ${LAGOM_TEST_CUSTOM_MAIN} ${LAGOM_TEST_LIBS})
95+
lagom_copy_runtime_dlls(${LAGOM_TEST_NAME})
8396

8497
if (WIN32)
8598
target_include_directories(${LAGOM_TEST_NAME} PRIVATE ${PTHREAD_INCLUDE_DIR})
@@ -117,6 +130,7 @@ function(ladybird_bin name)
117130
add_executable(${name} ${SOURCES} ${GENERATED_SOURCES})
118131
add_executable(Lagom::${name} ALIAS ${name})
119132
target_link_libraries(${name} PUBLIC GenericClangPlugin)
133+
lagom_copy_runtime_dlls(${name})
120134
install(
121135
TARGETS ${target_name}
122136
EXPORT LagomTargets

Tests/LibWeb/test-web/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,14 @@ set(SOURCES
99
add_executable(test-web ${SOURCES})
1010
add_dependencies(test-web ladybird_build_resource_files ImageDecoder RequestServer WebContent WebWorker)
1111
target_link_libraries(test-web PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)
12+
lagom_copy_runtime_dlls(test-web)
1213

1314
if (APPLE)
1415
target_compile_definitions(test-web PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")
1516
elseif (WIN32)
1617
target_link_libraries(test-web PRIVATE LibDevTools)
1718
find_package(pthread REQUIRED)
1819
target_include_directories(test-web PRIVATE $<BUILD_INTERFACE:${PTHREAD_INCLUDE_DIR}>)
19-
add_custom_command(TARGET test-web POST_BUILD
20-
COMMAND ${CMAKE_COMMAND}
21-
-E copy_if_different
22-
$<TARGET_RUNTIME_DLLS:test-web>
23-
$<TARGET_FILE_DIR:test-web>
24-
COMMAND_EXPAND_LISTS
25-
)
2620
endif()
2721

2822
# FIXME: Increase support for building targets on Windows

UI/Qt/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ target_sources(ladybird PRIVATE
1515
ladybird.qrc
1616
)
1717
target_link_libraries(ladybird PRIVATE Qt::Core Qt::Gui Qt::Widgets)
18+
lagom_copy_runtime_dlls(ladybird)
1819
create_ladybird_bundle(ladybird)
1920

2021
if (WIN32)
@@ -29,10 +30,6 @@ qt_deploy_runtime_dependencies(
2930
")
3031

3132
add_custom_command(TARGET ladybird POST_BUILD
32-
COMMAND ${CMAKE_COMMAND}
33-
-E copy_if_different
34-
$<TARGET_RUNTIME_DLLS:ladybird>
35-
$<TARGET_FILE_DIR:ladybird>
3633
COMMAND ${CMAKE_COMMAND}
3734
-P ${ladybird_deploy_script}
3835
COMMAND_EXPAND_LISTS

0 commit comments

Comments
 (0)