mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 08:15:06 +00:00

As many macros as possible are moved to Macros.h, while the macros to create a test case are moved to TestCase.h. TestCase is now the only user-facing header for creating a test case. TestSuite and its helpers have moved into a .cpp file. Instead of requiring a TEST_MAIN macro to be instantiated into the test file, a TestMain.cpp file is provided instead that will be linked against each test. This has the side effect that, if we wanted to have test cases split across multiple files, it's as simple as adding them all to the same executable. The test main should be portable to kernel mode as well, so if there's a set of tests that should be run in self-test mode in kernel space, we can accomodate that. A new serenity_test CMake function streamlines adding a new test with arguments for the test source file, subdirectory under /usr/Tests to install the test application and an optional list of libraries to link against the test application. To accomodate future test where the provided TestMain.cpp is not suitable (e.g. test-js), a CUSTOM_MAIN parameter can be passed to the function to not link against the boilerplate main function.
156 lines
6.5 KiB
CMake
156 lines
6.5 KiB
CMake
include(${CMAKE_SOURCE_DIR}/Meta/CMake/precompile-headers.cmake)
|
|
|
|
function(serenity_install_headers target_name)
|
|
file(GLOB_RECURSE headers RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
|
|
foreach(header ${headers})
|
|
get_filename_component(subdirectory ${header} DIRECTORY)
|
|
install(FILES ${header} DESTINATION usr/include/${target_name}/${subdirectory})
|
|
endforeach()
|
|
endfunction()
|
|
|
|
function(serenity_install_sources target_name)
|
|
file(GLOB_RECURSE sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.cpp")
|
|
foreach(source ${sources})
|
|
get_filename_component(subdirectory ${source} DIRECTORY)
|
|
install(FILES ${source} DESTINATION usr/src/serenity/${target_name}/${subdirectory})
|
|
endforeach()
|
|
endfunction()
|
|
|
|
function(serenity_generated_sources target_name)
|
|
if(DEFINED GENERATED_SOURCES)
|
|
set_source_files_properties(${GENERATED_SOURCES} PROPERTIES GENERATED 1)
|
|
foreach(generated ${GENERATED_SOURCES})
|
|
get_filename_component(generated_name ${generated} NAME)
|
|
add_dependencies(${target_name} generate_${generated_name})
|
|
endforeach()
|
|
endif()
|
|
endfunction()
|
|
|
|
function(serenity_lib target_name fs_name)
|
|
serenity_install_headers(${target_name})
|
|
serenity_install_sources("Userland/Libraries/${target_name}")
|
|
add_library(${target_name} SHARED ${SOURCES} ${GENERATED_SOURCES})
|
|
install(TARGETS ${target_name} DESTINATION usr/lib)
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
|
serenity_add_ak_precompiled_headers_to_target(${target_name})
|
|
serenity_generated_sources(${target_name})
|
|
endfunction()
|
|
|
|
function(serenity_shared_lib target_name fs_name)
|
|
serenity_install_headers(${target_name})
|
|
serenity_install_sources("Userland/Libraries/${target_name}")
|
|
add_library(${target_name} SHARED ${SOURCES} ${GENERATED_SOURCES})
|
|
install(TARGETS ${target_name} DESTINATION usr/lib)
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
|
serenity_generated_sources(${target_name})
|
|
endfunction()
|
|
|
|
function(serenity_libc target_name fs_name)
|
|
serenity_install_headers("")
|
|
serenity_install_sources("Userland/Libraries/LibC")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib -fpic")
|
|
add_library(${target_name} SHARED ${SOURCES})
|
|
install(TARGETS ${target_name} DESTINATION usr/lib)
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
|
target_link_directories(LibC PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
|
serenity_generated_sources(${target_name})
|
|
endfunction()
|
|
|
|
function(serenity_libc_static target_name fs_name)
|
|
serenity_install_headers("")
|
|
serenity_install_sources("Userland/Libraries/LibC")
|
|
add_library(${target_name} ${SOURCES})
|
|
install(TARGETS ${target_name} ARCHIVE DESTINATION usr/lib)
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
|
target_link_directories(${target_name} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
|
serenity_generated_sources(${target_name})
|
|
endfunction()
|
|
|
|
function(serenity_bin target_name)
|
|
add_executable(${target_name} ${SOURCES})
|
|
install(TARGETS ${target_name} RUNTIME DESTINATION bin)
|
|
serenity_add_ak_precompiled_headers_to_target(${target_name})
|
|
serenity_generated_sources(${target_name})
|
|
endfunction()
|
|
|
|
function(serenity_test test_src sub_dir)
|
|
cmake_parse_arguments(SERENITY_TEST "CUSTOM_MAIN" "" "LIBS" ${ARGN})
|
|
set(TEST_SOURCES ${test_src})
|
|
if (NOT ${SERENITY_TEST_CUSTOM_MAIN})
|
|
list(APPEND TEST_SOURCES "${CMAKE_SOURCE_DIR}/Userland/Libraries/LibTest/TestMain.cpp")
|
|
endif()
|
|
get_filename_component(test_name ${test_src} NAME_WE)
|
|
add_executable(${test_name} ${TEST_SOURCES})
|
|
target_link_libraries(${test_name} LibTest LibCore)
|
|
foreach(lib ${SERENITY_TEST_LIBS})
|
|
target_link_libraries(${test_name} ${lib})
|
|
endforeach()
|
|
install(TARGETS ${test_name} RUNTIME DESTINATION usr/Tests/${sub_dir})
|
|
endfunction()
|
|
|
|
function(serenity_app target_name)
|
|
cmake_parse_arguments(SERENITY_APP "" "ICON" "" ${ARGN})
|
|
|
|
serenity_bin("${target_name}")
|
|
set(small_icon "${CMAKE_SOURCE_DIR}/Base/res/icons/16x16/${SERENITY_APP_ICON}.png")
|
|
set(medium_icon "${CMAKE_SOURCE_DIR}/Base/res/icons/32x32/${SERENITY_APP_ICON}.png")
|
|
|
|
if (EXISTS "${small_icon}")
|
|
embed_resource("${target_name}" serenity_icon_s "${small_icon}")
|
|
else()
|
|
message(WARNING "Missing small app icon: ${small_icon}")
|
|
endif()
|
|
|
|
if (EXISTS "${medium_icon}")
|
|
embed_resource("${target_name}" serenity_icon_m "${medium_icon}")
|
|
else()
|
|
# These icons are designed small only for use in applets, and thus are exempt.
|
|
list(APPEND allowed_missing_medium_icons "audio-volume-high")
|
|
list(APPEND allowed_missing_medium_icons "edit-copy")
|
|
|
|
if (NOT ${SERENITY_APP_ICON} IN_LIST allowed_missing_medium_icons)
|
|
message(WARNING "Missing medium app icon: ${medium_icon}")
|
|
endif()
|
|
endif()
|
|
endfunction()
|
|
|
|
function(compile_gml source output string_name)
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
|
|
add_custom_command(
|
|
OUTPUT ${output}
|
|
COMMAND ${write_if_different} ${output} ${CMAKE_SOURCE_DIR}/Meta/text-to-cpp-string.sh ${string_name} ${source}
|
|
VERBATIM
|
|
DEPENDS ${CMAKE_SOURCE_DIR}/Meta/text-to-cpp-string.sh
|
|
MAIN_DEPENDENCY ${source}
|
|
)
|
|
get_filename_component(output_name ${output} NAME)
|
|
add_custom_target(generate_${output_name} DEPENDS ${output})
|
|
endfunction()
|
|
|
|
|
|
function(compile_ipc source output)
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
|
|
add_custom_command(
|
|
OUTPUT ${output}
|
|
COMMAND ${write_if_different} ${output} ${CMAKE_BINARY_DIR}/Userland/DevTools/IPCCompiler/IPCCompiler ${source}
|
|
VERBATIM
|
|
DEPENDS IPCCompiler
|
|
MAIN_DEPENDENCY ${source}
|
|
)
|
|
get_filename_component(output_name ${output} NAME)
|
|
add_custom_target(generate_${output_name} DEPENDS ${output})
|
|
endfunction()
|
|
|
|
function(embed_resource target section file)
|
|
get_filename_component(asm_file "${file}" NAME)
|
|
set(asm_file "${CMAKE_CURRENT_BINARY_DIR}/${target}-${section}.s")
|
|
get_filename_component(input_file "${file}" ABSOLUTE)
|
|
file(SIZE "${input_file}" file_size)
|
|
add_custom_command(
|
|
OUTPUT "${asm_file}"
|
|
COMMAND "${CMAKE_SOURCE_DIR}/Meta/generate-embedded-resource-assembly.sh" "${asm_file}" "${section}" "${input_file}" "${file_size}"
|
|
DEPENDS "${input_file}" "${CMAKE_SOURCE_DIR}/Meta/generate-embedded-resource-assembly.sh"
|
|
COMMENT "Generating ${asm_file}"
|
|
)
|
|
target_sources("${target}" PRIVATE "${asm_file}")
|
|
endfunction()
|