summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2022-12-23 11:36:02 -0700
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-25 07:58:58 -0700
commitb4d80f92eccf5bbb08805b1b453fd61153a3d2a5 (patch)
tree3fffe651f308f697d56e94e70520498af275b6be
parent03294b0177eea3cbbccc74ab84738bb1a49c39d4 (diff)
downloadserenity-b4d80f92eccf5bbb08805b1b453fd61153a3d2a5.zip
Ladybird: Support building Ladybird as a non-top-level project
The implementation assumes that Lagom is either the top level project, or included before Ladybird is.
-rw-r--r--Ladybird/CMakeLists.txt31
-rw-r--r--Ladybird/cmake/EnableLagom.cmake18
-rw-r--r--Ladybird/cmake/FetchLagom.cmake35
-rw-r--r--Ladybird/cmake/InstallRules.cmake2
4 files changed, 40 insertions, 46 deletions
diff --git a/Ladybird/CMakeLists.txt b/Ladybird/CMakeLists.txt
index 0f18c74b09..de2d38c971 100644
--- a/Ladybird/CMakeLists.txt
+++ b/Ladybird/CMakeLists.txt
@@ -45,16 +45,27 @@ if (ENABLE_UNDEFINED_SANITIZER)
endif()
# Lagom
-include(FetchContent)
-include(cmake/FetchLagom.cmake)
+# FIXME: PROJECT_IS_TOP_LEVEL with CMake 3.21+
+set(LADYBIRD_IS_TOP_LEVEL FALSE)
+set(LADYBIRD_CUSTOM_TARGET_SUFFIX "-ladybird")
+if ("${CMAKE_BINARY_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
+ set(LADYBIRD_IS_TOP_LEVEL TRUE)
+ set(LADYBIRD_CUSTOM_TARGET_SUFFIX "")
+endif()
-get_filename_component(
- SERENITY_SOURCE_DIR "${Lagom_SOURCE_DIR}/../.."
- ABSOLUTE
-)
+if (LADYBIRD_IS_TOP_LEVEL)
+ get_filename_component(
+ SERENITY_SOURCE_DIR "${ladybird_SOURCE_DIR}/.."
+ ABSOLUTE
+ )
+ list(APPEND CMAKE_MODULE_PATH "${SERENITY_SOURCE_DIR}/Meta/CMake")
+ include(cmake/EnableLagom.cmake)
+ include(lagom_compile_options NO_POLICY_SCOPE)
+else()
+ # FIXME: Use SERENITY_SOURCE_DIR in Lagom/CMakeLists.txt
+ set(SERENITY_SOURCE_DIR "${SERENITY_PROJECT_ROOT}")
+endif()
-# Lagom warnings
-include(${Lagom_SOURCE_DIR}/../CMake/lagom_compile_options.cmake)
add_compile_options(-Wno-expansion-to-defined)
add_compile_options(-Wno-user-defined-literals)
@@ -102,12 +113,12 @@ if (ANDROID)
include(cmake/AndroidExtras.cmake)
endif()
-add_custom_target(run
+add_custom_target(run${LADYBIRD_CUSTOM_TARGET_SUFFIX}
COMMAND "${CMAKE_COMMAND}" -E env "SERENITY_SOURCE_DIR=${SERENITY_SOURCE_DIR}" "$<TARGET_FILE:ladybird>"
USES_TERMINAL
)
-add_custom_target(debug
+add_custom_target(debug${LADYBIRD_CUSTOM_TARGET_SUFFIX}
COMMAND "${CMAKE_COMMAND}" -E env "SERENITY_SOURCE_DIR=${SERENITY_SOURCE_DIR}" gdb -ex "set follow-fork-mode child" "$<TARGET_FILE:ladybird>"
USES_TERMINAL
)
diff --git a/Ladybird/cmake/EnableLagom.cmake b/Ladybird/cmake/EnableLagom.cmake
new file mode 100644
index 0000000000..53624e072b
--- /dev/null
+++ b/Ladybird/cmake/EnableLagom.cmake
@@ -0,0 +1,18 @@
+# Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
+#
+# SPDX-License-Identifier: MIT
+
+set(BUILD_LAGOM ON CACHE INTERNAL "Build all Lagom targets")
+
+set(LAGOM_SOURCE_DIR "${SERENITY_SOURCE_DIR}/Meta/Lagom")
+set(LAGOM_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/Lagom")
+
+# FIXME: Setting target_include_directories on Lagom libraries might make this unecessary?
+include_directories(${SERENITY_SOURCE_DIR})
+include_directories(${SERENITY_SOURCE_DIR}/Userland/Libraries)
+include_directories(${LAGOM_BINARY_DIR})
+include_directories(${LAGOM_BINARY_DIR}/Userland/Services)
+include_directories(${LAGOM_BINARY_DIR}/Userland/Libraries)
+
+# We set EXCLUDE_FROM_ALL to make sure that only required Lagom libraries are built
+add_subdirectory("${LAGOM_SOURCE_DIR}" "${LAGOM_BINARY_DIR}" EXCLUDE_FROM_ALL)
diff --git a/Ladybird/cmake/FetchLagom.cmake b/Ladybird/cmake/FetchLagom.cmake
deleted file mode 100644
index aa114e4649..0000000000
--- a/Ladybird/cmake/FetchLagom.cmake
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
-#
-# SPDX-License-Identifier: MIT
-
-# Fetch serenity, so that we can build Lagom from it
-FetchContent_Declare(lagom
- GIT_REPOSITORY https://github.com/SerenityOS/serenity.git
- GIT_TAG origin/master
- GIT_SHALLOW TRUE
- SOURCE_DIR serenity
-)
-
-# Allow developers to skip download/update steps with local checkout
-if (SERENITY_SOURCE_DIR)
- set(FETCHCONTENT_SOURCE_DIR_LAGOM ${SERENITY_SOURCE_DIR} CACHE PATH "Developer's pre-existing serenity source directory" FORCE)
- message(STATUS "Using pre-existing SERENITY_SOURCE_DIR: ${SERENITY_SOURCE_DIR}")
-endif()
-
-# Can't use FetchContent_MakeAvailable b/c we want to use the Lagom build, not the main build
-# Populate source directory for lagom
-FetchContent_GetProperties(lagom)
-if (NOT lagom_POPULATED)
- FetchContent_Populate(lagom)
- set(BUILD_LAGOM ON CACHE INTERNAL "Build all Lagom targets")
-
- # FIXME: Setting target_include_directories on Lagom libraries might make this unecessary?
- include_directories(${lagom_SOURCE_DIR})
- include_directories(${lagom_SOURCE_DIR}/Userland/Libraries)
- include_directories(${lagom_BINARY_DIR})
- include_directories(${lagom_BINARY_DIR}/Userland/Services)
- include_directories(${lagom_BINARY_DIR}/Userland/Libraries)
-
- # We set EXCLUDE_FROM_ALL to make sure that only required Lagom libraries are built
- add_subdirectory(${lagom_SOURCE_DIR}/Meta/Lagom ${lagom_BINARY_DIR} EXCLUDE_FROM_ALL)
-endif()
diff --git a/Ladybird/cmake/InstallRules.cmake b/Ladybird/cmake/InstallRules.cmake
index 592d2f5224..58428b64df 100644
--- a/Ladybird/cmake/InstallRules.cmake
+++ b/Ladybird/cmake/InstallRules.cmake
@@ -28,7 +28,7 @@ install(TARGETS WebContent
DESTINATION bundle
)
-include("${Lagom_SOURCE_DIR}/get_linked_lagom_libraries.cmake")
+include("${SERENITY_SOURCE_DIR}/Meta/Lagom/get_linked_lagom_libraries.cmake")
get_linked_lagom_libraries(ladybird ladybird_lagom_libraries)
get_linked_lagom_libraries(WebContent webcontent_lagom_libraries)
list(APPEND all_required_lagom_libraries ${ladybird_lagom_libraries} ${webcontent_lagom_libraries})