Skip to content

Commit 95f239a

Browse files
ayeteadoeADKaster
authored andcommitted
CMake: Add Windows executable helper function
The function currently has 2 purposes: (1) To copy dependent dlls for executables to output binary directory. This ensures that these helper processes can be ran after a build given not all DLLs from vcpkg libs get implicitly copied to the bin folder. (2) Allow fully background and/or GUI processes to use the Windows Subsystem. This prevents unnecessarily launching a console for the process, as we either require no user interaction or the user interaction is all handled in the GUI.
1 parent 20f9510 commit 95f239a

File tree

8 files changed

+39
-5
lines changed

8 files changed

+39
-5
lines changed

Meta/CMake/targets.cmake

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ function(lagom_copy_runtime_dlls target_name)
3030
endif()
3131
endfunction()
3232

33+
# https://learn.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=msvc-170
34+
# Add /SUBSYSTEM:WINDOWS linker flag and defines the default WinMain. This makes the executable target not launch with a console
35+
function(lagom_subsystem_windows target_name)
36+
if(WIN32)
37+
set_target_properties(${target_name} PROPERTIES
38+
WIN32_EXECUTABLE TRUE
39+
LINK_FLAGS "/ENTRY:mainCRTStartup"
40+
)
41+
endif()
42+
endfunction()
43+
44+
function(lagom_windows_bin target_name)
45+
cmake_parse_arguments(PARSE_ARGV 2 LAGOM_WINDOWS_BIN "CONSOLE" "" "")
46+
lagom_copy_runtime_dlls(${target_name})
47+
if (NOT LAGOM_WINDOWS_BIN_CONSOLE)
48+
lagom_subsystem_windows(${target_name})
49+
endif()
50+
endfunction()
51+
3352
function(lagom_lib target_name fs_name)
3453
cmake_parse_arguments(LAGOM_LIBRARY "EXPLICIT_SYMBOL_EXPORT" "LIBRARY_TYPE" "SOURCES;LIBS" ${ARGN})
3554
string(REPLACE "Lib" "" library ${target_name})
@@ -92,7 +111,7 @@ function(lagom_test source)
92111
endif()
93112
add_executable(${LAGOM_TEST_NAME} ${source})
94113
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})
114+
lagom_windows_bin(${LAGOM_TEST_NAME} CONSOLE)
96115

97116
if (WIN32)
98117
target_include_directories(${LAGOM_TEST_NAME} PRIVATE ${PTHREAD_INCLUDE_DIR})
@@ -130,7 +149,7 @@ function(ladybird_bin name)
130149
add_executable(${name} ${SOURCES} ${GENERATED_SOURCES})
131150
add_executable(Lagom::${name} ALIAS ${name})
132151
target_link_libraries(${name} PUBLIC GenericClangPlugin)
133-
lagom_copy_runtime_dlls(${name})
152+
lagom_windows_bin(${name})
134153
install(
135154
TARGETS ${target_name}
136155
EXPORT LagomTargets

Services/ImageDecoder/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ target_include_directories(imagedecoderservice PRIVATE ${LADYBIRD_SOURCE_DIR}/Se
2424

2525
target_link_libraries(ImageDecoder PRIVATE imagedecoderservice LibCore LibMain LibThreading)
2626
target_link_libraries(imagedecoderservice PRIVATE LibCore LibGfx LibIPC LibImageDecoderClient LibMain LibThreading)
27+
28+
if (WIN32)
29+
lagom_windows_bin(ImageDecoder)
30+
endif()

Services/RequestServer/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ target_link_libraries(RequestServer PRIVATE requestserverservice)
4444
target_link_libraries(requestserverservice PUBLIC LibCore LibDatabase LibDNS LibCrypto LibFileSystem LibIPC LibMain LibTLS LibWebSocket LibURL LibTextCodec LibThreading CURL::libcurl)
4545
target_link_libraries(requestserverservice PRIVATE OpenSSL::Crypto OpenSSL::SSL)
4646

47+
if (WIN32)
48+
lagom_windows_bin(RequestServer)
49+
endif()
50+
4751
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
4852
# Solaris has socket and networking related functions in two extra libraries
4953
target_link_libraries(requestserverservice PUBLIC nsl socket)

Services/WebContent/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ target_link_libraries(WebContent PRIVATE webcontentservice LibURL)
4040

4141
if(WIN32)
4242
find_package(unofficial-angle REQUIRED CONFIG)
43-
target_link_libraries(WebContent PRIVATE LibTextCodec unofficial::angle::libGLESv2)
43+
find_package(SQLite3 REQUIRED)
44+
target_link_libraries(WebContent PRIVATE LibMedia LibTextCodec SQLite::SQLite3 unofficial::angle::libGLESv2)
45+
lagom_windows_bin(WebContent)
4446
endif()
4547

4648

Services/WebDriver/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ target_include_directories(WebDriver PRIVATE ${LADYBIRD_SOURCE_DIR}/Services)
1414

1515
target_link_libraries(WebDriver PRIVATE LibCore LibFileSystem LibGfx LibIPC LibJS LibMain LibWeb LibWebSocket LibWebView)
1616
target_link_libraries(WebDriver PRIVATE OpenSSL::Crypto OpenSSL::SSL)
17+
18+
if (WIN32)
19+
lagom_windows_bin(WebDriver)
20+
endif()

Services/WebWorker/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ target_link_libraries(WebWorker PRIVATE webworkerservice)
2424
if(WIN32)
2525
find_package(pthread REQUIRED)
2626
target_include_directories(WebWorker PRIVATE $<BUILD_INTERFACE:${PTHREAD_INCLUDE_DIR}>)
27+
lagom_windows_bin(WebWorker)
2728
endif()

Tests/LibWeb/test-web/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +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)
1312

1413
if (APPLE)
1514
target_compile_definitions(test-web PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")
1615
elseif (WIN32)
1716
target_link_libraries(test-web PRIVATE LibDevTools)
1817
find_package(pthread REQUIRED)
1918
target_include_directories(test-web PRIVATE $<BUILD_INTERFACE:${PTHREAD_INCLUDE_DIR}>)
19+
lagom_windows_bin(test-web CONSOLE)
2020
endif()
2121

2222
# FIXME: Increase support for building targets on Windows

UI/Qt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ target_sources(ladybird PRIVATE
1616
ladybird.qrc
1717
)
1818
target_link_libraries(ladybird PRIVATE Qt::Core Qt::Gui Qt::Widgets)
19-
lagom_copy_runtime_dlls(ladybird)
2019
create_ladybird_bundle(ladybird)
2120

2221
if (WIN32)
22+
lagom_windows_bin(ladybird)
2323
qt_generate_deploy_script(
2424
TARGET ladybird
2525
OUTPUT_SCRIPT ladybird_deploy_script

0 commit comments

Comments
 (0)