From 95f239a357b68d0925bb4801909a8e997d84bdfa Mon Sep 17 00:00:00 2001 From: ayeteadoe Date: Sat, 23 Aug 2025 23:58:41 -0700 Subject: [PATCH] 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. --- Meta/CMake/targets.cmake | 23 +++++++++++++++++++++-- Services/ImageDecoder/CMakeLists.txt | 4 ++++ Services/RequestServer/CMakeLists.txt | 4 ++++ Services/WebContent/CMakeLists.txt | 4 +++- Services/WebDriver/CMakeLists.txt | 4 ++++ Services/WebWorker/CMakeLists.txt | 1 + Tests/LibWeb/test-web/CMakeLists.txt | 2 +- UI/Qt/CMakeLists.txt | 2 +- 8 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Meta/CMake/targets.cmake b/Meta/CMake/targets.cmake index d712204516..a725d2a6c1 100644 --- a/Meta/CMake/targets.cmake +++ b/Meta/CMake/targets.cmake @@ -30,6 +30,25 @@ function(lagom_copy_runtime_dlls target_name) endif() endfunction() +# https://learn.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=msvc-170 +# Add /SUBSYSTEM:WINDOWS linker flag and defines the default WinMain. This makes the executable target not launch with a console +function(lagom_subsystem_windows target_name) + if(WIN32) + set_target_properties(${target_name} PROPERTIES + WIN32_EXECUTABLE TRUE + LINK_FLAGS "/ENTRY:mainCRTStartup" + ) + endif() +endfunction() + +function(lagom_windows_bin target_name) + cmake_parse_arguments(PARSE_ARGV 2 LAGOM_WINDOWS_BIN "CONSOLE" "" "") + lagom_copy_runtime_dlls(${target_name}) + if (NOT LAGOM_WINDOWS_BIN_CONSOLE) + lagom_subsystem_windows(${target_name}) + 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}) @@ -92,7 +111,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}) + lagom_windows_bin(${LAGOM_TEST_NAME} CONSOLE) if (WIN32) target_include_directories(${LAGOM_TEST_NAME} PRIVATE ${PTHREAD_INCLUDE_DIR}) @@ -130,7 +149,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}) + lagom_windows_bin(${name}) install( TARGETS ${target_name} EXPORT LagomTargets diff --git a/Services/ImageDecoder/CMakeLists.txt b/Services/ImageDecoder/CMakeLists.txt index 38e2268d84..2251e98bf2 100644 --- a/Services/ImageDecoder/CMakeLists.txt +++ b/Services/ImageDecoder/CMakeLists.txt @@ -24,3 +24,7 @@ target_include_directories(imagedecoderservice PRIVATE ${LADYBIRD_SOURCE_DIR}/Se target_link_libraries(ImageDecoder PRIVATE imagedecoderservice LibCore LibMain LibThreading) target_link_libraries(imagedecoderservice PRIVATE LibCore LibGfx LibIPC LibImageDecoderClient LibMain LibThreading) + +if (WIN32) + lagom_windows_bin(ImageDecoder) +endif() diff --git a/Services/RequestServer/CMakeLists.txt b/Services/RequestServer/CMakeLists.txt index b1184068c7..2f6e843c7d 100644 --- a/Services/RequestServer/CMakeLists.txt +++ b/Services/RequestServer/CMakeLists.txt @@ -44,6 +44,10 @@ target_link_libraries(RequestServer PRIVATE requestserverservice) target_link_libraries(requestserverservice PUBLIC LibCore LibDatabase LibDNS LibCrypto LibFileSystem LibIPC LibMain LibTLS LibWebSocket LibURL LibTextCodec LibThreading CURL::libcurl) target_link_libraries(requestserverservice PRIVATE OpenSSL::Crypto OpenSSL::SSL) +if (WIN32) + lagom_windows_bin(RequestServer) +endif() + if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") # Solaris has socket and networking related functions in two extra libraries target_link_libraries(requestserverservice PUBLIC nsl socket) diff --git a/Services/WebContent/CMakeLists.txt b/Services/WebContent/CMakeLists.txt index daa085f6bc..939860b3b8 100644 --- a/Services/WebContent/CMakeLists.txt +++ b/Services/WebContent/CMakeLists.txt @@ -40,7 +40,9 @@ target_link_libraries(WebContent PRIVATE webcontentservice LibURL) if(WIN32) find_package(unofficial-angle REQUIRED CONFIG) - target_link_libraries(WebContent PRIVATE LibTextCodec unofficial::angle::libGLESv2) + find_package(SQLite3 REQUIRED) + target_link_libraries(WebContent PRIVATE LibMedia LibTextCodec SQLite::SQLite3 unofficial::angle::libGLESv2) + lagom_windows_bin(WebContent) endif() diff --git a/Services/WebDriver/CMakeLists.txt b/Services/WebDriver/CMakeLists.txt index d2862d8968..8aa8709c76 100644 --- a/Services/WebDriver/CMakeLists.txt +++ b/Services/WebDriver/CMakeLists.txt @@ -14,3 +14,7 @@ target_include_directories(WebDriver PRIVATE ${LADYBIRD_SOURCE_DIR}/Services) target_link_libraries(WebDriver PRIVATE LibCore LibFileSystem LibGfx LibIPC LibJS LibMain LibWeb LibWebSocket LibWebView) target_link_libraries(WebDriver PRIVATE OpenSSL::Crypto OpenSSL::SSL) + +if (WIN32) + lagom_windows_bin(WebDriver) +endif() diff --git a/Services/WebWorker/CMakeLists.txt b/Services/WebWorker/CMakeLists.txt index d6589415c7..e0674fe736 100644 --- a/Services/WebWorker/CMakeLists.txt +++ b/Services/WebWorker/CMakeLists.txt @@ -24,4 +24,5 @@ target_link_libraries(WebWorker PRIVATE webworkerservice) if(WIN32) find_package(pthread REQUIRED) target_include_directories(WebWorker PRIVATE $) + lagom_windows_bin(WebWorker) endif() diff --git a/Tests/LibWeb/test-web/CMakeLists.txt b/Tests/LibWeb/test-web/CMakeLists.txt index 0d7f544226..77ab79fbee 100644 --- a/Tests/LibWeb/test-web/CMakeLists.txt +++ b/Tests/LibWeb/test-web/CMakeLists.txt @@ -9,7 +9,6 @@ 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="$") @@ -17,6 +16,7 @@ elseif (WIN32) target_link_libraries(test-web PRIVATE LibDevTools) find_package(pthread REQUIRED) target_include_directories(test-web PRIVATE $) + lagom_windows_bin(test-web CONSOLE) endif() # FIXME: Increase support for building targets on Windows diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txt index 404cdff5c4..3889b92d99 100644 --- a/UI/Qt/CMakeLists.txt +++ b/UI/Qt/CMakeLists.txt @@ -16,10 +16,10 @@ 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) + lagom_windows_bin(ladybird) qt_generate_deploy_script( TARGET ladybird OUTPUT_SCRIPT ladybird_deploy_script