Browse Source

Meta: Build select Services in Lagom

Add overrides for serenity_bin and serenity_lib to allow the actual
CMakeLists.txt from Userland to be used to build as many services as
possible without adding more clutter to Meta/Lagom/CMakeLists.txt
Andrew Kaster 3 years ago
parent
commit
0a62fcfbdf
3 changed files with 94 additions and 45 deletions
  1. 34 28
      Meta/CMake/utils.cmake
  2. 40 0
      Meta/Lagom/CMakeLists.txt
  3. 20 17
      Userland/Services/CMakeLists.txt

+ 34 - 28
Meta/CMake/utils.cmake

@@ -33,27 +33,31 @@ function(serenity_generated_sources target_name)
     endif()
 endfunction()
 
-function(serenity_lib target_name fs_name)
-    serenity_install_headers(${target_name})
-    serenity_install_sources()
-    add_library(${target_name} SHARED ${SOURCES} ${GENERATED_SOURCES})
-    set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
-    set_target_properties(${target_name} PROPERTIES VERSION "serenity")
-    install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL)
-    set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
-    serenity_generated_sources(${target_name})
-endfunction()
-
-function(serenity_lib_static target_name fs_name)
-    serenity_install_headers(${target_name})
-    serenity_install_sources()
-    add_library(${target_name} STATIC ${SOURCES} ${GENERATED_SOURCES})
-    set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
-    set_target_properties(${target_name} PROPERTIES VERSION "serenity")
-    install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL)
-    set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
-    serenity_generated_sources(${target_name})
-endfunction()
+if (NOT COMMAND serenity_lib)
+    function(serenity_lib target_name fs_name)
+        serenity_install_headers(${target_name})
+        serenity_install_sources()
+        add_library(${target_name} SHARED ${SOURCES} ${GENERATED_SOURCES})
+        set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
+        set_target_properties(${target_name} PROPERTIES VERSION "serenity")
+        install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL)
+        set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
+        serenity_generated_sources(${target_name})
+    endfunction()
+endif()
+
+if (NOT COMMAND serenity_lib_static)
+    function(serenity_lib_static target_name fs_name)
+        serenity_install_headers(${target_name})
+        serenity_install_sources()
+        add_library(${target_name} STATIC ${SOURCES} ${GENERATED_SOURCES})
+        set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
+        set_target_properties(${target_name} PROPERTIES VERSION "serenity")
+        install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL)
+        set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
+        serenity_generated_sources(${target_name})
+    endfunction()
+endif()
 
 function(serenity_libc target_name fs_name)
     serenity_install_headers("")
@@ -81,13 +85,15 @@ function(serenity_libc target_name fs_name)
     serenity_generated_sources(${target_name})
 endfunction()
 
-function(serenity_bin target_name)
-    serenity_install_sources()
-    add_executable(${target_name} ${SOURCES})
-    set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
-    install(TARGETS ${target_name} RUNTIME DESTINATION bin OPTIONAL)
-    serenity_generated_sources(${target_name})
-endfunction()
+if (NOT COMMAND serenity_bin)
+    function(serenity_bin target_name)
+        serenity_install_sources()
+        add_executable(${target_name} ${SOURCES})
+        set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
+        install(TARGETS ${target_name} RUNTIME DESTINATION bin OPTIONAL)
+        serenity_generated_sources(${target_name})
+    endfunction()
+endif()
 
 function(serenity_test test_src sub_dir)
     cmake_parse_arguments(PARSE_ARGV 2 SERENITY_TEST "MAIN_ALREADY_DEFINED" "CUSTOM_MAIN" "LIBS")

+ 40 - 0
Meta/Lagom/CMakeLists.txt

@@ -23,6 +23,7 @@ get_filename_component(
     SERENITY_PROJECT_ROOT "${PROJECT_SOURCE_DIR}/../.."
     ABSOLUTE CACHE
 )
+set(SerenityOS_SOURCE_DIR "${SERENITY_PROJECT_ROOT}" CACHE STRING "")
 
 list(APPEND CMAKE_MODULE_PATH "${SERENITY_PROJECT_ROOT}/Meta/CMake")
 
@@ -137,8 +138,11 @@ configure_file(../../AK/Debug.h.in AK/Debug.h @ONLY)
 include_directories(../../)
 include_directories(../../Userland/)
 include_directories(../../Userland/Libraries/)
+include_directories(../../Userland/Services)
 include_directories(${CMAKE_BINARY_DIR})
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
+include_directories(${CMAKE_BINARY_DIR}/Libraries)
+include_directories(${CMAKE_BINARY_DIR}/Services)
 
 # install rules, think about moving to its own helper cmake file
 include(CMakePackageConfigHelpers)
@@ -222,6 +226,31 @@ function(lagom_test source)
     )
 endfunction()
 
+function(serenity_bin name)
+    add_executable(${name} ${SOURCES} ${GENERATED_SOURCES})
+    add_executable(Lagom::${name} ALIAS ${name})
+    install(
+        TARGETS ${target_name}
+        EXPORT LagomTargets
+        RUNTIME #
+            COMPONENT Lagom_Runtime
+        LIBRARY #
+            COMPONENT Lagom_Runtime
+            NAMELINK_COMPONENT Lagom_Development
+        ARCHIVE #
+            COMPONENT Lagom_Development
+        INCLUDES #
+            DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+    )
+endfunction()
+
+function(serenity_lib name fs_name)
+    lagom_lib(name fs_name SOURCES ${SOURCES} ${GENERATED_SOURCES})
+endfunction()
+
+add_custom_target(components ALL)
+option(BUILD_EVERYTHING "Build all optional components" ON)
+
 if (NOT TARGET all_generated)
     # Meta target to run all code-gen steps in the build.
     add_custom_target(all_generated)
@@ -306,6 +335,12 @@ if (BUILD_LAGOM)
         SOURCES ${LIBCRYPTO_SOURCES} ${LIBCRYPTO_SUBDIR_SOURCES} ${LIBCRYPTO_SUBSUBDIR_SOURCES}
     )
 
+    file(GLOB LIBDNS_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibDNS/*.cpp")
+    lagom_lib(DNS dns
+        SOURCES ${LIBDNS_SOURCES}
+        LIBS LibIPC
+    )
+
     # ELF
     # FIXME: Excluding arm64 is a temporary hack to circumvent a build problem
     #        for Lagom on Apple M1
@@ -525,6 +560,9 @@ if (BUILD_LAGOM)
         SOURCES ${LIBXML_SOURCES})
 
     if (NOT ENABLE_FUZZERS AND NOT ENABLE_COMPILER_EXPLORER_BUILD)
+        # Lagom Services
+        add_subdirectory("${SERENITY_PROJECT_ROOT}/Userland/Services" "${CMAKE_CURRENT_BINARY_DIR}/Services")
+
         # Lagom Examples
         add_executable(TestApp TestApp.cpp)
         target_link_libraries(TestApp LibCore)
@@ -766,4 +804,6 @@ endif()
 
 if (ENABLE_FUZZERS)
     add_subdirectory(Fuzzers)
+else()
+    export_components("${CMAKE_BINARY_DIR}/components.ini")
 endif()

+ 20 - 17
Userland/Services/CMakeLists.txt

@@ -1,27 +1,30 @@
-add_subdirectory(AudioServer)
-add_subdirectory(ChessEngine)
-add_subdirectory(Clipboard)
 add_subdirectory(ConfigServer)
-add_subdirectory(CrashDaemon)
-add_subdirectory(DHCPClient)
 add_subdirectory(EchoServer)
-add_subdirectory(FileSystemAccessServer)
 add_subdirectory(FileOperation)
 add_subdirectory(ImageDecoder)
 add_subdirectory(InspectorServer)
-add_subdirectory(KeyboardPreferenceLoader)
-add_subdirectory(LaunchServer)
-add_subdirectory(LoginServer)
 add_subdirectory(LookupServer)
-add_subdirectory(NetworkServer)
-add_subdirectory(NotificationServer)
 add_subdirectory(RequestServer)
 add_subdirectory(SQLServer)
-add_subdirectory(SpiceAgent)
-add_subdirectory(SystemServer)
-add_subdirectory(Taskbar)
-add_subdirectory(TelnetServer)
-add_subdirectory(WebContent)
 add_subdirectory(WebServer)
 add_subdirectory(WebSocket)
-add_subdirectory(WindowServer)
+
+if (SERENITYOS)
+    add_subdirectory(AudioServer)
+    add_subdirectory(ChessEngine)
+    add_subdirectory(Clipboard)
+    add_subdirectory(CrashDaemon)
+    add_subdirectory(DHCPClient)
+    add_subdirectory(FileSystemAccessServer)
+    add_subdirectory(KeyboardPreferenceLoader)
+    add_subdirectory(LaunchServer)
+    add_subdirectory(LoginServer)
+    add_subdirectory(NetworkServer)
+    add_subdirectory(NotificationServer)
+    add_subdirectory(SpiceAgent)
+    add_subdirectory(SystemServer)
+    add_subdirectory(Taskbar)
+    add_subdirectory(TelnetServer)
+    add_subdirectory(WebContent)
+    add_subdirectory(WindowServer)
+endif()