mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 08:11:13 +00:00
CMake: Ensure C/C++ compile options only applied when compiling C/C++
This commit is contained in:
parent
02ba51f203
commit
4066ce2c7e
Notes:
github-actions[bot]
2024-07-21 21:56:48 +00:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/4066ce2c7ef Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/726
|
@ -34,24 +34,24 @@ include(lagom_compile_options)
|
||||||
include(lagom_install_options)
|
include(lagom_install_options)
|
||||||
|
|
||||||
if (ENABLE_ADDRESS_SANITIZER)
|
if (ENABLE_ADDRESS_SANITIZER)
|
||||||
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
add_cxx_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
||||||
add_link_options(-fsanitize=address)
|
add_cxx_link_options(-fsanitize=address)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ENABLE_MEMORY_SANITIZER)
|
if (ENABLE_MEMORY_SANITIZER)
|
||||||
add_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
|
add_cxx_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
|
||||||
add_link_options(-fsanitize=memory -fsanitize-memory-track-origins)
|
add_cxx_link_options(-fsanitize=memory -fsanitize-memory-track-origins)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ENABLE_UNDEFINED_SANITIZER)
|
if (ENABLE_UNDEFINED_SANITIZER)
|
||||||
add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
|
add_cxx_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
|
||||||
if (UNDEFINED_BEHAVIOR_IS_FATAL)
|
if (UNDEFINED_BEHAVIOR_IS_FATAL)
|
||||||
add_compile_options(-fno-sanitize-recover=undefined)
|
add_cxx_compile_options(-fno-sanitize-recover=undefined)
|
||||||
endif()
|
endif()
|
||||||
if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
|
if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
|
||||||
add_compile_options(-fno-sanitize=function)
|
add_cxx_compile_options(-fno-sanitize=function)
|
||||||
endif()
|
endif()
|
||||||
add_link_options(-fsanitize=undefined)
|
add_cxx_link_options(-fsanitize=undefined)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (HAIKU)
|
if (HAIKU)
|
||||||
|
@ -61,9 +61,9 @@ if (HAIKU)
|
||||||
add_compile_definitions(__USE_GNU)
|
add_compile_definitions(__USE_GNU)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_compile_options(-DAK_DONT_REPLACE_STD)
|
add_compile_definitions(AK_DONT_REPLACE_STD)
|
||||||
add_compile_options(-Wno-expansion-to-defined)
|
add_cxx_compile_options(-Wno-expansion-to-defined)
|
||||||
add_compile_options(-Wno-user-defined-literals)
|
add_cxx_compile_options(-Wno-user-defined-literals)
|
||||||
|
|
||||||
if (ANDROID OR APPLE)
|
if (ANDROID OR APPLE)
|
||||||
serenity_option(ENABLE_QT OFF CACHE BOOL "Build ladybird application using Qt GUI")
|
serenity_option(ENABLE_QT OFF CACHE BOOL "Build ladybird application using Qt GUI")
|
||||||
|
|
|
@ -5,74 +5,90 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
set(CMAKE_COLOR_DIAGNOSTICS ON)
|
set(CMAKE_COLOR_DIAGNOSTICS ON)
|
||||||
|
|
||||||
|
macro(add_cxx_compile_options)
|
||||||
|
set(args "")
|
||||||
|
foreach(arg ${ARGN})
|
||||||
|
string(APPEND args ${arg}$<SEMICOLON>)
|
||||||
|
endforeach()
|
||||||
|
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX,ASM>:${args}>)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(add_cxx_link_options)
|
||||||
|
set(args "")
|
||||||
|
foreach(arg ${ARGN})
|
||||||
|
string(APPEND args ${arg}$<SEMICOLON>)
|
||||||
|
endforeach()
|
||||||
|
add_link_options($<$<LINK_LANGUAGE:C,CXX>:${args}>)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
add_compile_options(/W4)
|
add_cxx_compile_options(/W4)
|
||||||
# do not warn about unused function
|
# do not warn about unused function
|
||||||
add_compile_options(/wd4505)
|
add_cxx_compile_options(/wd4505)
|
||||||
# disable exceptions
|
# disable exceptions
|
||||||
add_compile_options(/EHsc)
|
add_cxx_compile_options(/EHsc)
|
||||||
# disable floating-point expression contraction
|
# disable floating-point expression contraction
|
||||||
add_compile_options(/fp:precise)
|
add_cxx_compile_options(/fp:precise)
|
||||||
else()
|
else()
|
||||||
add_compile_options(-Wall -Wextra)
|
add_cxx_compile_options(-Wall -Wextra)
|
||||||
add_compile_options(-fno-exceptions)
|
add_cxx_compile_options(-fno-exceptions)
|
||||||
add_compile_options(-ffp-contract=off)
|
add_cxx_compile_options(-ffp-contract=off)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_compile_options(-Wcast-qual)
|
add_cxx_compile_options(-Wcast-qual)
|
||||||
add_compile_options(-Wformat=2)
|
add_cxx_compile_options(-Wformat=2)
|
||||||
add_compile_options(-Wimplicit-fallthrough)
|
add_cxx_compile_options(-Wimplicit-fallthrough)
|
||||||
add_compile_options(-Wmissing-declarations)
|
add_cxx_compile_options(-Wmissing-declarations)
|
||||||
add_compile_options(-Wsuggest-override)
|
add_cxx_compile_options(-Wsuggest-override)
|
||||||
|
|
||||||
add_compile_options(-Wno-invalid-offsetof)
|
add_cxx_compile_options(-Wno-invalid-offsetof)
|
||||||
add_compile_options(-Wno-unknown-warning-option)
|
add_cxx_compile_options(-Wno-unknown-warning-option)
|
||||||
add_compile_options(-Wno-unused-command-line-argument)
|
add_cxx_compile_options(-Wno-unused-command-line-argument)
|
||||||
|
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "18")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "18")
|
||||||
add_compile_options(-Wpadded-bitfield)
|
add_cxx_compile_options(-Wpadded-bitfield)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT CMAKE_HOST_SYSTEM_NAME MATCHES SerenityOS)
|
if (NOT CMAKE_HOST_SYSTEM_NAME MATCHES SerenityOS)
|
||||||
# FIXME: Something makes this go crazy and flag unused variables that aren't flagged as such when building with the toolchain.
|
# FIXME: Something makes this go crazy and flag unused variables that aren't flagged as such when building with the toolchain.
|
||||||
# Disable -Werror for now.
|
# Disable -Werror for now.
|
||||||
add_compile_options(-Werror)
|
add_cxx_compile_options(-Werror)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
|
||||||
# Clang's default constexpr-steps limit is 1048576(2^20), GCC doesn't have one
|
# Clang's default constexpr-steps limit is 1048576(2^20), GCC doesn't have one
|
||||||
add_compile_options(-fconstexpr-steps=16777216)
|
add_cxx_compile_options(-fconstexpr-steps=16777216)
|
||||||
|
|
||||||
add_compile_options(-Wmissing-prototypes)
|
add_cxx_compile_options(-Wmissing-prototypes)
|
||||||
|
|
||||||
add_compile_options(-Wno-implicit-const-int-float-conversion)
|
add_cxx_compile_options(-Wno-implicit-const-int-float-conversion)
|
||||||
add_compile_options(-Wno-user-defined-literals)
|
add_cxx_compile_options(-Wno-user-defined-literals)
|
||||||
add_compile_options(-Wno-vla-cxx-extension)
|
add_cxx_compile_options(-Wno-vla-cxx-extension)
|
||||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
# Only ignore expansion-to-defined for g++, clang's implementation doesn't complain about function-like macros
|
# Only ignore expansion-to-defined for g++, clang's implementation doesn't complain about function-like macros
|
||||||
add_compile_options(-Wno-expansion-to-defined)
|
add_cxx_compile_options(-Wno-expansion-to-defined)
|
||||||
add_compile_options(-Wno-literal-suffix)
|
add_cxx_compile_options(-Wno-literal-suffix)
|
||||||
|
|
||||||
# FIXME: This warning seems useful but has too many false positives with GCC 13.
|
# FIXME: This warning seems useful but has too many false positives with GCC 13.
|
||||||
add_compile_options(-Wno-dangling-reference)
|
add_cxx_compile_options(-Wno-dangling-reference)
|
||||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
|
||||||
add_compile_options(-Wno-reserved-identifier)
|
add_cxx_compile_options(-Wno-reserved-identifier)
|
||||||
add_compile_options(-Wno-user-defined-literals)
|
add_cxx_compile_options(-Wno-user-defined-literals)
|
||||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||||
|
|
||||||
# TODO: this seems wrong, but we use this kind of code too much
|
# TODO: this seems wrong, but we use this kind of code too much
|
||||||
# add_compile_options(-Wno-unsafe-buffer-usage)
|
# add_cxx_compile_options(-Wno-unsafe-buffer-usage)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (UNIX AND NOT APPLE AND NOT ENABLE_FUZZERS)
|
if (UNIX AND NOT APPLE AND NOT ENABLE_FUZZERS)
|
||||||
add_compile_options(-fno-semantic-interposition)
|
add_cxx_compile_options(-fno-semantic-interposition)
|
||||||
add_compile_options(-fvisibility-inlines-hidden)
|
add_cxx_compile_options(-fvisibility-inlines-hidden)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
add_compile_options(-fstack-protector-strong)
|
add_cxx_compile_options(-fstack-protector-strong)
|
||||||
add_link_options(-fstack-protector-strong)
|
add_cxx_link_options(-fstack-protector-strong)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_compile_options(-fstrict-flex-arrays=2)
|
add_cxx_compile_options(-fstrict-flex-arrays=2)
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
include(${CMAKE_CURRENT_LIST_DIR}/common_compile_options.cmake)
|
include(${CMAKE_CURRENT_LIST_DIR}/common_compile_options.cmake)
|
||||||
|
|
||||||
add_compile_options(-Wno-maybe-uninitialized)
|
add_cxx_compile_options(-Wno-maybe-uninitialized)
|
||||||
add_compile_options(-Wno-shorten-64-to-32)
|
add_cxx_compile_options(-Wno-shorten-64-to-32)
|
||||||
|
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
add_compile_options(-fsigned-char)
|
add_cxx_compile_options(-fsigned-char)
|
||||||
add_compile_options(-ggnu-pubnames)
|
add_cxx_compile_options(-ggnu-pubnames)
|
||||||
else()
|
else()
|
||||||
# char is signed
|
# char is signed
|
||||||
add_compile_options(/J)
|
add_cxx_compile_options(/J)
|
||||||
# full symbolic debugginng information
|
# full symbolic debugginng information
|
||||||
add_compile_options(/Z7)
|
add_cxx_compile_options(/Z7)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
add_compile_options(-fPIC)
|
add_cxx_compile_options(-fPIC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (LINUX)
|
if (LINUX)
|
||||||
add_compile_options(-D_FILE_OFFSET_BITS=64)
|
add_compile_definitions(_FILE_OFFSET_BITS=64)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
|
@ -27,33 +27,33 @@ endif()
|
||||||
|
|
||||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||||
if (NOT MSVC)
|
if (NOT MSVC)
|
||||||
add_compile_options(-ggdb3)
|
add_cxx_compile_options(-ggdb3)
|
||||||
endif()
|
endif()
|
||||||
add_compile_options(-Og)
|
add_cxx_compile_options(-Og)
|
||||||
else()
|
else()
|
||||||
add_compile_options(-O2)
|
add_cxx_compile_options(-O2)
|
||||||
add_compile_options(-g1)
|
add_cxx_compile_options(-g1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
function(add_linker_flag_if_supported flag)
|
function(add_cxx_linker_flag_if_supported flag)
|
||||||
include(CheckLinkerFlag)
|
include(CheckLinkerFlag)
|
||||||
|
|
||||||
check_linker_flag(CXX ${flag} LAGOM_LINKER_SUPPORTS_${flag})
|
check_linker_flag(CXX ${flag} LAGOM_LINKER_SUPPORTS_${flag})
|
||||||
if (${LAGOM_LINKER_SUPPORTS_${flag}})
|
if (${LAGOM_LINKER_SUPPORTS_${flag}})
|
||||||
add_link_options(${flag})
|
add_cxx_link_options(${flag})
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
add_linker_flag_if_supported(LINKER:--gdb-index)
|
add_cxx_linker_flag_if_supported(LINKER:--gdb-index)
|
||||||
|
|
||||||
if (NOT ENABLE_FUZZERS)
|
if (NOT ENABLE_FUZZERS)
|
||||||
add_linker_flag_if_supported(LINKER:-Bsymbolic-non-weak-functions)
|
add_cxx_linker_flag_if_supported(LINKER:-Bsymbolic-non-weak-functions)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ENABLE_LAGOM_COVERAGE_COLLECTION)
|
if (ENABLE_LAGOM_COVERAGE_COLLECTION)
|
||||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND NOT ENABLE_FUZZERS)
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND NOT ENABLE_FUZZERS)
|
||||||
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
|
add_cxx_compile_options(-fprofile-instr-generate -fcoverage-mapping)
|
||||||
add_link_options(-fprofile-instr-generate)
|
add_cxx_link_options(-fprofile-instr-generate)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR
|
||||||
"Collecting code coverage is unsupported in this configuration.")
|
"Collecting code coverage is unsupported in this configuration.")
|
||||||
|
|
|
@ -88,27 +88,27 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
if (EMSCRIPTEN)
|
if (EMSCRIPTEN)
|
||||||
set(CMAKE_EXECUTABLE_SUFFIX ".js")
|
set(CMAKE_EXECUTABLE_SUFFIX ".js")
|
||||||
add_compile_options(-gsource-map)
|
add_cxx_compile_options(-gsource-map)
|
||||||
add_link_options(--emrun "SHELL:-s ALLOW_MEMORY_GROWTH")
|
add_cxx_link_options(--emrun "SHELL:-s ALLOW_MEMORY_GROWTH")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ENABLE_ADDRESS_SANITIZER)
|
if (ENABLE_ADDRESS_SANITIZER)
|
||||||
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
add_cxx_compile_options(-fsanitize=address -fno-omit-frame-pointer)
|
||||||
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=address")
|
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=address")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ENABLE_MEMORY_SANITIZER)
|
if (ENABLE_MEMORY_SANITIZER)
|
||||||
add_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
|
add_cxx_compile_options(-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer)
|
||||||
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins")
|
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ENABLE_UNDEFINED_SANITIZER)
|
if (ENABLE_UNDEFINED_SANITIZER)
|
||||||
add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
|
add_cxx_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
|
||||||
if (UNDEFINED_BEHAVIOR_IS_FATAL)
|
if (UNDEFINED_BEHAVIOR_IS_FATAL)
|
||||||
add_compile_options(-fno-sanitize-recover=undefined)
|
add_cxx_compile_options(-fno-sanitize-recover=undefined)
|
||||||
endif()
|
endif()
|
||||||
if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
|
if (APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang$" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
|
||||||
add_compile_options(-fno-sanitize=function)
|
add_cxx_compile_options(-fno-sanitize=function)
|
||||||
endif()
|
endif()
|
||||||
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=undefined")
|
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=undefined")
|
||||||
endif()
|
endif()
|
||||||
|
@ -125,7 +125,7 @@ if (HAIKU)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ENABLE_FUZZERS)
|
if (ENABLE_FUZZERS)
|
||||||
add_compile_options(-fno-omit-frame-pointer)
|
add_cxx_compile_options(-fno-omit-frame-pointer)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSEAUDIO)
|
CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSEAUDIO)
|
||||||
|
@ -134,14 +134,14 @@ add_library(JSClangPlugin INTERFACE)
|
||||||
add_library(GenericClangPlugin INTERFACE)
|
add_library(GenericClangPlugin INTERFACE)
|
||||||
|
|
||||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
|
||||||
add_compile_options(-Wno-overloaded-virtual)
|
add_cxx_compile_options(-Wno-overloaded-virtual)
|
||||||
# FIXME: Re-enable this check when the warning stops triggering, or document why we can't stop it from triggering.
|
# FIXME: Re-enable this check when the warning stops triggering, or document why we can't stop it from triggering.
|
||||||
# For now, there is a lot of unused private fields in LibWeb that trigger this that could be removed.
|
# For now, there is a lot of unused private fields in LibWeb that trigger this that could be removed.
|
||||||
# See issue #14137 for details
|
# See issue #14137 for details
|
||||||
add_compile_options(-Wno-unused-private-field)
|
add_cxx_compile_options(-Wno-unused-private-field)
|
||||||
|
|
||||||
if (ENABLE_FUZZERS_LIBFUZZER)
|
if (ENABLE_FUZZERS_LIBFUZZER)
|
||||||
add_compile_options(-fsanitize=fuzzer)
|
add_cxx_compile_options(-fsanitize=fuzzer)
|
||||||
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=fuzzer")
|
set(LINKER_FLAGS "${LINKER_FLAGS} -fsanitize=fuzzer")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
add_compile_options(-Wvla)
|
add_cxx_compile_options(-Wvla)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
AEAD/ChaCha20Poly1305.cpp
|
AEAD/ChaCha20Poly1305.cpp
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
add_compile_options(-Wvla)
|
add_cxx_compile_options(-Wvla)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
Certificate.cpp
|
Certificate.cpp
|
||||||
|
|
Loading…
Reference in a new issue