2021-08-07 23:11:02 +00:00
|
|
|
|
2021-08-07 23:37:09 +00:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/code_generators.cmake)
|
2021-08-07 23:11:02 +00:00
|
|
|
|
2022-10-22 13:13:49 +00:00
|
|
|
function(serenity_set_implicit_links target_name)
|
|
|
|
# Make sure that CMake is aware of the implicit LibC dependency, and ensure
|
|
|
|
# that we are choosing the correct and updated LibC.
|
|
|
|
# The latter is a problem with Clang especially, since we might have the
|
|
|
|
# slightly outdated stub in the sysroot, but have not yet installed the freshly
|
|
|
|
# built LibC.
|
2022-10-21 19:43:56 +00:00
|
|
|
target_link_libraries(${target_name} PRIVATE LibC)
|
2022-10-22 13:13:49 +00:00
|
|
|
endfunction()
|
|
|
|
|
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)
|
2022-07-04 17:01:05 +00:00
|
|
|
install(FILES ${header} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${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)
|
2024-04-25 17:30:44 +00:00
|
|
|
cmake_path(RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR BASE_DIRECTORY ${SerenityOS_SOURCE_DIR} OUTPUT_VARIABLE current_source_dir_relative)
|
2022-10-23 14:56:27 +00:00
|
|
|
file(GLOB_RECURSE sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h" "*.cpp" "*.gml")
|
2020-12-23 17:07:22 +00:00
|
|
|
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()
|
|
|
|
|
2022-07-04 16:08:01 +00:00
|
|
|
if (NOT COMMAND serenity_lib)
|
|
|
|
function(serenity_lib target_name fs_name)
|
2024-03-26 14:01:36 +00:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 2 SERENITY_LIB "" "TYPE" "")
|
|
|
|
|
|
|
|
if ("${SERENITY_LIB_TYPE}" STREQUAL "")
|
|
|
|
set(SERENITY_LIB_TYPE SHARED)
|
|
|
|
endif()
|
|
|
|
|
2022-07-04 16:08:01 +00:00
|
|
|
serenity_install_headers(${target_name})
|
|
|
|
serenity_install_sources()
|
2024-03-26 14:01:36 +00:00
|
|
|
add_library(${target_name} ${SERENITY_LIB_TYPE} ${SOURCES} ${GENERATED_SOURCES})
|
2022-07-04 16:08:01 +00:00
|
|
|
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
|
|
|
set_target_properties(${target_name} PROPERTIES VERSION "serenity")
|
2024-04-16 01:50:49 +00:00
|
|
|
target_link_libraries(${target_name} PUBLIC GenericClangPlugin)
|
2022-07-04 16:08:01 +00:00
|
|
|
install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL)
|
|
|
|
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name})
|
|
|
|
serenity_generated_sources(${target_name})
|
2022-10-22 13:13:49 +00:00
|
|
|
serenity_set_implicit_links(${target_name})
|
2022-07-04 16:08:01 +00:00
|
|
|
endfunction()
|
|
|
|
endif()
|
2022-03-23 00:36:47 +00:00
|
|
|
|
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()
|
2023-07-04 08:21:36 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib -fpic -ftls-model=initial-exec")
|
2020-12-23 17:07:22 +00:00
|
|
|
add_library(${target_name} SHARED ${SOURCES})
|
2022-07-04 17:01:05 +00:00
|
|
|
install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
2020-12-23 17:07:22 +00:00
|
|
|
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).
|
2022-09-14 12:10:23 +00:00
|
|
|
target_link_options(${target_name} PRIVATE -static-libstdc++)
|
2022-12-10 09:59:37 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND ENABLE_USERSPACE_COVERAGE_COLLECTION)
|
|
|
|
target_link_libraries(${target_name} PRIVATE clang_rt.profile)
|
|
|
|
endif()
|
2020-12-23 17:07:22 +00:00
|
|
|
target_link_directories(LibC PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
serenity_generated_sources(${target_name})
|
|
|
|
endfunction()
|
|
|
|
|
2022-07-04 16:08:01 +00:00
|
|
|
if (NOT COMMAND serenity_bin)
|
|
|
|
function(serenity_bin target_name)
|
|
|
|
serenity_install_sources()
|
|
|
|
add_executable(${target_name} ${SOURCES})
|
2024-04-16 01:50:49 +00:00
|
|
|
target_link_libraries(${target_name} PUBLIC GenericClangPlugin)
|
2022-07-04 16:08:01 +00:00
|
|
|
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
|
|
|
install(TARGETS ${target_name} RUNTIME DESTINATION bin OPTIONAL)
|
|
|
|
serenity_generated_sources(${target_name})
|
2022-10-22 13:13:49 +00:00
|
|
|
serenity_set_implicit_links(${target_name})
|
2022-07-04 16:08:01 +00:00
|
|
|
endfunction()
|
|
|
|
endif()
|
2020-12-23 17:07:22 +00:00
|
|
|
|
2023-01-16 15:35:40 +00:00
|
|
|
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})
|
2023-03-21 15:35:30 +00:00
|
|
|
target_link_libraries(${test_name} PRIVATE LibTest LibCore LibFileSystem)
|
2023-01-16 15:35:40 +00:00
|
|
|
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()
|
2021-04-25 05:53:23 +00:00
|
|
|
|
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()
|
2023-03-21 15:35:30 +00:00
|
|
|
list(APPEND SERENITY_TEST_LIBS LibJS LibCore LibFileSystem)
|
2021-05-18 14:15:12 +00:00
|
|
|
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()
|
|
|
|
|
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
|
|
|
|
2024-05-21 16:22:26 +00:00
|
|
|
function(invoke_generator name generator primary_source header implementation)
|
2022-10-26 19:57:30 +00:00
|
|
|
cmake_parse_arguments(invoke_generator "" "" "arguments;dependencies" ${ARGN})
|
2021-12-22 21:30:21 +00:00
|
|
|
|
|
|
|
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
|
2024-05-21 16:22:26 +00:00
|
|
|
DEPENDS ${generator} ${invoke_generator_dependencies} "${primary_source}"
|
2021-12-22 21:30:21 +00:00
|
|
|
)
|
|
|
|
|
2022-10-16 15:53:48 +00:00
|
|
|
add_custom_target("generate_${name}" DEPENDS "${header}" "${implementation}")
|
|
|
|
add_dependencies(all_generated "generate_${name}")
|
2022-10-17 05:49:52 +00:00
|
|
|
list(APPEND CURRENT_LIB_GENERATED "${name}")
|
|
|
|
set(CURRENT_LIB_GENERATED ${CURRENT_LIB_GENERATED} PARENT_SCOPE)
|
2021-12-22 21:30:21 +00:00
|
|
|
endfunction()
|
2022-01-25 23:36:40 +00:00
|
|
|
|
2022-12-19 20:46:07 +00:00
|
|
|
function(download_file_multisource urls path)
|
2024-05-23 16:04:02 +00:00
|
|
|
cmake_parse_arguments(DOWNLOAD "" "SHA256" "" ${ARGN})
|
|
|
|
|
|
|
|
if (NOT "${DOWNLOAD_SHA256}" STREQUAL "")
|
|
|
|
set(DOWNLOAD_SHA256 EXPECTED_HASH "SHA256=${DOWNLOAD_SHA256}")
|
|
|
|
endif()
|
|
|
|
|
2022-01-25 23:36:40 +00:00
|
|
|
if (NOT EXISTS "${path}")
|
2023-08-10 21:45:59 +00:00
|
|
|
if (NOT ENABLE_NETWORK_DOWNLOADS)
|
|
|
|
message(FATAL_ERROR "${path} does not exist, and unable to download it")
|
|
|
|
endif()
|
2024-05-23 16:08:24 +00:00
|
|
|
|
2022-01-25 23:36:40 +00:00
|
|
|
get_filename_component(file "${path}" NAME)
|
2024-05-23 16:08:24 +00:00
|
|
|
set(tmp_path "${path}.tmp")
|
2022-01-25 23:36:40 +00:00
|
|
|
|
2022-12-19 20:46:07 +00:00
|
|
|
foreach(url ${urls})
|
|
|
|
message(STATUS "Downloading file ${file} from ${url}")
|
|
|
|
|
2024-05-23 16:08:24 +00:00
|
|
|
file(DOWNLOAD "${url}" "${tmp_path}" INACTIVITY_TIMEOUT 10 STATUS download_result ${DOWNLOAD_SHA256})
|
2022-12-19 20:46:07 +00:00
|
|
|
list(GET download_result 0 status_code)
|
|
|
|
list(GET download_result 1 error_message)
|
|
|
|
|
|
|
|
if (status_code EQUAL 0)
|
2024-05-23 16:08:24 +00:00
|
|
|
file(RENAME "${tmp_path}" "${path}")
|
2022-12-19 20:46:07 +00:00
|
|
|
break()
|
|
|
|
endif()
|
2022-01-25 23:36:40 +00:00
|
|
|
|
2024-05-23 16:08:24 +00:00
|
|
|
file(REMOVE "${tmp_path}")
|
2022-12-19 20:46:07 +00:00
|
|
|
message(WARNING "Failed to download ${url}: ${error_message}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if (NOT status_code EQUAL 0)
|
|
|
|
message(FATAL_ERROR "Failed to download ${path} from any source")
|
2022-01-25 23:36:40 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2022-09-02 14:27:46 +00:00
|
|
|
|
2022-12-19 20:46:07 +00:00
|
|
|
function(download_file url path)
|
2024-05-23 16:04:02 +00:00
|
|
|
cmake_parse_arguments(DOWNLOAD "" "SHA256" "" ${ARGN})
|
|
|
|
|
2022-12-19 20:46:07 +00:00
|
|
|
# If the timestamp doesn't match exactly, the Web Archive should redirect to the closest archived file automatically.
|
2024-05-23 16:04:02 +00:00
|
|
|
download_file_multisource("${url};https://web.archive.org/web/99991231235959/${url}" "${path}" SHA256 "${DOWNLOAD_SHA256}")
|
2022-12-19 20:46:07 +00:00
|
|
|
endfunction()
|
|
|
|
|
2022-09-02 14:27:46 +00:00
|
|
|
function(extract_path dest_dir zip_path source_path dest_path)
|
|
|
|
if (EXISTS "${zip_path}" AND NOT EXISTS "${dest_path}")
|
2024-01-29 19:53:00 +00:00
|
|
|
file(ARCHIVE_EXTRACT INPUT "${zip_path}" DESTINATION "${dest_dir}" PATTERNS "${source_path}")
|
2022-09-02 14:27:46 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|
2024-05-14 00:25:47 +00:00
|
|
|
|
|
|
|
function(add_lagom_library_install_rules target_name)
|
|
|
|
cmake_parse_arguments(PARSE_ARGV 1 LAGOM_INSTALL_RULES "" "ALIAS_NAME" "")
|
|
|
|
if (NOT LAGOM_INSTALL_RULES_ALIAS_NAME)
|
|
|
|
set(LAGOM_INSTALL_RULES_ALIAS_NAME ${target_name})
|
|
|
|
endif()
|
|
|
|
# Don't make alias when we're going to import a previous build for Tools
|
|
|
|
# FIXME: Is there a better way to write this?
|
|
|
|
if (NOT ENABLE_FUZZERS AND NOT CMAKE_CROSSCOMPILING)
|
|
|
|
# alias for parity with exports
|
|
|
|
add_library(Lagom::${LAGOM_INSTALL_RULES_ALIAS_NAME} ALIAS ${target_name})
|
|
|
|
endif()
|
|
|
|
install(TARGETS ${target_name} EXPORT LagomTargets
|
|
|
|
RUNTIME COMPONENT Lagom_Runtime
|
|
|
|
LIBRARY COMPONENT Lagom_Runtime NAMELINK_COMPONENT Lagom_Development
|
|
|
|
ARCHIVE COMPONENT Lagom_Development
|
|
|
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
|
|
)
|
|
|
|
endfunction()
|