2021-08-07 23:11:02 +00:00
|
|
|
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/serenity_components.cmake)
|
2021-08-07 23:37:09 +00:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/code_generators.cmake)
|
2021-08-07 23:11:02 +00:00
|
|
|
|
2020-12-23 17:07:22 +00:00
|
|
|
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)
|
2021-06-15 13:07:25 +00:00
|
|
|
install(FILES ${header} DESTINATION usr/include/${target_name}/${subdirectory} OPTIONAL)
|
2020-12-23 17:07:22 +00:00
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
2021-11-26 13:53:46 +00:00
|
|
|
function(serenity_install_sources)
|
2022-03-19 15:15:08 +00:00
|
|
|
# TODO: Use cmake_path() when we upgrade the minimum CMake version to 3.20
|
|
|
|
# https://cmake.org/cmake/help/v3.23/command/cmake_path.html#relative-path
|
2021-11-26 13:53:46 +00:00
|
|
|
string(LENGTH ${SerenityOS_SOURCE_DIR} root_source_dir_length)
|
|
|
|
string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${root_source_dir_length} -1 current_source_dir_relative)
|
2020-12-23 17:07:22 +00:00
|
|
|
file(GLOB_RECURSE sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.cpp")
|
|
|
|
foreach(source ${sources})
|
|
|
|
get_filename_component(subdirectory ${source} DIRECTORY)
|
2021-11-26 13:53:46 +00:00
|
|
|
install(FILES ${source} DESTINATION usr/src/serenity/${current_source_dir_relative}/${subdirectory} OPTIONAL)
|
2020-12-23 17:07:22 +00:00
|
|
|
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})
|
2021-08-30 02:27:50 +00:00
|
|
|
add_dependencies(all_generated generate_${generated_name})
|
2020-12-23 17:07:22 +00:00
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(serenity_lib target_name fs_name)
|
|
|
|
serenity_install_headers(${target_name})
|
2021-11-26 13:53:46 +00:00
|
|
|
serenity_install_sources()
|
2020-12-20 20:32:10 +00:00
|
|
|
add_library(${target_name} SHARED ${SOURCES} ${GENERATED_SOURCES})
|
2021-06-15 13:07:25 +00:00
|
|
|
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
2021-10-31 16:38:01 +00:00
|
|
|
set_target_properties(${target_name} PROPERTIES VERSION "serenity")
|
2021-06-15 13:07:25 +00:00
|
|
|
install(TARGETS ${target_name} DESTINATION usr/lib OPTIONAL)
|
2020-12-23 17:07:22 +00:00
|
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
|
|
|
serenity_generated_sources(${target_name})
|
|
|
|
endfunction()
|
|
|
|
|
2022-03-23 00:36:47 +00:00
|
|
|
function(serenity_lib_static target_name fs_name)
|
|
|
|
serenity_install_headers(${target_name})
|
|
|
|
serenity_install_sources()
|
|
|
|
add_library(${target_name} STATIC ${SOURCES} ${GENERATED_SOURCES})
|
|
|
|
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
|
|
|
set_target_properties(${target_name} PROPERTIES VERSION "serenity")
|
|
|
|
install(TARGETS ${target_name} DESTINATION usr/lib OPTIONAL)
|
|
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
|
|
|
serenity_generated_sources(${target_name})
|
|
|
|
endfunction()
|
|
|
|
|
2020-12-23 17:07:22 +00:00
|
|
|
function(serenity_libc target_name fs_name)
|
|
|
|
serenity_install_headers("")
|
2021-11-26 13:53:46 +00:00
|
|
|
serenity_install_sources()
|
2020-12-23 17:07:22 +00:00
|
|
|
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})
|
2021-11-08 18:06:02 +00:00
|
|
|
# Avoid creating a dependency cycle between system libraries and the C++ standard library. This is necessary
|
|
|
|
# to ensure that initialization functions will be called in the right order (libc++ must come after LibPthread).
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
target_link_options(${target_name} PRIVATE -static-libstdc++)
|
|
|
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
Toolchain+Meta: Update LLVM version to 13.0.0
This commit updates the Clang toolchain's version to 13.0.0, which comes
with better C++20 support and improved handling of new features by
clang-format. Due to the newly enabled `-Bsymbolic-functions` flag, our
Clang binaries will only be 2-4% slower than if we dynamically linked
them, but we save hundreds of megabytes of disk space.
The `BuildClang.sh` script has been reworked to build the entire
toolchain in just three steps: one for the compiler, one for GNU
binutils, and one for the runtime libraries. This reduces the complexity
of the build script, and will allow us to modify the CI configuration to
only rebuild the libraries when our libc headers change.
Most of the compile flags have been moved out to a separate CMake cache
file, similarly to how the Android and Fuchsia toolchains are
implemented within the LLVM repo. This provides a nicer interface than
the heaps of command-line arguments.
We no longer build separate toolchains for each architecture, as the
same Clang binary can compile code for multiple targets.
The horrible mess that `SERENITY_CLANG_ARCH` was, has been removed in
this commit. Clang happily accepts an `i686-pc-serenity` target triple,
which matches what our GCC toolchain accepts.
2021-08-13 10:11:12 +00:00
|
|
|
target_link_libraries(${target_name} clang_rt.builtins)
|
2021-11-08 18:06:02 +00:00
|
|
|
# FIXME: Implement -static-libstdc++ in the next toolchain update.
|
|
|
|
target_link_options(${target_name} PRIVATE -nostdlib++ -Wl,-Bstatic -lc++ -Wl,-Bdynamic)
|
2022-01-19 19:54:34 +00:00
|
|
|
if (NOT ENABLE_MOLD_LINKER)
|
|
|
|
target_link_options(${target_name} PRIVATE -Wl,--no-dependent-libraries)
|
|
|
|
endif()
|
2022-03-05 01:02:09 +00:00
|
|
|
if (ENABLE_USERSPACE_COVERAGE_COLLECTION)
|
|
|
|
target_link_libraries(${target_name} clang_rt.profile)
|
|
|
|
endif()
|
2021-07-13 14:43:45 +00:00
|
|
|
endif()
|
2020-12-23 17:07:22 +00:00
|
|
|
target_link_directories(LibC PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
serenity_generated_sources(${target_name})
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(serenity_bin target_name)
|
2021-11-26 13:53:46 +00:00
|
|
|
serenity_install_sources()
|
2020-12-23 17:07:22 +00:00
|
|
|
add_executable(${target_name} ${SOURCES})
|
2021-06-15 13:07:25 +00:00
|
|
|
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
|
|
|
install(TARGETS ${target_name} RUNTIME DESTINATION bin OPTIONAL)
|
2020-12-23 17:07:22 +00:00
|
|
|
serenity_generated_sources(${target_name})
|
|
|
|
endfunction()
|
|
|
|
|
2021-04-25 05:53:23 +00:00
|
|
|
function(serenity_test test_src sub_dir)
|
2021-08-08 00:32:49 +00:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 2 SERENITY_TEST "MAIN_ALREADY_DEFINED" "CUSTOM_MAIN" "LIBS")
|
2021-04-25 05:53:23 +00:00
|
|
|
set(TEST_SOURCES ${test_src})
|
2021-05-18 14:15:12 +00:00
|
|
|
if ("${SERENITY_TEST_CUSTOM_MAIN}" STREQUAL "")
|
2021-07-27 06:19:08 +00:00
|
|
|
set(SERENITY_TEST_CUSTOM_MAIN "$<TARGET_OBJECTS:LibTestMain>")
|
2021-05-18 14:15:12 +00:00
|
|
|
endif()
|
|
|
|
if (NOT ${SERENITY_TEST_MAIN_ALREADY_DEFINED})
|
|
|
|
list(PREPEND TEST_SOURCES "${SERENITY_TEST_CUSTOM_MAIN}")
|
2021-04-25 05:53:23 +00:00
|
|
|
endif()
|
|
|
|
get_filename_component(test_name ${test_src} NAME_WE)
|
|
|
|
add_executable(${test_name} ${TEST_SOURCES})
|
2021-06-15 13:07:25 +00:00
|
|
|
add_dependencies(ComponentTests ${test_name})
|
|
|
|
set_target_properties(${test_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
2021-04-25 05:53:23 +00:00
|
|
|
target_link_libraries(${test_name} LibTest LibCore)
|
|
|
|
foreach(lib ${SERENITY_TEST_LIBS})
|
|
|
|
target_link_libraries(${test_name} ${lib})
|
|
|
|
endforeach()
|
2021-06-15 13:07:25 +00:00
|
|
|
install(TARGETS ${test_name} RUNTIME DESTINATION usr/Tests/${sub_dir} OPTIONAL)
|
2021-04-25 05:53:23 +00:00
|
|
|
endfunction()
|
|
|
|
|
2021-05-18 14:15:12 +00:00
|
|
|
function(serenity_testjs_test test_src sub_dir)
|
2021-08-08 00:32:49 +00:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 2 SERENITY_TEST "" "CUSTOM_MAIN" "LIBS")
|
2021-05-18 14:15:12 +00:00
|
|
|
if ("${SERENITY_TEST_CUSTOM_MAIN}" STREQUAL "")
|
2021-07-27 06:19:08 +00:00
|
|
|
set(SERENITY_TEST_CUSTOM_MAIN "$<TARGET_OBJECTS:JavaScriptTestRunnerMain>")
|
2021-05-18 14:15:12 +00:00
|
|
|
endif()
|
|
|
|
list(APPEND SERENITY_TEST_LIBS LibJS LibCore)
|
|
|
|
serenity_test(${test_src} ${sub_dir}
|
|
|
|
CUSTOM_MAIN "${SERENITY_TEST_CUSTOM_MAIN}"
|
|
|
|
LIBS ${SERENITY_TEST_LIBS})
|
|
|
|
endfunction()
|
|
|
|
|
2020-12-23 17:07:22 +00:00
|
|
|
function(serenity_app target_name)
|
2021-08-08 00:32:49 +00:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 1 SERENITY_APP "" "ICON" "")
|
2020-12-23 17:07:22 +00:00
|
|
|
|
|
|
|
serenity_bin("${target_name}")
|
2021-08-08 00:32:49 +00:00
|
|
|
set(small_icon "${SerenityOS_SOURCE_DIR}/Base/res/icons/16x16/${SERENITY_APP_ICON}.png")
|
|
|
|
set(medium_icon "${SerenityOS_SOURCE_DIR}/Base/res/icons/32x32/${SERENITY_APP_ICON}.png")
|
2020-12-23 17:07:22 +00:00
|
|
|
|
|
|
|
if (EXISTS "${small_icon}")
|
|
|
|
embed_resource("${target_name}" serenity_icon_s "${small_icon}")
|
2021-01-01 23:44:39 +00:00
|
|
|
else()
|
2021-05-13 11:15:35 +00:00
|
|
|
message(FATAL_ERROR "Missing small app icon: ${small_icon}")
|
2020-12-23 17:07:22 +00:00
|
|
|
endif()
|
2021-01-01 23:44:39 +00:00
|
|
|
|
2020-12-23 17:07:22 +00:00
|
|
|
if (EXISTS "${medium_icon}")
|
|
|
|
embed_resource("${target_name}" serenity_icon_m "${medium_icon}")
|
2021-01-01 23:44:39 +00:00
|
|
|
else()
|
2021-04-20 04:26:09 +00:00
|
|
|
# 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)
|
2021-05-13 21:33:12 +00:00
|
|
|
message(FATAL_ERROR "Missing medium app icon: ${medium_icon}")
|
2021-04-20 04:26:09 +00:00
|
|
|
endif()
|
2020-12-23 17:07:22 +00:00
|
|
|
endif()
|
|
|
|
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)
|
2020-12-29 12:38:14 +00:00
|
|
|
file(SIZE "${input_file}" file_size)
|
2020-12-23 17:07:22 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${asm_file}"
|
2021-08-08 00:32:49 +00:00
|
|
|
COMMAND "${SerenityOS_SOURCE_DIR}/Meta/generate-embedded-resource-assembly.sh" "${asm_file}" "${section}" "${input_file}" "${file_size}"
|
|
|
|
DEPENDS "${input_file}" "${SerenityOS_SOURCE_DIR}/Meta/generate-embedded-resource-assembly.sh"
|
2020-12-23 17:07:22 +00:00
|
|
|
COMMENT "Generating ${asm_file}"
|
|
|
|
)
|
|
|
|
target_sources("${target}" PRIVATE "${asm_file}")
|
|
|
|
endfunction()
|
2021-12-29 17:55:23 +00:00
|
|
|
|
|
|
|
function(link_with_unicode_data target)
|
2021-12-30 13:47:38 +00:00
|
|
|
if (ENABLE_UNICODE_DATABASE_DOWNLOAD)
|
2021-12-29 17:55:23 +00:00
|
|
|
target_link_libraries("${target}" LibUnicodeData)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2021-12-22 21:12:59 +00:00
|
|
|
|
|
|
|
function(remove_path_if_version_changed version version_file cache_path)
|
|
|
|
set(version_differs YES)
|
|
|
|
|
|
|
|
if (EXISTS "${version_file}")
|
|
|
|
file(STRINGS "${version_file}" active_version)
|
|
|
|
if (version STREQUAL active_version)
|
|
|
|
set(version_differs NO)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (version_differs)
|
|
|
|
message(STATUS "Removing outdated ${cache_path} for version ${version}")
|
|
|
|
file(REMOVE_RECURSE "${cache_path}")
|
|
|
|
file(WRITE "${version_file}" "${version}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2021-12-22 21:30:21 +00:00
|
|
|
|
|
|
|
function(invoke_generator name generator version_file prefix header implementation)
|
|
|
|
cmake_parse_arguments(invoke_generator "" "" "arguments" ${ARGN})
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${header}" "${implementation}"
|
|
|
|
COMMAND $<TARGET_FILE:${generator}> -h "${header}.tmp" -c "${implementation}.tmp" ${invoke_generator_arguments}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${header}.tmp" "${header}"
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${implementation}.tmp" "${implementation}"
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -E remove "${header}.tmp" "${implementation}.tmp"
|
|
|
|
VERBATIM
|
|
|
|
DEPENDS ${generator} "${version_file}"
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target("generate_${prefix}${name}" DEPENDS "${header}" "${implementation}")
|
|
|
|
add_dependencies(all_generated "generate_${prefix}${name}")
|
|
|
|
endfunction()
|
2022-01-25 23:36:40 +00:00
|
|
|
|
|
|
|
function(download_file url path)
|
|
|
|
if (NOT EXISTS "${path}")
|
|
|
|
get_filename_component(file "${path}" NAME)
|
|
|
|
message(STATUS "Downloading file ${file} from ${url}")
|
|
|
|
|
|
|
|
file(DOWNLOAD "${url}" "${path}" INACTIVITY_TIMEOUT 10 STATUS download_result)
|
|
|
|
list(GET download_result 0 status_code)
|
|
|
|
list(GET download_result 1 error_message)
|
|
|
|
|
|
|
|
if (NOT status_code EQUAL 0)
|
|
|
|
file(REMOVE "${path}")
|
|
|
|
message(FATAL_ERROR "Failed to download ${url}: ${error_message}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|