1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:27:35 +00:00

CMake+Userland: Use CMakeLists from Userland to build Lagom Libraries

Also do this for Shell.

This greatly simplifies the CMakeLists in Lagom, replacing many glob
patterns with a big list of libraries. There are still a few special
libraries that need some help to conform to the pattern, like LibELF and
LibWebView.

It also lets us remove essentially all of the Serenity or Lagom binary
directory detection logic from code generators, as now both projects
directories enter the generator logic from the same place.
This commit is contained in:
Andrew Kaster 2022-10-13 20:14:36 -06:00 committed by Linus Groh
parent a01c0e81f3
commit 1ae0cfd08b
12 changed files with 217 additions and 461 deletions

View file

@ -1,24 +1,12 @@
function (generate_css_implementation)
if (CMAKE_CURRENT_BINARY_DIR MATCHES ".*/LibWeb")
# Serenity build
SET(LIBWEB_INPUT_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}")
SET(LIBWEB_OUTPUT_FOLDER "")
SET(LIBWEB_META_PREFIX "")
else()
# Lagom Build
SET(LIBWEB_INPUT_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibWeb")
SET(LIBWEB_OUTPUT_FOLDER "LibWeb/")
SET(LIBWEB_META_PREFIX "Lagom")
endif()
set(LIBWEB_INPUT_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}")
invoke_generator(
"Enums.cpp"
Lagom::GenerateCSSEnums
"${LIBWEB_INPUT_FOLDER}/CSS/Enums.json"
"${LIBWEB_META_PREFIX}"
"${LIBWEB_OUTPUT_FOLDER}CSS/Enums.h"
"${LIBWEB_OUTPUT_FOLDER}CSS/Enums.cpp"
""
"CSS/Enums.h"
"CSS/Enums.cpp"
arguments -j "${LIBWEB_INPUT_FOLDER}/CSS/Enums.json"
)
@ -26,9 +14,9 @@ function (generate_css_implementation)
"MediaFeatureID.cpp"
Lagom::GenerateCSSMediaFeatureID
"${LIBWEB_INPUT_FOLDER}/CSS/MediaFeatures.json"
"${LIBWEB_META_PREFIX}"
"${LIBWEB_OUTPUT_FOLDER}CSS/MediaFeatureID.h"
"${LIBWEB_OUTPUT_FOLDER}CSS/MediaFeatureID.cpp"
""
"CSS/MediaFeatureID.h"
"CSS/MediaFeatureID.cpp"
arguments -j "${LIBWEB_INPUT_FOLDER}/CSS/MediaFeatures.json"
)
@ -36,9 +24,9 @@ function (generate_css_implementation)
"PropertyID.cpp"
Lagom::GenerateCSSPropertyID
"${LIBWEB_INPUT_FOLDER}/CSS/Properties.json"
"${LIBWEB_META_PREFIX}"
"${LIBWEB_OUTPUT_FOLDER}CSS/PropertyID.h"
"${LIBWEB_OUTPUT_FOLDER}CSS/PropertyID.cpp"
""
"CSS/PropertyID.h"
"CSS/PropertyID.cpp"
arguments -j "${LIBWEB_INPUT_FOLDER}/CSS/Properties.json"
)
@ -46,9 +34,9 @@ function (generate_css_implementation)
"TransformFunctions.cpp"
Lagom::GenerateCSSTransformFunctions
"${LIBWEB_INPUT_FOLDER}/CSS/TransformFunctions.json"
"${LIBWEB_META_PREFIX}"
"${LIBWEB_OUTPUT_FOLDER}CSS/TransformFunctions.h"
"${LIBWEB_OUTPUT_FOLDER}CSS/TransformFunctions.cpp"
""
"CSS/TransformFunctions.h"
"CSS/TransformFunctions.cpp"
arguments -j "${LIBWEB_INPUT_FOLDER}/CSS/TransformFunctions.json"
)
@ -56,62 +44,50 @@ function (generate_css_implementation)
"ValueID.cpp"
Lagom::GenerateCSSValueID
"${LIBWEB_INPUT_FOLDER}/CSS/Identifiers.json"
"${LIBWEB_META_PREFIX}"
"${LIBWEB_OUTPUT_FOLDER}CSS/ValueID.h"
"${LIBWEB_OUTPUT_FOLDER}CSS/ValueID.cpp"
""
"CSS/ValueID.h"
"CSS/ValueID.cpp"
arguments -j "${LIBWEB_INPUT_FOLDER}/CSS/Identifiers.json"
)
add_custom_command(
OUTPUT ${LIBWEB_OUTPUT_FOLDER}CSS/DefaultStyleSheetSource.cpp
COMMAND "${CMAKE_COMMAND}" -E make_directory ${LIBWEB_OUTPUT_FOLDER}CSS
COMMAND "${LIBWEB_INPUT_FOLDER}/Scripts/GenerateStyleSheetSource.sh" default_stylesheet_source "${LIBWEB_INPUT_FOLDER}/CSS/Default.css" > ${LIBWEB_OUTPUT_FOLDER}CSS/DefaultStyleSheetSource.cpp.tmp
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${LIBWEB_OUTPUT_FOLDER}CSS/DefaultStyleSheetSource.cpp.tmp ${LIBWEB_OUTPUT_FOLDER}CSS/DefaultStyleSheetSource.cpp
COMMAND "${CMAKE_COMMAND}" -E remove ${LIBWEB_OUTPUT_FOLDER}CSS/DefaultStyleSheetSource.cpp.tmp
OUTPUT CSS/DefaultStyleSheetSource.cpp
COMMAND "${CMAKE_COMMAND}" -E make_directory CSS
COMMAND "${LIBWEB_INPUT_FOLDER}/Scripts/GenerateStyleSheetSource.sh" default_stylesheet_source "${LIBWEB_INPUT_FOLDER}/CSS/Default.css" > CSS/DefaultStyleSheetSource.cpp.tmp
COMMAND "${CMAKE_COMMAND}" -E copy_if_different CSS/DefaultStyleSheetSource.cpp.tmp CSS/DefaultStyleSheetSource.cpp
COMMAND "${CMAKE_COMMAND}" -E remove CSS/DefaultStyleSheetSource.cpp.tmp
VERBATIM
DEPENDS "${LIBWEB_INPUT_FOLDER}/Scripts/GenerateStyleSheetSource.sh"
MAIN_DEPENDENCY ${LIBWEB_INPUT_FOLDER}/CSS/Default.css
MAIN_DEPENDENCY "${LIBWEB_INPUT_FOLDER}/CSS/Default.css"
)
add_custom_target(generate_${LIBWEB_META_PREFIX}DefaultStyleSheetSource.cpp DEPENDS ${LIBWEB_OUTPUT_FOLDER}CSS/DefaultStyleSheetSource.cpp)
add_dependencies(all_generated generate_${LIBWEB_META_PREFIX}DefaultStyleSheetSource.cpp)
add_custom_target(generate_DefaultStyleSheetSource.cpp DEPENDS CSS/DefaultStyleSheetSource.cpp)
add_dependencies(all_generated generate_DefaultStyleSheetSource.cpp)
add_custom_command(
OUTPUT ${LIBWEB_OUTPUT_FOLDER}CSS/QuirksModeStyleSheetSource.cpp
COMMAND "${CMAKE_COMMAND}" -E make_directory ${LIBWEB_OUTPUT_FOLDER}CSS
COMMAND "${LIBWEB_INPUT_FOLDER}/Scripts/GenerateStyleSheetSource.sh" quirks_mode_stylesheet_source "${LIBWEB_INPUT_FOLDER}/CSS/QuirksMode.css" > ${LIBWEB_OUTPUT_FOLDER}CSS/QuirksModeStyleSheetSource.cpp.tmp
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${LIBWEB_OUTPUT_FOLDER}CSS/QuirksModeStyleSheetSource.cpp.tmp ${LIBWEB_OUTPUT_FOLDER}CSS/QuirksModeStyleSheetSource.cpp
COMMAND "${CMAKE_COMMAND}" -E remove ${LIBWEB_OUTPUT_FOLDER}CSS/QuirksModeStyleSheetSource.cpp.tmp
OUTPUT CSS/QuirksModeStyleSheetSource.cpp
COMMAND "${CMAKE_COMMAND}" -E make_directory CSS
COMMAND "${LIBWEB_INPUT_FOLDER}/Scripts/GenerateStyleSheetSource.sh" quirks_mode_stylesheet_source "${LIBWEB_INPUT_FOLDER}/CSS/QuirksMode.css" > CSS/QuirksModeStyleSheetSource.cpp.tmp
COMMAND "${CMAKE_COMMAND}" -E copy_if_different CSS/QuirksModeStyleSheetSource.cpp.tmp CSS/QuirksModeStyleSheetSource.cpp
COMMAND "${CMAKE_COMMAND}" -E remove CSS/QuirksModeStyleSheetSource.cpp.tmp
VERBATIM
DEPENDS "${LIBWEB_INPUT_FOLDER}/Scripts/GenerateStyleSheetSource.sh"
MAIN_DEPENDENCY ${LIBWEB_INPUT_FOLDER}/CSS/Default.css
MAIN_DEPENDENCY "${LIBWEB_INPUT_FOLDER}/CSS/Default.css"
)
add_custom_target(generate_${LIBWEB_META_PREFIX}QuirksModeStyleSheetSource.cpp DEPENDS ${LIBWEB_OUTPUT_FOLDER}CSS/QuirksModeStyleSheetSource.cpp)
add_dependencies(all_generated generate_${LIBWEB_META_PREFIX}QuirksModeStyleSheetSource.cpp)
add_custom_target(generate_QuirksModeStyleSheetSource.cpp DEPENDS CSS/QuirksModeStyleSheetSource.cpp)
add_dependencies(all_generated generate_QuirksModeStyleSheetSource.cpp)
endfunction()
function (generate_js_bindings target)
if (CMAKE_CURRENT_BINARY_DIR MATCHES ".*/LibWeb")
# Serenity build
SET(LIBWEB_INPUT_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}")
SET(LIBWEB_OUTPUT_FOLDER "")
SET(LIBWEB_META_PREFIX "")
else()
# Lagom Build
SET(LIBWEB_INPUT_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/../../Userland/Libraries/LibWeb")
SET(LIBWEB_OUTPUT_FOLDER "LibWeb/")
SET(LIBWEB_META_PREFIX "Lagom")
endif()
set(LIBWEB_INPUT_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}")
function(libweb_js_bindings class)
cmake_parse_arguments(PARSE_ARGV 1 LIBWEB_BINDINGS "ITERABLE" "" "")
get_filename_component(basename "${class}" NAME)
set(BINDINGS_SOURCES
"${LIBWEB_OUTPUT_FOLDER}Bindings/${basename}Constructor.h"
"${LIBWEB_OUTPUT_FOLDER}Bindings/${basename}Constructor.cpp"
"${LIBWEB_OUTPUT_FOLDER}Bindings/${basename}Prototype.h"
"${LIBWEB_OUTPUT_FOLDER}Bindings/${basename}Prototype.cpp"
"Bindings/${basename}Constructor.h"
"Bindings/${basename}Constructor.cpp"
"Bindings/${basename}Prototype.h"
"Bindings/${basename}Prototype.cpp"
)
set(BINDINGS_TYPES
constructor-header
@ -123,8 +99,8 @@ function (generate_js_bindings target)
# FIXME: Instead of requiring a manual declaration of iterable bindings, we should ask BindingsGenerator if it's iterable
if(LIBWEB_BINDINGS_ITERABLE)
list(APPEND BINDINGS_SOURCES
"${LIBWEB_OUTPUT_FOLDER}Bindings/${basename}IteratorPrototype.h"
"${LIBWEB_OUTPUT_FOLDER}Bindings/${basename}IteratorPrototype.cpp"
"Bindings/${basename}IteratorPrototype.h"
"Bindings/${basename}IteratorPrototype.cpp"
)
list(APPEND BINDINGS_TYPES
iterator-prototype-header
@ -147,16 +123,16 @@ function (generate_js_bindings target)
COMMAND "${CMAKE_COMMAND}" -E remove "${bindings_src}.tmp"
VERBATIM
DEPENDS Lagom::BindingsGenerator
MAIN_DEPENDENCY ${LIBWEB_INPUT_FOLDER}/${class}.idl
MAIN_DEPENDENCY ${class}.idl
)
endforeach()
add_custom_target(generate_${basename}Constructor.h DEPENDS ${LIBWEB_OUTPUT_FOLDER}Bindings/${basename}Constructor.h)
add_custom_target(generate_${basename}Constructor.h DEPENDS Bindings/${basename}Constructor.h)
add_dependencies(all_generated generate_${basename}Constructor.h)
add_custom_target(generate_${basename}Constructor.cpp DEPENDS ${LIBWEB_OUTPUT_FOLDER}Bindings/${basename}Constructor.cpp)
add_custom_target(generate_${basename}Constructor.cpp DEPENDS Bindings/${basename}Constructor.cpp)
add_dependencies(all_generated generate_${basename}Constructor.cpp)
add_custom_target(generate_${basename}Prototype.h DEPENDS ${LIBWEB_OUTPUT_FOLDER}Bindings/${basename}Prototype.h)
add_custom_target(generate_${basename}Prototype.h DEPENDS Bindings/${basename}Prototype.h)
add_dependencies(all_generated generate_${basename}Prototype.h)
add_custom_target(generate_${basename}Prototype.cpp DEPENDS ${LIBWEB_OUTPUT_FOLDER}Bindings/${basename}Prototype.cpp)
add_custom_target(generate_${basename}Prototype.cpp DEPENDS Bindings/${basename}Prototype.cpp)
add_dependencies(all_generated generate_${basename}Prototype.cpp)
list(APPEND LIBWEB_ALL_IDL_FILES "${LIBWEB_INPUT_FOLDER}/${class}.idl")
@ -167,27 +143,27 @@ function (generate_js_bindings target)
set(exposed_interface_sources DedicatedWorkerExposedInterfaces.cpp DedicatedWorkerExposedInterfaces.h
SharedWorkerExposedInterfaces.cpp SharedWorkerExposedInterfaces.h
WindowExposedInterfaces.cpp WindowExposedInterfaces.h)
list(TRANSFORM exposed_interface_sources PREPEND "${LIBWEB_OUTPUT_FOLDER}Bindings/")
list(TRANSFORM exposed_interface_sources PREPEND "Bindings/")
add_custom_command(
OUTPUT ${exposed_interface_sources}
COMMAND "${CMAKE_COMMAND}" -E make_directory "tmp"
COMMAND $<TARGET_FILE:Lagom::GenerateWindowOrWorkerInterfaces> -o "${CMAKE_CURRENT_BINARY_DIR}/tmp" -b "${LIBWEB_INPUT_FOLDER}" ${LIBWEB_ALL_IDL_FILES}
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/DedicatedWorkerExposedInterfaces.h "${LIBWEB_OUTPUT_FOLDER}Bindings/DedicatedWorkerExposedInterfaces.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/DedicatedWorkerExposedInterfaces.cpp "${LIBWEB_OUTPUT_FOLDER}Bindings/DedicatedWorkerExposedInterfaces.cpp"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/SharedWorkerExposedInterfaces.h "${LIBWEB_OUTPUT_FOLDER}Bindings/SharedWorkerExposedInterfaces.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/SharedWorkerExposedInterfaces.cpp "${LIBWEB_OUTPUT_FOLDER}Bindings/SharedWorkerExposedInterfaces.cpp"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/WindowExposedInterfaces.h "${LIBWEB_OUTPUT_FOLDER}Bindings/WindowExposedInterfaces.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/WindowExposedInterfaces.cpp "${LIBWEB_OUTPUT_FOLDER}Bindings/WindowExposedInterfaces.cpp"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/DedicatedWorkerExposedInterfaces.h "Bindings/DedicatedWorkerExposedInterfaces.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/DedicatedWorkerExposedInterfaces.cpp "Bindings/DedicatedWorkerExposedInterfaces.cpp"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/SharedWorkerExposedInterfaces.h "Bindings/SharedWorkerExposedInterfaces.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/SharedWorkerExposedInterfaces.cpp "Bindings/SharedWorkerExposedInterfaces.cpp"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/WindowExposedInterfaces.h "Bindings/WindowExposedInterfaces.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/WindowExposedInterfaces.cpp "Bindings/WindowExposedInterfaces.cpp"
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/tmp"
VERBATIM
DEPENDS Lagom::GenerateWindowOrWorkerInterfaces ${LIBWEB_ALL_IDL_FILES}
)
target_sources(${target} PRIVATE ${exposed_interface_sources})
add_custom_target("generate_${LIBWEB_META_PREFIX}exposed_interfaces" DEPENDS ${exposed_interface_sources})
add_dependencies(all_generated "generate_${LIBWEB_META_PREFIX}exposed_interfaces")
add_custom_target("generate_exposed_interfaces" DEPENDS ${exposed_interface_sources})
add_dependencies(all_generated "generate_exposed_interfaces")
endfunction()
include("${LIBWEB_INPUT_FOLDER}/idl_files.cmake")
include("idl_files.cmake")
generate_exposed_interface_files()
endfunction()