CMakeLists.txt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. cmake_minimum_required(VERSION 3.25)
  2. if (VCPKG_TARGET_ANDROID)
  3. # If we are building for Android, we must load vcpkg_android.cmake before the project() declaration.
  4. # This ensures that the CMAKE_TOOLCHAIN_FILE is set correctly.
  5. # (we cannot set CMAKE_TOOLCHAIN_FILE from Gradle, unfortunately, so this is the only place we can do it.)
  6. include("UI/Android/vcpkg_android.cmake")
  7. endif()
  8. # vcpkg flags depend on what linker we are using
  9. include("Meta/CMake/use_linker.cmake")
  10. # Pass additional information to vcpkg toolchain files if we are using vcpkg.
  11. if (CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg.cmake$")
  12. set(CMAKE_PROJECT_ladybird_INCLUDE_BEFORE "Meta/CMake/vcpkg/generate_vcpkg_toolchain_variables.cmake")
  13. endif()
  14. project(ladybird
  15. VERSION 0.1.0
  16. LANGUAGES C CXX
  17. DESCRIPTION "Ladybird Web Browser"
  18. HOMEPAGE_URL "https://ladybird.org"
  19. )
  20. if (ANDROID OR IOS)
  21. set(BUILD_SHARED_LIBS OFF)
  22. endif()
  23. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  24. set(LADYBIRD_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
  25. list(APPEND CMAKE_MODULE_PATH "${LADYBIRD_SOURCE_DIR}/Meta/CMake")
  26. include(UI/cmake/EnableLagom.cmake)
  27. include(lagom_options NO_POLICY_SCOPE)
  28. include(lagom_compile_options)
  29. if (ENABLE_ADDRESS_SANITIZER)
  30. add_cxx_compile_options(-fsanitize=address -fno-omit-frame-pointer)
  31. add_cxx_link_options(-fsanitize=address)
  32. add_swift_compile_options(-sanitize=address)
  33. add_swift_link_options(-sanitize=address)
  34. endif()
  35. if (ENABLE_MEMORY_SANITIZER)
  36. add_cxx_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
  37. add_cxx_link_options(-fsanitize=memory -fsanitize-memory-track-origins)
  38. endif()
  39. if (ENABLE_UNDEFINED_SANITIZER AND (APPLE OR NOT ENABLE_SWIFT))
  40. add_cxx_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
  41. if (UNDEFINED_BEHAVIOR_IS_FATAL)
  42. add_cxx_compile_options(-fno-sanitize-recover=undefined)
  43. endif()
  44. if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
  45. add_cxx_compile_options(-fno-sanitize=function)
  46. endif()
  47. add_cxx_link_options(-fsanitize=undefined)
  48. add_swift_compile_options(-sanitize=undefined)
  49. add_swift_link_options(-sanitize=undefined)
  50. endif()
  51. if (HAIKU)
  52. # Haiku needs some extra compile definitions to make important stuff in its headers available.
  53. add_compile_definitions(_DEFAULT_SOURCE)
  54. add_compile_definitions(_GNU_SOURCE)
  55. add_compile_definitions(__USE_GNU)
  56. endif()
  57. add_cxx_compile_options(-Wno-expansion-to-defined)
  58. add_cxx_compile_options(-Wno-user-defined-literals)
  59. if (ANDROID AND ENABLE_QT)
  60. message(STATUS "Disabling Qt for Android")
  61. set(ENABLE_QT OFF CACHE BOOL "" FORCE)
  62. endif()
  63. if (ENABLE_QT AND ENABLE_GUI_TARGETS)
  64. set(CMAKE_AUTOMOC ON)
  65. set(CMAKE_AUTORCC ON)
  66. set(CMAKE_AUTOUIC ON)
  67. find_package(Qt6 REQUIRED COMPONENTS Core Widgets)
  68. endif()
  69. # We need to find OpenSSL in order to link it explicitly with all targets.
  70. find_package(OpenSSL REQUIRED)
  71. include(CTest) # for BUILD_TESTING option, default ON
  72. if (ENABLE_GUI_TARGETS)
  73. add_subdirectory(Services)
  74. add_subdirectory(UI)
  75. endif()
  76. add_custom_target(lint-shell-scripts
  77. COMMAND "${ladybird_SOURCE_DIR}/Meta/lint-shell-scripts.sh"
  78. USES_TERMINAL
  79. )
  80. find_package(Python3 COMPONENTS Interpreter)
  81. if (Python3_FOUND)
  82. add_custom_target(check-style
  83. COMMAND ${Python3_EXECUTABLE} "${ladybird_SOURCE_DIR}/Meta/check-style.py"
  84. USES_TERMINAL
  85. )
  86. endif()