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

Meta: Use existing test-sources lists for Lagom instead of globbing

...mostly.

This creates and uses an override for the `serenity_test()` function, so
that Lagom can make use of the existing `Tests/LibFoo/CMakeLists.txt`
files instead of having to GLOB for test source files and manually copy
any data files.

Some GLOBs remain but this is most of them.

Co-authored-by: Andrew Kaster <akaster@serenityos.org>
This commit is contained in:
Sam Atkins 2023-01-16 15:35:40 +00:00 committed by Linus Groh
parent 73350b8492
commit 5ac57f9d41
2 changed files with 52 additions and 136 deletions

View file

@ -107,26 +107,28 @@ if (NOT COMMAND serenity_bin)
endfunction()
endif()
function(serenity_test test_src sub_dir)
cmake_parse_arguments(PARSE_ARGV 2 SERENITY_TEST "MAIN_ALREADY_DEFINED" "CUSTOM_MAIN" "LIBS")
set(TEST_SOURCES ${test_src})
if ("${SERENITY_TEST_CUSTOM_MAIN}" STREQUAL "")
set(SERENITY_TEST_CUSTOM_MAIN "$<TARGET_OBJECTS:LibTestMain>")
endif()
if (NOT ${SERENITY_TEST_MAIN_ALREADY_DEFINED})
list(PREPEND TEST_SOURCES "${SERENITY_TEST_CUSTOM_MAIN}")
endif()
get_filename_component(test_name ${test_src} NAME_WE)
add_executable(${test_name} ${TEST_SOURCES})
add_dependencies(ComponentTests ${test_name})
set_target_properties(${test_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
serenity_set_implicit_links(${test_name})
target_link_libraries(${test_name} PRIVATE LibTest LibCore)
foreach(lib ${SERENITY_TEST_LIBS})
target_link_libraries(${test_name} PRIVATE ${lib})
endforeach()
install(TARGETS ${test_name} RUNTIME DESTINATION usr/Tests/${sub_dir} OPTIONAL)
endfunction()
if (NOT COMMAND serenity_test)
function(serenity_test test_src sub_dir)
cmake_parse_arguments(PARSE_ARGV 2 SERENITY_TEST "MAIN_ALREADY_DEFINED" "CUSTOM_MAIN" "LIBS")
set(TEST_SOURCES ${test_src})
if ("${SERENITY_TEST_CUSTOM_MAIN}" STREQUAL "")
set(SERENITY_TEST_CUSTOM_MAIN "$<TARGET_OBJECTS:LibTestMain>")
endif()
if (NOT ${SERENITY_TEST_MAIN_ALREADY_DEFINED})
list(PREPEND TEST_SOURCES "${SERENITY_TEST_CUSTOM_MAIN}")
endif()
get_filename_component(test_name ${test_src} NAME_WE)
add_executable(${test_name} ${TEST_SOURCES})
add_dependencies(ComponentTests ${test_name})
set_target_properties(${test_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
serenity_set_implicit_links(${test_name})
target_link_libraries(${test_name} PRIVATE LibTest LibCore)
foreach(lib ${SERENITY_TEST_LIBS})
target_link_libraries(${test_name} PRIVATE ${lib})
endforeach()
install(TARGETS ${test_name} RUNTIME DESTINATION usr/Tests/${sub_dir} OPTIONAL)
endfunction()
endif()
function(serenity_testjs_test test_src sub_dir)
cmake_parse_arguments(PARSE_ARGV 2 SERENITY_TEST "" "CUSTOM_MAIN" "LIBS")