mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
CMake: Export targets for Clang Plugins so they can be used by Serenity
This commit is contained in:
parent
5194ab59b5
commit
d51c96d56d
Notes:
sideshowbarker
2024-07-17 06:40:21 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/d51c96d56d Pull-request: https://github.com/SerenityOS/serenity/pull/24322
5 changed files with 49 additions and 32 deletions
12
Meta/CMake/clang_development.cmake
Normal file
12
Meta/CMake/clang_development.cmake
Normal file
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# Finds clang and llvm development packages that match the current clang version
|
||||
#
|
||||
|
||||
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(DESIRED_CLANG_VERSION "${CMAKE_CXX_COMPILER_VERSION}")
|
||||
|
||||
find_package(Clang "${DESIRED_CLANG_VERSION}" QUIET REQUIRED CONFIG)
|
||||
find_package(LLVM "${DESIRED_CLANG_VERSION}" QUIET REQUIRED CONFIG)
|
|
@ -237,3 +237,22 @@ function(extract_path dest_dir zip_path source_path dest_path)
|
|||
file(ARCHIVE_EXTRACT INPUT "${zip_path}" DESTINATION "${dest_dir}" PATTERNS "${source_path}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(add_lagom_library_install_rules target_name)
|
||||
cmake_parse_arguments(PARSE_ARGV 1 LAGOM_INSTALL_RULES "" "ALIAS_NAME" "")
|
||||
if (NOT LAGOM_INSTALL_RULES_ALIAS_NAME)
|
||||
set(LAGOM_INSTALL_RULES_ALIAS_NAME ${target_name})
|
||||
endif()
|
||||
# Don't make alias when we're going to import a previous build for Tools
|
||||
# FIXME: Is there a better way to write this?
|
||||
if (NOT ENABLE_FUZZERS AND NOT CMAKE_CROSSCOMPILING)
|
||||
# alias for parity with exports
|
||||
add_library(Lagom::${LAGOM_INSTALL_RULES_ALIAS_NAME} ALIAS ${target_name})
|
||||
endif()
|
||||
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()
|
||||
|
|
|
@ -137,8 +137,6 @@ CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSEAUDIO)
|
|||
|
||||
add_library(JSClangPlugin INTERFACE)
|
||||
add_library(GenericClangPlugin INTERFACE)
|
||||
# These need to be installed to avoid CMake complaining about them not being in the export set
|
||||
install(TARGETS GenericClangPlugin JSClangPlugin EXPORT LagomTargets)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
||||
add_compile_options(-Wno-overloaded-virtual)
|
||||
|
@ -152,7 +150,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
|||
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=fuzzer")
|
||||
endif()
|
||||
|
||||
if (ENABLE_CLANG_PLUGINS)
|
||||
# Vanilla host builds only for building the clang plugins
|
||||
if (ENABLE_CLANG_PLUGINS AND NOT CROSS_COMPILING AND NOT ENABLE_FUZZERS AND NOT ENABLE_COMPILER_EXPLORER_BUILD)
|
||||
add_subdirectory(ClangPlugins)
|
||||
depend_on_clang_plugin(JSClangPlugin LibJSGCClangPlugin)
|
||||
depend_on_clang_plugin(GenericClangPlugin LambdaCaptureClangPlugin)
|
||||
|
@ -219,13 +218,6 @@ function(lagom_lib target_name fs_name)
|
|||
set(LAGOM_LIBRARY_LIBRARY_TYPE "")
|
||||
endif()
|
||||
add_library(${target_name} ${LAGOM_LIBRARY_LIBRARY_TYPE} ${LAGOM_LIBRARY_SOURCES})
|
||||
# Don't make alias when we're going to import a previous build for Tools
|
||||
# FIXME: Is there a better way to write this?
|
||||
if (NOT ENABLE_FUZZERS AND NOT CMAKE_CROSSCOMPILING)
|
||||
# alias for parity with exports
|
||||
add_library(Lagom::${library} ALIAS ${target_name})
|
||||
endif()
|
||||
|
||||
set_target_properties(
|
||||
${target_name} PROPERTIES
|
||||
VERSION "${PROJECT_VERSION}"
|
||||
|
@ -246,19 +238,7 @@ function(lagom_lib target_name fs_name)
|
|||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/Userland/Libraries>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/Userland/Services>
|
||||
)
|
||||
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}
|
||||
)
|
||||
add_lagom_library_install_rules(${target_name} ALIAS_NAME ${library})
|
||||
# FIXME: Move this to serenity_install_headers
|
||||
install(
|
||||
DIRECTORY "${SERENITY_PROJECT_ROOT}/Userland/Libraries/Lib${library}"
|
||||
|
@ -340,6 +320,10 @@ if (NOT TARGET all_generated)
|
|||
add_custom_target(all_generated)
|
||||
endif()
|
||||
|
||||
# Plugins need to be installed in order to be used by non-lagom builds
|
||||
add_lagom_library_install_rules(GenericClangPlugin)
|
||||
add_lagom_library_install_rules(JSClangPlugin)
|
||||
|
||||
# Create mostly empty targets for system libraries we don't need to build for Lagom
|
||||
add_library(LibC INTERFACE)
|
||||
add_library(LibCrypt INTERFACE)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
find_package(Clang 17 CONFIG REQUIRED)
|
||||
include(clang_development)
|
||||
|
||||
function(clang_plugin target_name)
|
||||
cmake_parse_arguments(CLANG_PLUGIN "" "" "SOURCES" ${ARGN})
|
||||
add_library(${target_name} ${CLANG_PLUGIN_SOURCES})
|
||||
install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
target_include_directories(${target_name} SYSTEM PRIVATE ${CLANG_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS})
|
||||
target_compile_features(${target_name} PRIVATE cxx_std_20)
|
||||
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Werror -Wno-unused -fno-rtti)
|
||||
|
@ -11,12 +10,16 @@ function(clang_plugin target_name)
|
|||
add_custom_target(${target_name}Target DEPENDS ${target_name})
|
||||
|
||||
set_property(GLOBAL APPEND PROPERTY CLANG_PLUGINS_ALL_COMPILE_OPTIONS -fplugin=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/lib${target_name}.so)
|
||||
|
||||
add_lagom_library_install_rules(${target_name})
|
||||
endfunction()
|
||||
|
||||
function(depend_on_clang_plugin target_name plugin_name)
|
||||
if (TARGET ${plugin_name}Target)
|
||||
add_dependencies(${target_name} ${plugin_name}Target)
|
||||
endif()
|
||||
target_compile_options(${target_name} INTERFACE -fplugin=$<TARGET_FILE:Lagom::${plugin_name}>)
|
||||
endfunction()
|
||||
|
||||
clang_plugin(LambdaCaptureClangPlugin SOURCES LambdaCapturePluginAction.cpp)
|
||||
clang_plugin(LibJSGCClangPlugin SOURCES LibJSGCPluginAction.cpp)
|
||||
|
||||
function(depend_on_clang_plugin target_name plugin_name)
|
||||
add_dependencies(${target_name} ${plugin_name}Target)
|
||||
target_compile_options(${target_name} INTERFACE -fplugin=$<TARGET_FILE:${plugin_name}>)
|
||||
endfunction()
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
find_package(Clang 17 CONFIG REQUIRED)
|
||||
find_package(LLVM 17 CONFIG REQUIRED)
|
||||
include(clang_development)
|
||||
include(AddLLVM)
|
||||
|
||||
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
||||
|
|
Loading…
Reference in a new issue