2022-02-03 00:34:01 +01:00
|
|
|
|
|
|
|
# Copyright Catch2 Authors
|
|
|
|
# Distributed under the Boost Software License, Version 1.0.
|
2022-10-28 11:22:53 +02:00
|
|
|
# (See accompanying file LICENSE.txt or copy at
|
2022-02-03 00:34:01 +01:00
|
|
|
# https://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
# SPDX-License-Identifier: BSL-1.0
|
|
|
|
|
2020-02-21 21:15:45 +01:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
function(add_cxx_flag_if_supported_to_targets flagname targets)
|
2022-10-04 15:55:50 +02:00
|
|
|
string(MAKE_C_IDENTIFIER ${flagname} flag_identifier )
|
|
|
|
check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flag_identifier})
|
2020-02-21 21:15:45 +01:00
|
|
|
|
2022-10-04 15:55:50 +02:00
|
|
|
if (HAVE_FLAG_${flag_identifier})
|
2020-02-21 21:15:45 +01:00
|
|
|
foreach(target ${targets})
|
2022-10-24 18:26:40 +02:00
|
|
|
target_compile_options(${target} PRIVATE ${flagname})
|
2020-02-21 21:15:45 +01:00
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Assumes that it is only called for development builds, where warnings
|
|
|
|
# and Werror is desired, so it also enables Werror.
|
|
|
|
function(add_warnings_to_targets targets)
|
|
|
|
LIST(LENGTH targets TARGETS_LEN)
|
|
|
|
# For now we just assume 2 possibilities: msvc and msvc-like compilers,
|
|
|
|
# and other.
|
|
|
|
if (MSVC)
|
|
|
|
foreach(target ${targets})
|
|
|
|
# Force MSVC to consider everything as encoded in utf-8
|
|
|
|
target_compile_options( ${target} PRIVATE /utf-8 )
|
|
|
|
# Enable Werror equivalent
|
|
|
|
if (CATCH_ENABLE_WERROR)
|
|
|
|
target_compile_options( ${target} PRIVATE /WX )
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# MSVC is currently handled specially
|
|
|
|
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
|
|
|
|
STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level
|
|
|
|
target_compile_options( ${target} PRIVATE /w44265 /w44061 /w44062 /w45038 )
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (NOT MSVC)
|
|
|
|
set(CHECKED_WARNING_FLAGS
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wabsolute-value"
|
2020-02-21 21:15:45 +01:00
|
|
|
"-Wall"
|
2022-05-03 10:49:45 +02:00
|
|
|
"-Wc++20-compat"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wcall-to-pure-virtual-from-ctor-dtor"
|
2022-04-28 11:40:52 +02:00
|
|
|
"-Wcast-align"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wcatch-value"
|
2022-05-01 23:15:24 +02:00
|
|
|
"-Wdangling"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wdeprecated"
|
|
|
|
"-Wdeprecated-register"
|
2022-05-01 23:15:24 +02:00
|
|
|
"-Wexceptions"
|
2020-02-21 21:15:45 +01:00
|
|
|
"-Wexit-time-destructors"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wextra"
|
|
|
|
"-Wextra-semi"
|
2022-05-14 15:37:39 +02:00
|
|
|
"-Wfloat-equal"
|
2020-02-21 21:15:45 +01:00
|
|
|
"-Wglobal-constructors"
|
2022-05-01 23:15:24 +02:00
|
|
|
"-Winit-self"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wmisleading-indentation"
|
2022-05-01 23:15:24 +02:00
|
|
|
"-Wmismatched-new-delete"
|
|
|
|
"-Wmismatched-return-types"
|
|
|
|
"-Wmismatched-tags"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wmissing-braces"
|
|
|
|
"-Wmissing-declarations"
|
2020-02-21 21:15:45 +01:00
|
|
|
"-Wmissing-noreturn"
|
2022-05-02 12:57:46 +02:00
|
|
|
"-Wmissing-prototypes"
|
2022-05-02 12:51:46 +02:00
|
|
|
"-Wmissing-variable-declarations"
|
2022-05-01 23:15:24 +02:00
|
|
|
"-Wnull-dereference"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wold-style-cast"
|
2022-05-01 23:15:24 +02:00
|
|
|
"-Woverloaded-virtual"
|
2020-02-21 21:15:45 +01:00
|
|
|
"-Wparentheses"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wpedantic"
|
2022-04-28 11:40:52 +02:00
|
|
|
"-Wreorder"
|
2020-02-21 21:15:45 +01:00
|
|
|
"-Wreturn-std-move"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wshadow"
|
|
|
|
"-Wstrict-aliasing"
|
2022-05-02 10:45:02 +02:00
|
|
|
"-Wsuggest-destructor-override"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wsuggest-override"
|
2020-05-12 13:57:16 +02:00
|
|
|
"-Wundef"
|
2022-05-01 23:15:24 +02:00
|
|
|
"-Wuninitialized"
|
|
|
|
"-Wunneeded-internal-declaration"
|
2023-04-19 10:12:44 +02:00
|
|
|
"-Wunreachable-code-aggressive"
|
2022-04-28 11:40:52 +02:00
|
|
|
"-Wunused"
|
2020-05-12 13:57:16 +02:00
|
|
|
"-Wunused-function"
|
2022-04-28 11:06:53 +02:00
|
|
|
"-Wunused-parameter"
|
|
|
|
"-Wvla"
|
|
|
|
"-Wweak-vtables"
|
2022-05-01 23:15:24 +02:00
|
|
|
|
|
|
|
# This is a useful warning, but our tests sometimes rely on
|
|
|
|
# functions being present, but not picked (e.g. various checks
|
|
|
|
# for stringification implementation ordering).
|
|
|
|
# Ergo, we should use it every now and then, but we cannot
|
|
|
|
# enable it by default.
|
|
|
|
# "-Wunused-member-function"
|
2020-02-21 21:15:45 +01:00
|
|
|
)
|
|
|
|
foreach(warning ${CHECKED_WARNING_FLAGS})
|
|
|
|
add_cxx_flag_if_supported_to_targets(${warning} "${targets}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if (CATCH_ENABLE_WERROR)
|
|
|
|
foreach(target ${targets})
|
|
|
|
# Enable Werror equivalent
|
|
|
|
target_compile_options( ${target} PRIVATE -Werror )
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2021-05-09 17:36:30 +02:00
|
|
|
|
|
|
|
# Adds flags required for reproducible build to the target
|
|
|
|
# Currently only supports GCC and Clang
|
|
|
|
function(add_build_reproducibility_settings target)
|
2022-10-04 15:55:50 +02:00
|
|
|
# Make the build reproducible on versions of g++ and clang that supports -ffile-prefix-map
|
|
|
|
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
|
|
|
add_cxx_flag_if_supported_to_targets("-ffile-prefix-map=${CATCH_DIR}/=" "${target}")
|
2021-05-09 17:36:30 +02:00
|
|
|
endif()
|
|
|
|
endfunction()
|