mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 16:16:43 +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: 4066ce2c7e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/726
6 changed files with 91 additions and 75 deletions
|
@ -5,74 +5,90 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
|||
|
||||
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)
|
||||
add_compile_options(/W4)
|
||||
add_cxx_compile_options(/W4)
|
||||
# do not warn about unused function
|
||||
add_compile_options(/wd4505)
|
||||
add_cxx_compile_options(/wd4505)
|
||||
# disable exceptions
|
||||
add_compile_options(/EHsc)
|
||||
add_cxx_compile_options(/EHsc)
|
||||
# disable floating-point expression contraction
|
||||
add_compile_options(/fp:precise)
|
||||
add_cxx_compile_options(/fp:precise)
|
||||
else()
|
||||
add_compile_options(-Wall -Wextra)
|
||||
add_compile_options(-fno-exceptions)
|
||||
add_compile_options(-ffp-contract=off)
|
||||
add_cxx_compile_options(-Wall -Wextra)
|
||||
add_cxx_compile_options(-fno-exceptions)
|
||||
add_cxx_compile_options(-ffp-contract=off)
|
||||
endif()
|
||||
|
||||
add_compile_options(-Wcast-qual)
|
||||
add_compile_options(-Wformat=2)
|
||||
add_compile_options(-Wimplicit-fallthrough)
|
||||
add_compile_options(-Wmissing-declarations)
|
||||
add_compile_options(-Wsuggest-override)
|
||||
add_cxx_compile_options(-Wcast-qual)
|
||||
add_cxx_compile_options(-Wformat=2)
|
||||
add_cxx_compile_options(-Wimplicit-fallthrough)
|
||||
add_cxx_compile_options(-Wmissing-declarations)
|
||||
add_cxx_compile_options(-Wsuggest-override)
|
||||
|
||||
add_compile_options(-Wno-invalid-offsetof)
|
||||
add_compile_options(-Wno-unknown-warning-option)
|
||||
add_compile_options(-Wno-unused-command-line-argument)
|
||||
add_cxx_compile_options(-Wno-invalid-offsetof)
|
||||
add_cxx_compile_options(-Wno-unknown-warning-option)
|
||||
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")
|
||||
add_compile_options(-Wpadded-bitfield)
|
||||
add_cxx_compile_options(-Wpadded-bitfield)
|
||||
endif()
|
||||
|
||||
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.
|
||||
# Disable -Werror for now.
|
||||
add_compile_options(-Werror)
|
||||
add_cxx_compile_options(-Werror)
|
||||
endif()
|
||||
|
||||
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
|
||||
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_compile_options(-Wno-user-defined-literals)
|
||||
add_compile_options(-Wno-vla-cxx-extension)
|
||||
add_cxx_compile_options(-Wno-implicit-const-int-float-conversion)
|
||||
add_cxx_compile_options(-Wno-user-defined-literals)
|
||||
add_cxx_compile_options(-Wno-vla-cxx-extension)
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
# 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_compile_options(-Wno-literal-suffix)
|
||||
add_cxx_compile_options(-Wno-expansion-to-defined)
|
||||
add_cxx_compile_options(-Wno-literal-suffix)
|
||||
|
||||
# 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")
|
||||
add_compile_options(-Wno-reserved-identifier)
|
||||
add_compile_options(-Wno-user-defined-literals)
|
||||
add_cxx_compile_options(-Wno-reserved-identifier)
|
||||
add_cxx_compile_options(-Wno-user-defined-literals)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
|
||||
# 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()
|
||||
|
||||
if (UNIX AND NOT APPLE AND NOT ENABLE_FUZZERS)
|
||||
add_compile_options(-fno-semantic-interposition)
|
||||
add_compile_options(-fvisibility-inlines-hidden)
|
||||
add_cxx_compile_options(-fno-semantic-interposition)
|
||||
add_cxx_compile_options(-fvisibility-inlines-hidden)
|
||||
endif()
|
||||
|
||||
if (NOT WIN32)
|
||||
add_compile_options(-fstack-protector-strong)
|
||||
add_link_options(-fstack-protector-strong)
|
||||
add_cxx_compile_options(-fstack-protector-strong)
|
||||
add_cxx_link_options(-fstack-protector-strong)
|
||||
endif()
|
||||
|
||||
add_compile_options(-fstrict-flex-arrays=2)
|
||||
add_cxx_compile_options(-fstrict-flex-arrays=2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue