mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
Meta: Move all compile options to one file
This is the first step to unify the common / lagom code paths which are not relevant since the SerenityOS fork.
This commit is contained in:
Notes:
github-actions[bot]
2026-03-29 20:01:36 +00:00
Author: https://github.com/cqundefine Commit: https://github.com/LadybirdBrowser/ladybird/commit/ceca4a701b3 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8650 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/spholz
@@ -41,17 +41,7 @@ list(APPEND CMAKE_MODULE_PATH "${LADYBIRD_SOURCE_DIR}/Meta/CMake")
|
||||
|
||||
include(UI/cmake/EnableLagom.cmake)
|
||||
include(lagom_options NO_POLICY_SCOPE)
|
||||
include(lagom_compile_options)
|
||||
|
||||
if (HAIKU)
|
||||
# Haiku needs some extra compile definitions to make important stuff in its headers available.
|
||||
add_compile_definitions(_DEFAULT_SOURCE)
|
||||
add_compile_definitions(_GNU_SOURCE)
|
||||
add_compile_definitions(__USE_GNU)
|
||||
endif()
|
||||
|
||||
add_cxx_compile_options(-Wno-expansion-to-defined)
|
||||
add_cxx_compile_options(-Wno-user-defined-literals)
|
||||
include(compile_options)
|
||||
|
||||
# We need to find OpenSSL in order to link it explicitly with all targets.
|
||||
find_package(OpenSSL REQUIRED)
|
||||
|
||||
@@ -147,10 +147,10 @@ If you do run into such an error, the rest of this section explains how to deal
|
||||
|
||||
```diff
|
||||
$ patch -p1 <<EOF
|
||||
diff --git a/Meta/CMake/lagom_compile_options.cmake b/Meta/CMake/lagom_compile_options.cmake
|
||||
diff --git a/Meta/CMake/compile_options.cmake b/Meta/CMake/compile_options.cmake
|
||||
index 7fec47ac843..45c3af87493 100644
|
||||
--- a/Meta/CMake/lagom_compile_options.cmake
|
||||
+++ b/Meta/CMake/lagom_compile_options.cmake
|
||||
--- a/Meta/CMake/compile_options.cmake
|
||||
+++ b/Meta/CMake/compile_options.cmake
|
||||
@@ -29,7 +29,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
if (NOT MSVC)
|
||||
add_cxx_compile_options(-ggdb3)
|
||||
@@ -169,7 +169,7 @@ If you do run into such an error, the rest of this section explains how to deal
|
||||
2. At your command-line prompt in your shell environment, run the following command:
|
||||
|
||||
```
|
||||
git update-index --skip-worktree Meta/CMake/lagom_compile_options.cmake
|
||||
git update-index --skip-worktree Meta/CMake/compile_options.cmake
|
||||
```
|
||||
|
||||
That will cause git to ignore the change you made to that build file. Otherwise, if you don’t run that command, git will consider that build file to have been modified, and you might then end up inadvertently committing the changes to that build file as part of some actual code change you’re making to the sources that you’re in the process of debugging.
|
||||
@@ -181,8 +181,8 @@ After you’ve finished debugging your code changes with that build, you can rev
|
||||
1. At your command-line prompt in your shell environment, run the following:
|
||||
|
||||
```
|
||||
git update-index --no-skip-worktree Meta/CMake/lagom_compile_options.cmake \
|
||||
&& git checkout Meta/CMake/lagom_compile_options.cmake
|
||||
git update-index --no-skip-worktree Meta/CMake/compile_options.cmake \
|
||||
&& git checkout Meta/CMake/compile_options.cmake
|
||||
```
|
||||
|
||||
That will restore your git environment to the state it was in before you patched the build file.
|
||||
|
||||
@@ -74,9 +74,13 @@ add_cxx_compile_options(-Wmissing-declarations)
|
||||
add_cxx_compile_options(-Wmissing-field-initializers)
|
||||
add_cxx_compile_options(-Wsuggest-override)
|
||||
|
||||
add_cxx_compile_options(-Wno-expansion-to-defined)
|
||||
add_cxx_compile_options(-Wno-invalid-offsetof)
|
||||
add_cxx_compile_options(-Wno-maybe-uninitialized)
|
||||
add_cxx_compile_options(-Wno-shorten-64-to-32)
|
||||
add_cxx_compile_options(-Wno-unknown-warning-option)
|
||||
add_cxx_compile_options(-Wno-unused-command-line-argument)
|
||||
add_cxx_compile_options(-Wno-user-defined-literals)
|
||||
|
||||
add_cxx_compile_options(-Werror)
|
||||
|
||||
@@ -90,6 +94,8 @@ if (NOT MSVC)
|
||||
add_cxx_compile_options(-ffp-contract=off)
|
||||
add_cxx_compile_options(-fstrict-flex-arrays=2)
|
||||
add_cxx_compile_options(-fstack-protector-strong)
|
||||
add_cxx_compile_options(-fsigned-char)
|
||||
add_cxx_compile_options(-ggnu-pubnames)
|
||||
add_cxx_link_options(-fstack-protector-strong)
|
||||
if (UNIX AND NOT APPLE AND NOT ENABLE_FUZZERS)
|
||||
add_cxx_compile_options(-fno-semantic-interposition)
|
||||
@@ -146,6 +152,9 @@ elseif (MSVC)
|
||||
# TODO: Use export macros everywhere
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
|
||||
# full symbolic debugginng information
|
||||
add_cxx_compile_options(/Z7)
|
||||
|
||||
# Compiler options
|
||||
# disable exceptions
|
||||
add_cxx_compile_options(/EHs-)
|
||||
@@ -179,3 +188,99 @@ elseif (MSVC)
|
||||
endif()
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/sanitizers.cmake)
|
||||
|
||||
include(CheckPIESupported)
|
||||
check_pie_supported(LANGUAGES CXX)
|
||||
if(CMAKE_CXX_LINK_PIE_SUPPORTED)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
|
||||
if (LINUX)
|
||||
add_cxx_compile_definitions(_FILE_OFFSET_BITS=64)
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
list(APPEND CMAKE_PREFIX_PATH /opt/homebrew)
|
||||
add_cxx_link_options(LINKER:-dead_strip)
|
||||
endif()
|
||||
|
||||
if (HAIKU)
|
||||
# Haiku needs some extra compile definitions to make important stuff in its headers available.
|
||||
add_compile_definitions(_DEFAULT_SOURCE)
|
||||
add_compile_definitions(_GNU_SOURCE)
|
||||
add_compile_definitions(__USE_GNU)
|
||||
endif()
|
||||
|
||||
if (NOT WIN32)
|
||||
add_cxx_link_option_if_supported(LINKER:--gdb-index)
|
||||
|
||||
if (NOT ENABLE_FUZZERS)
|
||||
add_cxx_link_option_if_supported(LINKER:-Bsymbolic-non-weak-functions)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT WIN32 AND NOT APPLE AND NOT ENABLE_FUZZERS)
|
||||
# NOTE: Assume ELF
|
||||
# NOTE: --no-undefined is not compatible with clang sanitizer runtimes
|
||||
# NOTE: Some BSDs don't export all symbols from LibC so we can't use --no-undefined
|
||||
if ((CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND (ENABLE_ADDRESS_SANITIZER OR ENABLE_MEMORY_SANITIZER OR ENABLE_UNDEFINED_SANITIZER OR ENABLE_LAGOM_COVERAGE_COLLECTION)) OR BSD)
|
||||
add_link_options(LINKER:--allow-shlib-undefined)
|
||||
add_link_options(LINKER:-z,undefs)
|
||||
else()
|
||||
add_link_options(LINKER:-z,defs)
|
||||
add_link_options(LINKER:--no-undefined)
|
||||
add_link_options(LINKER:--no-allow-shlib-undefined)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
if (NOT MSVC)
|
||||
add_cxx_compile_options(-ggdb3)
|
||||
add_cxx_compile_options(-Og)
|
||||
endif()
|
||||
elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||
if (NOT MSVC)
|
||||
add_cxx_compile_options(-O2)
|
||||
add_cxx_compile_options(-g1)
|
||||
else()
|
||||
# Add OPT:REF either way as it doesn't impact debugging experience negatively and decreases binary size
|
||||
# see: https://learn.microsoft.com/en-us/cpp/build/reference/opt-optimizations?view=msvc-170
|
||||
# This doesn't play nicely with ASAN
|
||||
if (NOT ENABLE_ADDRESS_SANITIZER)
|
||||
add_cxx_link_options(/OPT:REF)
|
||||
endif()
|
||||
# Override /Ob1 that cmake adds to allow inlining on all functions.
|
||||
# This makes debugging worse but is closer to a normal build for profiling and testing.
|
||||
add_cxx_compile_options(/O2)
|
||||
endif()
|
||||
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
if (NOT MSVC)
|
||||
add_cxx_compile_options(-O3)
|
||||
else()
|
||||
add_cxx_compile_options(/O2)
|
||||
endif()
|
||||
|
||||
if (ENABLE_LTO_FOR_RELEASE)
|
||||
include(CheckIPOSupported)
|
||||
check_ipo_supported(RESULT IPO_AVAILABLE OUTPUT output)
|
||||
if(IPO_AVAILABLE)
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
else()
|
||||
message(WARNING "Not enabling IPO as it is not supported: ${output}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (ENABLE_LAGOM_COVERAGE_COLLECTION)
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND NOT ENABLE_FUZZERS)
|
||||
add_cxx_compile_options(-fprofile-instr-generate -fcoverage-mapping)
|
||||
add_cxx_link_options(-fprofile-instr-generate)
|
||||
else()
|
||||
message(FATAL_ERROR
|
||||
"Collecting code coverage is unsupported in this configuration.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (ENABLE_FUZZERS)
|
||||
add_cxx_compile_options(-fno-omit-frame-pointer)
|
||||
endif()
|
||||
@@ -1,97 +0,0 @@
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/common_compile_options.cmake)
|
||||
|
||||
add_cxx_compile_options(-Wno-maybe-uninitialized)
|
||||
add_cxx_compile_options(-Wno-shorten-64-to-32)
|
||||
|
||||
if(NOT MSVC)
|
||||
add_cxx_compile_options(-fsigned-char)
|
||||
add_cxx_compile_options(-ggnu-pubnames)
|
||||
else()
|
||||
# full symbolic debugginng information
|
||||
add_cxx_compile_options(/Z7)
|
||||
endif()
|
||||
|
||||
include(CheckPIESupported)
|
||||
check_pie_supported(LANGUAGES CXX)
|
||||
if(CMAKE_CXX_LINK_PIE_SUPPORTED)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
endif()
|
||||
|
||||
if (LINUX)
|
||||
add_cxx_compile_definitions(_FILE_OFFSET_BITS=64)
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
list(APPEND CMAKE_PREFIX_PATH /opt/homebrew)
|
||||
add_cxx_link_options(LINKER:-dead_strip)
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
if (NOT MSVC)
|
||||
add_cxx_compile_options(-ggdb3)
|
||||
add_cxx_compile_options(-Og)
|
||||
endif()
|
||||
elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
||||
if (NOT MSVC)
|
||||
add_cxx_compile_options(-O2)
|
||||
add_cxx_compile_options(-g1)
|
||||
else()
|
||||
# Add OPT:REF either way as it doesn't impact debugging experience negatively and decreases binary size
|
||||
# see: https://learn.microsoft.com/en-us/cpp/build/reference/opt-optimizations?view=msvc-170
|
||||
# This doesn't play nicely with ASAN
|
||||
if (NOT ENABLE_ADDRESS_SANITIZER)
|
||||
add_cxx_link_options(/OPT:REF)
|
||||
endif()
|
||||
# Override /Ob1 that cmake adds to allow inlining on all functions.
|
||||
# This makes debugging worse but is closer to a normal build for profiling and testing.
|
||||
add_cxx_compile_options(/O2)
|
||||
endif()
|
||||
else()
|
||||
if (NOT MSVC)
|
||||
add_cxx_compile_options(-O3)
|
||||
else()
|
||||
add_cxx_compile_options(/O2)
|
||||
endif()
|
||||
|
||||
if (ENABLE_LTO_FOR_RELEASE)
|
||||
include(CheckIPOSupported)
|
||||
check_ipo_supported(RESULT IPO_AVAILABLE OUTPUT output)
|
||||
if(IPO_AVAILABLE)
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||
else()
|
||||
message(WARNING "Not enabling IPO as it is not supported: ${output}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT WIN32)
|
||||
add_cxx_link_option_if_supported(LINKER:--gdb-index)
|
||||
|
||||
if (NOT ENABLE_FUZZERS)
|
||||
add_cxx_link_option_if_supported(LINKER:-Bsymbolic-non-weak-functions)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (NOT WIN32 AND NOT APPLE AND NOT ENABLE_FUZZERS)
|
||||
# NOTE: Assume ELF
|
||||
# NOTE: --no-undefined is not compatible with clang sanitizer runtimes
|
||||
# NOTE: Some BSDs don't export all symbols from LibC so we can't use --no-undefined
|
||||
if ((CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND (ENABLE_ADDRESS_SANITIZER OR ENABLE_MEMORY_SANITIZER OR ENABLE_UNDEFINED_SANITIZER OR ENABLE_LAGOM_COVERAGE_COLLECTION)) OR BSD)
|
||||
add_link_options(LINKER:--allow-shlib-undefined)
|
||||
add_link_options(LINKER:-z,undefs)
|
||||
else()
|
||||
add_link_options(LINKER:-z,defs)
|
||||
add_link_options(LINKER:--no-undefined)
|
||||
add_link_options(LINKER:--no-allow-shlib-undefined)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (ENABLE_LAGOM_COVERAGE_COLLECTION)
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND NOT ENABLE_FUZZERS)
|
||||
add_cxx_compile_options(-fprofile-instr-generate -fcoverage-mapping)
|
||||
add_cxx_link_options(-fprofile-instr-generate)
|
||||
else()
|
||||
message(FATAL_ERROR
|
||||
"Collecting code coverage is unsupported in this configuration.")
|
||||
endif()
|
||||
endif()
|
||||
@@ -79,7 +79,7 @@ if (ENABLE_FUZZERS OR CMAKE_CROSSCOMPILING)
|
||||
set(BUILD_LAGOM_TOOLS OFF)
|
||||
endif()
|
||||
|
||||
include(lagom_compile_options)
|
||||
include(compile_options)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
@@ -87,17 +87,6 @@ if (ENABLE_COMPILETIME_FORMAT_CHECK)
|
||||
add_compile_definitions(ENABLE_COMPILETIME_FORMAT_CHECK)
|
||||
endif()
|
||||
|
||||
if (HAIKU)
|
||||
# Haiku needs some extra compile definitions to make important stuff in its headers available.
|
||||
add_compile_definitions(_DEFAULT_SOURCE)
|
||||
add_compile_definitions(_GNU_SOURCE)
|
||||
add_compile_definitions(__USE_GNU)
|
||||
endif()
|
||||
|
||||
if (ENABLE_FUZZERS)
|
||||
add_cxx_compile_options(-fno-omit-frame-pointer)
|
||||
endif()
|
||||
|
||||
add_library(JSClangPlugin INTERFACE)
|
||||
add_library(GenericClangPlugin INTERFACE)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user