ladybird/Meta/Lagom/ClangPlugins/CMakeLists.txt
Matthew Olsson 5740f93ef4 ClangPlugins: Check for strong root fields in GC allocated objects
GC-allocated objects should never have JS::SafeFunction/JS::Handle
fields.

For now the plugin only emits warnings here, as there are many cases
of this occurring in the codebase that aren't trivial to fix. It is also
behind a CMake flag since it is a _very_ loud warning.
2024-05-30 09:29:20 -06:00

28 lines
1.3 KiB
CMake

include(clang_development)
function(clang_plugin target_name)
cmake_parse_arguments(CLANG_PLUGIN "" "" "SOURCES" ${ARGN})
add_library(${target_name} ${CLANG_PLUGIN_SOURCES})
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)
add_custom_target(${target_name}Target DEPENDS ${target_name})
set_property(GLOBAL APPEND PROPERTY CLANG_PLUGINS_COMPILE_OPTIONS_FOR_TESTS -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}>)
if (${ENABLE_CLANG_PLUGINS_INVALID_FUNCTION_MEMBERS})
target_compile_options(${target_name} INTERFACE -fplugin-arg-libjs_gc_scanner-detect-invalid-function-members)
endif()
endfunction()
clang_plugin(LambdaCaptureClangPlugin SOURCES LambdaCapturePluginAction.cpp)
clang_plugin(LibJSGCClangPlugin SOURCES LibJSGCPluginAction.cpp)