Lagom: Add ClangPlugins to the build system

This commit is contained in:
Matthew Olsson 2024-04-15 18:50:49 -07:00 committed by Andrew Kaster
parent c3ed1a7995
commit 4ae7bbda52
Notes: sideshowbarker 2024-07-17 03:03:15 +09:00
9 changed files with 34 additions and 1 deletions

View file

@ -264,3 +264,6 @@ if (ENABLE_USB_IDS_DOWNLOAD AND NOT EXISTS "${USB_IDS_INSTALL_PATH}/${USB_IDS_FI
download_file("${USB_IDS_URL}" "${USB_IDS_DOWNLOAD_PATH}")
install(FILES "${USB_IDS_DOWNLOAD_PATH}" DESTINATION "${USB_IDS_INSTALL_PATH}")
endif()
add_library(GenericClangPlugin INTERFACE)
add_library(JSClangPlugin INTERFACE)

View file

@ -798,9 +798,11 @@ add_link_options(LINKER:-z,notext)
add_library(kernel_heap STATIC ${KERNEL_HEAP_SOURCES})
add_dependencies(kernel_heap install_libc_headers)
target_link_libraries(kernel_heap PUBLIC GenericClangPlugin)
add_executable(Kernel ${SOURCES})
add_dependencies(Kernel generate_EscapeSequenceStateMachine.h generate_version_header install_libc_headers)
target_link_libraries(Kernel PUBLIC GenericClangPlugin)
if("${SERENITY_ARCH}" STREQUAL "aarch64")
target_link_options(Kernel PRIVATE LINKER:-T ${CMAKE_CURRENT_SOURCE_DIR}/Arch/aarch64/linker.ld -nostdlib LINKER:--no-pie)

View file

@ -22,6 +22,7 @@ target_compile_options(${PREKERNEL_TARGET} PRIVATE -no-pie -fno-pic -fno-threads
target_link_options(${PREKERNEL_TARGET} PRIVATE LINKER:-T ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld -nostdlib LINKER:--no-pie)
set_target_properties(${PREKERNEL_TARGET} PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld)
target_link_libraries(${PREKERNEL_TARGET} PUBLIC GenericClangPlugin)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(${PREKERNEL_TARGET} PRIVATE gcc)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang$")

View file

@ -31,3 +31,5 @@ serenity_option(JAKT_SOURCE_DIR "" CACHE STRING "Pre-existing jakt language sour
serenity_option(SERENITY_CACHE_DIR "${PROJECT_BINARY_DIR}/../caches" CACHE PATH "Location of shared cache of downloaded files")
serenity_option(ENABLE_NETWORK_DOWNLOADS ON CACHE BOOL "Allow downloads of required files. If OFF, required files must already be present in SERENITY_CACHE_DIR")
serenity_option(ENABLE_CLANG_PLUGINS OFF CACHE BOOL "Enable building with the Clang plugins")

View file

@ -52,6 +52,7 @@ if (NOT COMMAND serenity_lib)
add_library(${target_name} ${SERENITY_LIB_TYPE} ${SOURCES} ${GENERATED_SOURCES})
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
set_target_properties(${target_name} PROPERTIES VERSION "serenity")
target_link_libraries(${target_name} PUBLIC GenericClangPlugin)
install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL)
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
serenity_generated_sources(${target_name})
@ -80,6 +81,7 @@ if (NOT COMMAND serenity_bin)
function(serenity_bin target_name)
serenity_install_sources()
add_executable(${target_name} ${SOURCES})
target_link_libraries(${target_name} PUBLIC GenericClangPlugin)
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
install(TARGETS ${target_name} RUNTIME DESTINATION bin OPTIONAL)
serenity_generated_sources(${target_name})

View file

@ -135,6 +135,11 @@ endif()
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)
# FIXME: Re-enable this check when the warning stops triggering, or document why we can't stop it from triggering.
@ -147,6 +152,11 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=fuzzer")
endif()
if (ENABLE_CLANG_PLUGINS)
add_subdirectory(ClangPlugins)
depend_on_clang_plugin(JSClangPlugin LibJSGCClangPlugin)
depend_on_clang_plugin(GenericClangPlugin LambdaCaptureClangPlugin)
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (ENABLE_FUZZERS_LIBFUZZER)
message(FATAL_ERROR
@ -224,6 +234,7 @@ function(lagom_lib target_name fs_name)
OUTPUT_NAME lagom-${fs_name}
)
target_link_libraries(${target_name} PRIVATE ${LAGOM_LIBRARY_LIBS})
target_link_libraries(${target_name} PUBLIC GenericClangPlugin)
if (NOT "${target_name}" STREQUAL "AK")
target_link_libraries(${target_name} PRIVATE AK)
@ -289,6 +300,7 @@ endfunction()
function(serenity_bin name)
add_executable(${name} ${SOURCES} ${GENERATED_SOURCES})
add_executable(Lagom::${name} ALIAS ${name})
target_link_libraries(${name} PUBLIC GenericClangPlugin)
install(
TARGETS ${target_name}
EXPORT LagomTargets
@ -630,6 +642,8 @@ if (BUILD_LAGOM)
OBJECT
"${SERENITY_PROJECT_ROOT}/Userland/Libraries/LibTest/TestMain.cpp"
)
target_link_libraries(LibTest PUBLIC GenericClangPlugin)
target_link_libraries(LibTestMain PUBLIC GenericClangPlugin)
# LibTest tests from Tests/
set(TEST_DIRECTORIES
@ -659,6 +673,9 @@ if (BUILD_LAGOM)
if (LINUX)
list(APPEND TEST_DIRECTORIES LibELF)
endif()
if (ENABLE_CLANG_PLUGINS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
list(APPEND TEST_DIRECTORIES ClangPlugins)
endif()
foreach (dir IN LISTS TEST_DIRECTORIES)
add_serenity_subdirectory("Tests/${dir}")

View file

@ -15,3 +15,8 @@ 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()

View file

@ -3,7 +3,7 @@ function(lagom_tool tool)
add_executable(${tool} ${SOURCES} ${LAGOM_TOOL_SOURCES})
# alias for parity with exports
add_executable(Lagom::${tool} ALIAS ${tool})
target_link_libraries(${tool} AK LibCoreMinimal LibFileSystem ${LAGOM_TOOL_LIBS})
target_link_libraries(${tool} AK LibCoreMinimal LibFileSystem GenericClangPlugin ${LAGOM_TOOL_LIBS})
install(
TARGETS ${tool}
EXPORT LagomTargets

View file

@ -282,3 +282,4 @@ if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i.86.*")
endif()
target_compile_options(LibJS PRIVATE -fno-omit-frame-pointer)
target_link_libraries(LibJS PUBLIC JSClangPlugin)