CMakeLists.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. cmake_minimum_required (VERSION 3.21)
  2. project(
  3. Lagom
  4. VERSION 0.0.0
  5. DESCRIPTION "Host build of SerenityOS libraries and applications"
  6. HOMEPAGE_URL "https://github.com/SerenityOS/serenity"
  7. LANGUAGES C CXX
  8. )
  9. if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "12")
  10. message(FATAL_ERROR
  11. "A GCC version less than 12 was detected (${CMAKE_CXX_COMPILER_VERSION}), this is unsupported.\n"
  12. "Please re-read the build instructions documentation, and upgrade your host compiler.\n")
  13. endif()
  14. if (${ENABLE_LAGOM_LADYBIRD} OR $CACHE{ENABLE_LAGOM_LADYBIRD})
  15. message(FATAL_ERROR
  16. "The ENABLE_LAGOM_LADYBIRD option is no longer supported.\n"
  17. "Please use the top-level CMakeLists.txt to enable Ladybird builds.\n")
  18. endif()
  19. # This is required for CMake (when invoked for a Lagom-only build) to
  20. # ignore any files downloading during the build, e.g. public_suffix_list.dat.
  21. # https://cmake.org/cmake/help/latest/policy/CMP0058.html
  22. cmake_policy(SET CMP0058 NEW)
  23. # Make CMAKE_EXE_LINKER_FLAGS have an effect on `try_compile()` jobs.
  24. # This is required if we want to have the `LAGOM_USE_LINKER` option
  25. # take effect in `check_linker_flag` checks.
  26. cmake_policy(SET CMP0056 NEW)
  27. get_filename_component(
  28. SERENITY_PROJECT_ROOT "${PROJECT_SOURCE_DIR}/../.."
  29. ABSOLUTE CACHE
  30. )
  31. set(SerenityOS_SOURCE_DIR "${SERENITY_PROJECT_ROOT}" CACHE STRING "")
  32. list(APPEND CMAKE_MODULE_PATH "${SERENITY_PROJECT_ROOT}/Meta/CMake")
  33. if(NOT COMMAND serenity_option)
  34. macro(serenity_option)
  35. set(${ARGV})
  36. endmacro()
  37. endif()
  38. include(check_for_dependencies)
  39. include(use_linker)
  40. include(lagom_options NO_POLICY_SCOPE)
  41. if(ENABLE_ALL_THE_DEBUG_MACROS)
  42. include(all_the_debug_macros)
  43. endif()
  44. # FIXME: BUILD_SHARED_LIBS has a default of OFF, as it's intended to be set by the
  45. # user when configuring the project. We should instead change libjs-test262
  46. # and oss-fuzz to set this option on their end, and enable it by default in
  47. # Meta/ladybird.sh. This is #9867.
  48. option(BUILD_SHARED_LIBS "Build shared libraries instead of static libraries" ON)
  49. find_package(Threads REQUIRED)
  50. # FIXME: This global link libraries is required to workaround linker issues (on some systems)
  51. # from the Ladybird import. See https://github.com/SerenityOS/serenity/issues/16847
  52. link_libraries(Threads::Threads)
  53. if (ENABLE_LAGOM_CCACHE)
  54. include(setup_ccache)
  55. endif()
  56. if (ENABLE_FUZZERS_LIBFUZZER OR ENABLE_FUZZERS_OSSFUZZ)
  57. set(ENABLE_FUZZERS ON)
  58. endif()
  59. # We need to make sure not to build code generators for Fuzzer builds, as they already have their own main.cpp
  60. # Instead, we import them from a previous install of Lagom. This mandates a two-stage build for fuzzers.
  61. # The same concern goes for cross-compile builds, where we need the tools built for the host
  62. set(BUILD_LAGOM_TOOLS ON)
  63. if (ENABLE_FUZZERS OR CMAKE_CROSSCOMPILING)
  64. find_package(LagomTools REQUIRED)
  65. set(BUILD_LAGOM_TOOLS OFF)
  66. endif()
  67. include(flac_spec_tests)
  68. include(ca_certificates_data)
  69. include(lagom_compile_options)
  70. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  71. if (EMSCRIPTEN)
  72. set(CMAKE_EXECUTABLE_SUFFIX ".js")
  73. add_cxx_compile_options(-gsource-map)
  74. add_cxx_link_options(--emrun "SHELL:-s ALLOW_MEMORY_GROWTH")
  75. endif()
  76. if (ENABLE_ADDRESS_SANITIZER)
  77. add_cxx_compile_options(-fsanitize=address -fno-omit-frame-pointer)
  78. add_cxx_link_options(-fsanitize=address)
  79. add_swift_compile_options(-sanitize=address)
  80. add_swift_link_options(-sanitize=address)
  81. endif()
  82. if (ENABLE_MEMORY_SANITIZER)
  83. add_cxx_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
  84. add_cxx_link_options(-fsanitize=memory -fsanitize-memory-track-origins)
  85. endif()
  86. if (ENABLE_UNDEFINED_SANITIZER AND (APPLE OR NOT ENABLE_SWIFT))
  87. add_cxx_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
  88. if (UNDEFINED_BEHAVIOR_IS_FATAL)
  89. add_cxx_compile_options(-fno-sanitize-recover=undefined)
  90. endif()
  91. if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
  92. add_cxx_compile_options(-fno-sanitize=function)
  93. endif()
  94. add_cxx_link_options(-fsanitize=undefined)
  95. add_swift_compile_options(-sanitize=undefined)
  96. add_swift_link_options(-sanitize=undefined)
  97. endif()
  98. if (ENABLE_COMPILETIME_FORMAT_CHECK)
  99. add_compile_definitions(ENABLE_COMPILETIME_FORMAT_CHECK)
  100. endif()
  101. if (HAIKU)
  102. # Haiku needs some extra compile definitions to make important stuff in its headers available.
  103. add_compile_definitions(_DEFAULT_SOURCE)
  104. add_compile_definitions(_GNU_SOURCE)
  105. add_compile_definitions(__USE_GNU)
  106. endif()
  107. if (ENABLE_FUZZERS)
  108. add_cxx_compile_options(-fno-omit-frame-pointer)
  109. endif()
  110. add_library(JSClangPlugin INTERFACE)
  111. add_library(GenericClangPlugin INTERFACE)
  112. if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
  113. add_cxx_compile_options(-Wno-overloaded-virtual)
  114. # FIXME: Re-enable this check when the warning stops triggering, or document why we can't stop it from triggering.
  115. # For now, there is a lot of unused private fields in LibWeb that trigger this that could be removed.
  116. # See issue #14137 for details
  117. add_cxx_compile_options(-Wno-unused-private-field)
  118. if (ENABLE_FUZZERS_LIBFUZZER)
  119. add_cxx_compile_options(-fsanitize=fuzzer)
  120. set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=fuzzer")
  121. endif()
  122. # Vanilla host builds only for building the clang plugins
  123. if (ENABLE_CLANG_PLUGINS AND NOT CROSS_COMPILING AND NOT ENABLE_FUZZERS AND NOT ENABLE_COMPILER_EXPLORER_BUILD)
  124. add_subdirectory(ClangPlugins)
  125. depend_on_clang_plugin(JSClangPlugin LibJSGCClangPlugin)
  126. depend_on_clang_plugin(GenericClangPlugin LambdaCaptureClangPlugin)
  127. endif()
  128. elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  129. if (ENABLE_FUZZERS_LIBFUZZER)
  130. message(FATAL_ERROR
  131. "Fuzzer Sanitizer (-fsanitize=fuzzer) is only supported for Fuzzer targets with LLVM. "
  132. "Reconfigure CMake with -DCMAKE_C_COMPILER and -DCMAKE_CXX_COMPILER pointing to a clang-based toolchain "
  133. "or build binaries without built-in fuzzing support by setting -DENABLE_FUZZERS instead."
  134. )
  135. endif()
  136. endif()
  137. # These are here to support Fuzzili builds further down the directory stack
  138. set(ORIGINAL_CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
  139. set(ORIGINAL_CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
  140. set(ORIGINAL_CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS}")
  141. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LINKER_FLAGS}")
  142. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
  143. set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")
  144. configure_file(../../AK/Debug.h.in AK/Debug.h @ONLY)
  145. include_directories(../../)
  146. include_directories(../../Userland/)
  147. include_directories(../../Userland/Libraries/)
  148. include_directories(../../Userland/Services)
  149. include_directories(${CMAKE_BINARY_DIR})
  150. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  151. include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland/Libraries)
  152. include_directories(${CMAKE_CURRENT_BINARY_DIR}/Userland/Services)
  153. # install rules, think about moving to its own helper cmake file
  154. include(CMakePackageConfigHelpers)
  155. # find_package(<package>) call for consumers to find this project
  156. set(package Lagom CACHE STRING "")
  157. # Allow package maintainers to freely override the path for the configs
  158. set(Lagom_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/${package}"
  159. CACHE PATH "CMake package config location relative to the install prefix")
  160. mark_as_advanced(Lagom_INSTALL_CMAKEDIR)
  161. install(
  162. FILES "${SERENITY_PROJECT_ROOT}/Meta/CMake/lagom-install-config.cmake"
  163. DESTINATION "${Lagom_INSTALL_CMAKEDIR}"
  164. RENAME "${package}Config.cmake"
  165. COMPONENT Lagom_Development
  166. )
  167. install(
  168. EXPORT LagomTargets
  169. NAMESPACE Lagom::
  170. DESTINATION "${Lagom_INSTALL_CMAKEDIR}"
  171. COMPONENT Lagom_Development
  172. )
  173. function(lagom_lib target_name fs_name)
  174. cmake_parse_arguments(LAGOM_LIBRARY "" "LIBRARY_TYPE" "SOURCES;LIBS" ${ARGN})
  175. string(REPLACE "Lib" "" library ${target_name})
  176. if (NOT LAGOM_LIBRARY_LIBRARY_TYPE)
  177. set(LAGOM_LIBRARY_LIBRARY_TYPE "")
  178. endif()
  179. add_library(${target_name} ${LAGOM_LIBRARY_LIBRARY_TYPE} ${LAGOM_LIBRARY_SOURCES})
  180. set_target_properties(
  181. ${target_name} PROPERTIES
  182. VERSION "${PROJECT_VERSION}"
  183. SOVERSION "${PROJECT_VERSION_MAJOR}"
  184. EXPORT_NAME ${library}
  185. OUTPUT_NAME lagom-${fs_name}
  186. )
  187. target_link_libraries(${target_name} PRIVATE ${LAGOM_LIBRARY_LIBS})
  188. target_link_libraries(${target_name} PUBLIC GenericClangPlugin)
  189. if (NOT "${target_name}" STREQUAL "AK")
  190. target_link_libraries(${target_name} PRIVATE AK)
  191. endif()
  192. # FIXME: Clean these up so that we don't need so many include dirs
  193. if (ENABLE_INSTALL_HEADERS)
  194. target_include_directories(${target_name} INTERFACE
  195. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/Services>
  196. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/Userland/Libraries>
  197. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/Userland/Services>
  198. )
  199. endif()
  200. add_lagom_library_install_rules(${target_name} ALIAS_NAME ${library})
  201. if (ENABLE_INSTALL_HEADERS)
  202. # FIXME: Move this to serenity_install_headers
  203. install(
  204. DIRECTORY "${SERENITY_PROJECT_ROOT}/Userland/Libraries/Lib${library}"
  205. COMPONENT Lagom_Development
  206. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  207. FILES_MATCHING PATTERN "*.h"
  208. )
  209. endif()
  210. serenity_generated_sources(${target_name})
  211. endfunction()
  212. function(lagom_test source)
  213. cmake_parse_arguments(LAGOM_TEST "" "NAME;WORKING_DIRECTORY" "LIBS" ${ARGN})
  214. if (NOT DEFINED LAGOM_TEST_NAME)
  215. get_filename_component(LAGOM_TEST_NAME ${source} NAME_WE)
  216. endif()
  217. add_executable(${LAGOM_TEST_NAME} ${source})
  218. target_link_libraries(${LAGOM_TEST_NAME} PRIVATE AK LibCore LibFileSystem LibTest LibTestMain ${LAGOM_TEST_LIBS})
  219. add_test(
  220. NAME ${LAGOM_TEST_NAME}
  221. COMMAND ${LAGOM_TEST_NAME}
  222. WORKING_DIRECTORY ${LAGOM_TEST_WORKING_DIRECTORY}
  223. )
  224. endfunction()
  225. function(lagom_utility name)
  226. cmake_parse_arguments(LAGOM_UTILITY "" "" "SOURCES;LIBS" ${ARGN})
  227. add_executable("${name}" ${LAGOM_UTILITY_SOURCES})
  228. target_link_libraries("${name}" PRIVATE AK LibCore ${LAGOM_UTILITY_LIBS})
  229. endfunction()
  230. function(serenity_test test_src sub_dir)
  231. cmake_parse_arguments(PARSE_ARGV 2 SERENITY_TEST "MAIN_ALREADY_DEFINED" "CUSTOM_MAIN" "LIBS")
  232. # FIXME: Pass MAIN_ALREADY_DEFINED and CUSTOM_MAIN to support tests that use them.
  233. lagom_test(${test_src} LIBS ${SERENITY_TEST_LIBS} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  234. endfunction()
  235. function(serenity_bin name)
  236. add_executable(${name} ${SOURCES} ${GENERATED_SOURCES})
  237. add_executable(Lagom::${name} ALIAS ${name})
  238. target_link_libraries(${name} PUBLIC GenericClangPlugin)
  239. install(
  240. TARGETS ${target_name}
  241. EXPORT LagomTargets
  242. RUNTIME #
  243. COMPONENT Lagom_Runtime
  244. LIBRARY #
  245. COMPONENT Lagom_Runtime
  246. NAMELINK_COMPONENT Lagom_Development
  247. ARCHIVE #
  248. COMPONENT Lagom_Development
  249. INCLUDES #
  250. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  251. )
  252. serenity_generated_sources(${name})
  253. endfunction()
  254. function(serenity_lib name fs_name)
  255. cmake_parse_arguments(PARSE_ARGV 2 SERENITY_LIB "" "TYPE" "")
  256. lagom_lib(${name} ${fs_name} LIBRARY_TYPE ${SERENITY_LIB_TYPE} SOURCES ${SOURCES} ${GENERATED_SOURCES})
  257. endfunction()
  258. function(serenity_install_headers dir)
  259. endfunction()
  260. function(serenity_install_sources dir)
  261. endfunction()
  262. macro(add_serenity_subdirectory path)
  263. add_subdirectory("${SERENITY_PROJECT_ROOT}/${path}" "${CMAKE_CURRENT_BINARY_DIR}/${path}")
  264. endmacro()
  265. if (NOT TARGET all_generated)
  266. # Meta target to run all code-gen steps in the build.
  267. add_custom_target(all_generated)
  268. endif()
  269. # Plugins need to be installed in order to be used by non-lagom builds
  270. add_lagom_library_install_rules(GenericClangPlugin)
  271. add_lagom_library_install_rules(JSClangPlugin)
  272. # Create mostly empty targets for system libraries we don't need to build for Lagom
  273. add_library(LibC INTERFACE)
  274. add_library(LibCrypt INTERFACE)
  275. if (NOT APPLE AND NOT ANDROID AND NOT EMSCRIPTEN AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" AND NOT HAIKU AND NOT WIN32)
  276. target_link_libraries(LibCrypt INTERFACE crypt) # LibCore::Account uses crypt() but it's not in libcrypt on macOS
  277. endif()
  278. add_library(NoCoverage INTERFACE)
  279. # "install" these special targets to placate CMake
  280. install(TARGETS LibC LibCrypt NoCoverage EXPORT LagomTargets)
  281. # AK
  282. add_serenity_subdirectory(AK)
  283. # LibCoreMinimal
  284. add_serenity_subdirectory(Userland/Libraries/LibCore)
  285. if (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
  286. # NetBSD has its shm_open and shm_unlink functions in librt so we need to link that
  287. target_link_libraries(LibCoreMinimal PRIVATE rt)
  288. endif()
  289. # LibMain
  290. add_serenity_subdirectory(Userland/Libraries/LibMain)
  291. # LibFileSystem
  292. # This is needed even if Lagom is not enabled because it is depended upon by code generators.
  293. add_serenity_subdirectory(Userland/Libraries/LibFileSystem)
  294. # LibIDL
  295. # This is used by the BindingsGenerator so needs to always be built.
  296. add_serenity_subdirectory(Userland/Libraries/LibIDL)
  297. # Manually install AK headers
  298. if (ENABLE_INSTALL_HEADERS)
  299. install(
  300. DIRECTORY "${SERENITY_PROJECT_ROOT}/AK"
  301. COMPONENT Lagom_Development
  302. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  303. FILES_MATCHING PATTERN "*.h"
  304. )
  305. install(FILES
  306. ${Lagom_BINARY_DIR}/AK/Debug.h
  307. ${Lagom_BINARY_DIR}/AK/Backtrace.h
  308. COMPONENT Lagom_Development
  309. DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/AK"
  310. )
  311. endif()
  312. # Code Generators and other host tools
  313. if (BUILD_LAGOM_TOOLS)
  314. add_subdirectory(Tools)
  315. endif()
  316. if (LAGOM_TOOLS_ONLY)
  317. return()
  318. endif()
  319. # Lagom Libraries
  320. set(lagom_standard_libraries
  321. Archive
  322. Compress
  323. Crypto
  324. Diff
  325. HTTP
  326. IPC
  327. JS
  328. Line
  329. Regex
  330. Requests
  331. RIFF
  332. Syntax
  333. TextCodec
  334. Threading
  335. TLS
  336. Unicode
  337. URL
  338. Wasm
  339. WebSocket
  340. XML
  341. )
  342. if (ENABLE_GUI_TARGETS)
  343. list(APPEND lagom_standard_libraries
  344. Gfx
  345. ImageDecoderClient
  346. Media
  347. WebView
  348. Web
  349. )
  350. endif()
  351. target_link_libraries(LibCore PRIVATE LibURL Threads::Threads)
  352. if (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
  353. # NetBSD has its shm_open and shm_unlink functions in librt so we need to link that
  354. target_link_libraries(LibCore PRIVATE rt)
  355. endif()
  356. if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
  357. # Solaris has socket and networking related functions in two extra libraries
  358. target_link_libraries(LibCore PRIVATE nsl socket)
  359. endif()
  360. if (HAIKU)
  361. # Haiku has networking related functions in the network library
  362. target_link_libraries(LibCore PRIVATE network)
  363. endif()
  364. compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/RequestServer/RequestClient.ipc Userland/Services/RequestServer/RequestClientEndpoint.h)
  365. compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/RequestServer/RequestServer.ipc Userland/Services/RequestServer/RequestServerEndpoint.h)
  366. compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebContentServer.ipc Userland/Services/WebContent/WebContentServerEndpoint.h)
  367. compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebContentClient.ipc Userland/Services/WebContent/WebContentClientEndpoint.h)
  368. compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebDriverClient.ipc Userland/Services/WebContent/WebDriverClientEndpoint.h)
  369. compile_ipc(${SERENITY_PROJECT_ROOT}/Userland/Services/WebContent/WebDriverServer.ipc Userland/Services/WebContent/WebDriverServerEndpoint.h)
  370. foreach(lib IN LISTS lagom_standard_libraries)
  371. add_serenity_subdirectory("Userland/Libraries/Lib${lib}")
  372. endforeach()
  373. if (ENABLE_FUZZERS)
  374. add_subdirectory(Fuzzers)
  375. endif()
  376. # No utilities or tests in these configs
  377. if (ENABLE_FUZZERS OR ENABLE_COMPILER_EXPLORER_BUILD OR ANDROID OR IOS)
  378. return()
  379. endif()
  380. # Lagom Utilities
  381. lagom_utility(abench SOURCES ../../Userland/Utilities/abench.cpp LIBS LibMain LibFileSystem LibMedia)
  382. if (ENABLE_GUI_TARGETS)
  383. lagom_utility(animation SOURCES ../../Userland/Utilities/animation.cpp LIBS LibGfx LibMain)
  384. lagom_utility(icc SOURCES ../../Userland/Utilities/icc.cpp LIBS LibGfx LibMain LibURL)
  385. lagom_utility(image SOURCES ../../Userland/Utilities/image.cpp LIBS LibGfx LibMain)
  386. endif()
  387. lagom_utility(js SOURCES ../../Userland/Utilities/js.cpp LIBS LibCrypto LibJS LibLine LibUnicode LibMain LibTextCodec Threads::Threads)
  388. lagom_utility(gzip SOURCES ../../Userland/Utilities/gzip.cpp LIBS LibCompress LibMain)
  389. lagom_utility(lzcat SOURCES ../../Userland/Utilities/lzcat.cpp LIBS LibCompress LibMain)
  390. lagom_utility(tar SOURCES ../../Userland/Utilities/tar.cpp LIBS LibArchive LibCompress LibFileSystem LibMain)
  391. lagom_utility(test262-runner SOURCES ../../Tests/LibJS/test262-runner.cpp LIBS LibJS LibFileSystem)
  392. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  393. include(CheckCSourceCompiles)
  394. # Check for musl's declaration of __assert_fail
  395. check_c_source_compiles(
  396. "
  397. #include <assert.h>
  398. __attribute__((__noreturn__)) void __assert_fail(char const* assertion, char const* file, int line, char const* function) {}
  399. int main() {}
  400. "
  401. ASSERT_FAIL_HAS_INT
  402. )
  403. endif()
  404. if (ASSERT_FAIL_HAS_INT OR EMSCRIPTEN)
  405. target_compile_definitions(test262-runner PRIVATE ASSERT_FAIL_HAS_INT)
  406. endif()
  407. lagom_utility(wasm SOURCES ../../Userland/Utilities/wasm.cpp LIBS LibFileSystem LibWasm LibLine LibMain LibJS)
  408. lagom_utility(xml SOURCES ../../Userland/Utilities/xml.cpp LIBS LibFileSystem LibMain LibXML LibURL)
  409. lagom_utility(xzcat SOURCES ../../Userland/Utilities/xzcat.cpp LIBS LibCompress LibMain)
  410. include(CTest)
  411. if (BUILD_TESTING)
  412. # LibTest
  413. file(GLOB LIBTEST_SOURCES CONFIGURE_DEPENDS "../../Userland/Libraries/LibTest/*.cpp")
  414. list(FILTER LIBTEST_SOURCES EXCLUDE REGEX ".*Main.cpp$")
  415. add_library(
  416. LibTest
  417. ${LIBTEST_SOURCES}
  418. )
  419. target_link_libraries(LibTest PRIVATE AK LibCore LibFileSystem)
  420. set_target_properties(LibTest PROPERTIES OUTPUT_NAME lagom-test)
  421. add_library(
  422. LibTestMain
  423. OBJECT
  424. "${SERENITY_PROJECT_ROOT}/Userland/Libraries/LibTest/TestMain.cpp"
  425. )
  426. target_link_libraries(LibTest PUBLIC GenericClangPlugin)
  427. target_link_libraries(LibTestMain PUBLIC GenericClangPlugin)
  428. # LibTest tests from Tests/
  429. set(TEST_DIRECTORIES
  430. AK
  431. LibCrypto
  432. LibCompress
  433. LibTest
  434. LibTextCodec
  435. LibThreading
  436. LibUnicode
  437. LibURL
  438. LibXML
  439. )
  440. if (ENABLE_GUI_TARGETS)
  441. list(APPEND TEST_DIRECTORIES
  442. LibGfx
  443. LibMedia
  444. LibWeb
  445. LibWebView
  446. )
  447. endif()
  448. if (ENABLE_CLANG_PLUGINS AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
  449. list(APPEND TEST_DIRECTORIES ClangPlugins)
  450. endif()
  451. foreach (dir IN LISTS TEST_DIRECTORIES)
  452. add_serenity_subdirectory("Tests/${dir}")
  453. endforeach()
  454. # LibTLS needs a special working directory to find cacert.pem
  455. lagom_test(../../Tests/LibTLS/TestTLSHandshake.cpp LibTLS LIBS LibTLS LibCrypto)
  456. lagom_test(../../Tests/LibTLS/TestTLSCertificateParser.cpp LibTLS LIBS LibTLS LibCrypto)
  457. # LibCore
  458. lagom_test(../../Tests/LibCore/TestLibCoreArgsParser.cpp)
  459. if ((LINUX OR APPLE) AND NOT EMSCRIPTEN)
  460. lagom_test(../../Tests/LibCore/TestLibCoreFileWatcher.cpp)
  461. lagom_test(../../Tests/LibCore/TestLibCorePromise.cpp LIBS LibThreading)
  462. endif()
  463. lagom_test(../../Tests/LibCore/TestLibCoreDateTime.cpp LIBS LibUnicode)
  464. # RegexLibC test POSIX <regex.h> and contains many Serenity extensions
  465. # It is therefore not reasonable to run it on Lagom, and we only run the Regex test
  466. lagom_test(../../Tests/LibRegex/Regex.cpp LIBS LibRegex WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/LibRegex)
  467. # JavaScriptTestRunner + LibTest tests
  468. # test-js
  469. add_executable(test-js
  470. ../../Tests/LibJS/test-js.cpp
  471. ../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp)
  472. target_link_libraries(test-js AK LibCore LibFileSystem LibTest LibJS)
  473. add_test(
  474. NAME JS
  475. COMMAND test-js --show-progress=false
  476. )
  477. set_tests_properties(JS PROPERTIES ENVIRONMENT LADYBIRD_SOURCE_DIR=${SERENITY_PROJECT_ROOT})
  478. # Extra tests from Tests/LibJS
  479. lagom_test(../../Tests/LibJS/test-invalid-unicode-js.cpp LIBS LibJS)
  480. lagom_test(../../Tests/LibJS/test-value-js.cpp LIBS LibJS)
  481. # test-wasm
  482. add_executable(test-wasm
  483. ../../Tests/LibWasm/test-wasm.cpp
  484. ../../Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp)
  485. target_link_libraries(test-wasm AK LibCore LibFileSystem LibTest LibWasm LibJS LibCrypto)
  486. set(wasm_test_root "${SERENITY_PROJECT_ROOT}")
  487. if (INCLUDE_WASM_SPEC_TESTS)
  488. set(wasm_test_root "${CMAKE_CURRENT_BINARY_DIR}")
  489. endif()
  490. add_test(
  491. NAME Wasm
  492. COMMAND test-wasm --show-progress=false "${wasm_test_root}/Userland/Libraries/LibWasm/Tests"
  493. )
  494. endif()
  495. # FIXME: When we are using CMake >= 3.21, the library installations can be replaced with RUNTIME_DEPENDENCIES.
  496. # https://cmake.org/cmake/help/latest/command/install.html
  497. include(get_linked_lagom_libraries.cmake)
  498. get_linked_lagom_libraries(js js_libraries)
  499. install(TARGETS js ${js_libraries} COMPONENT js)
  500. set(CPACK_GENERATOR "TGZ")
  501. set(CPACK_STRIP_FILES TRUE)
  502. set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
  503. set(CPACK_COMPONENTS_ALL js)
  504. if (APPLE)
  505. if("arm64" IN_LIST CMAKE_OSX_ARCHITECTURES AND "x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES)
  506. set(CPACK_SYSTEM_NAME "macOS-universal2")
  507. else()
  508. set(CPACK_SYSTEM_NAME "macOS-${CMAKE_SYSTEM_PROCESSOR}")
  509. endif()
  510. else()
  511. set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
  512. endif()
  513. set(CPACK_ARCHIVE_JS_FILE_NAME "ladybird-js-${CPACK_SYSTEM_NAME}")
  514. set(CPACK_PACKAGE_FILE_NAME "ladybird-js-${CPACK_SYSTEM_NAME}")
  515. include(CPack)