2019-02-12 16:31:17 +00:00
|
|
|
# based on https://github.com/bluescarni/yacma
|
|
|
|
|
2020-04-18 16:50:12 +00:00
|
|
|
option(CMLIB_WARNING_FLAGS "Enable warning flags" ON)
|
|
|
|
|
2019-10-09 14:10:17 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
2019-02-12 16:31:17 +00:00
|
|
|
macro(CHECK_ENABLE_CXX_FLAG flag)
|
|
|
|
set(CMAKE_REQUIRED_QUIET TRUE)
|
|
|
|
check_cxx_compiler_flag("${flag}" CHECK_CXX_FLAG)
|
|
|
|
unset(CMAKE_REQUIRED_QUIET)
|
|
|
|
|
|
|
|
if(CHECK_CXX_FLAG)
|
|
|
|
message(STATUS "'${flag}': flag is enabled.")
|
|
|
|
add_compile_options("${flag}")
|
|
|
|
else()
|
|
|
|
message(STATUS "'${flag}': flag is NOT supported.")
|
|
|
|
endif()
|
|
|
|
# NOTE: check_cxx_compiler stores variables in the cache.
|
|
|
|
unset(CHECK_CXX_FLAG CACHE)
|
|
|
|
endmacro()
|
|
|
|
|
2021-05-30 17:31:10 +00:00
|
|
|
function(cmlib_set_cxx_standard version)
|
|
|
|
# Выбор стандарта по умолчанию (можно переопределить в проекте)
|
2021-05-30 17:53:38 +00:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED YES PARENT_SCOPE)
|
2021-05-30 17:31:10 +00:00
|
|
|
|
2021-05-30 17:53:38 +00:00
|
|
|
if(version EQUAL 11)
|
|
|
|
set(CMAKE_CXX_STANDARD 11 PARENT_SCOPE)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS YES PARENT_SCOPE)
|
2021-05-30 17:31:10 +00:00
|
|
|
endif()
|
|
|
|
|
2021-05-30 17:53:38 +00:00
|
|
|
if(version EQUAL 14)
|
|
|
|
set(CMAKE_CXX_STANDARD 14 PARENT_SCOPE)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS YES PARENT_SCOPE)
|
2021-05-30 17:31:10 +00:00
|
|
|
endif()
|
|
|
|
|
2021-05-30 17:53:38 +00:00
|
|
|
if(version EQUAL 17)
|
2021-05-30 17:31:10 +00:00
|
|
|
if(${CMAKE_VERSION} VERSION_LESS "3.10.0")
|
|
|
|
check_cxx_compiler_flag(-std=gnu++17 HAVE_FLAG_STD_GNUXX17)
|
|
|
|
if(HAVE_FLAG_STD_GNUXX17)
|
|
|
|
add_compile_options("-std=gnu++17")
|
|
|
|
else()
|
|
|
|
check_cxx_compiler_flag(-std=gnu++1z HAVE_FLAG_STD_GNUXX1Z)
|
|
|
|
if(HAVE_FLAG_STD_GNUXX1Z)
|
|
|
|
add_compile_options("-std=gnu++1z")
|
|
|
|
else()
|
|
|
|
check_cxx_compiler_flag(-std=c++17 HAVE_FLAG_STD_CXX17)
|
|
|
|
if(HAVE_FLAG_STD_CXX17)
|
|
|
|
add_compile_options("-std=c++17")
|
|
|
|
else()
|
|
|
|
check_cxx_compiler_flag(-std=c++1z HAVE_FLAG_STD_CXX1Z)
|
|
|
|
if(HAVE_FLAG_STD_CXX1Z)
|
|
|
|
add_compile_options("-std=c++1z")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
else()
|
2021-05-30 17:53:38 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 17 PARENT_SCOPE)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS YES PARENT_SCOPE)
|
2021-05-30 17:31:10 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# cmake-format: off
|
|
|
|
if(LSB_DISTRIBUTOR_ID STREQUAL "AstraLinuxSE" AND
|
|
|
|
LSB_CODENAME STREQUAL "smolensk" AND
|
|
|
|
LSB_RELEASE STREQUAL "1.5")
|
|
|
|
# cmake-format: on
|
|
|
|
cmlib_set_cxx_standard(11)
|
|
|
|
|
2019-10-09 14:17:24 +00:00
|
|
|
set(_CMAKE_TOOLCHAIN_PREFIX "x86_64-linux-gnu-")
|
|
|
|
set(_CMAKE_TOOLCHAIN_SUFFIX "-4.7")
|
|
|
|
set(_CMAKE_TOOLCHAIN_LOCATION} "/usr/bin")
|
|
|
|
else()
|
2021-05-30 17:31:10 +00:00
|
|
|
cmlib_set_cxx_standard(17)
|
|
|
|
|
2019-10-09 14:17:24 +00:00
|
|
|
# -Wshadow gives a lot of false positives with GCC 4.7.2 in Astra Linux 1.5
|
|
|
|
if(CMAKE_CXX_COMPILER_IS_GCC)
|
|
|
|
check_enable_cxx_flag(-Wshadow)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-06-25 06:20:23 +00:00
|
|
|
# Common configuration for GCC, clang and Intel.
|
|
|
|
if(CMAKE_CXX_COMPILER_IS_CLANG OR CMAKE_CXX_COMPILER_IS_INTEL OR CMAKE_CXX_COMPILER_IS_GCC)
|
2020-04-18 16:50:12 +00:00
|
|
|
if(CMLIB_WARNING_FLAGS AND CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2019-02-16 10:10:12 +00:00
|
|
|
check_enable_cxx_flag(-Wall)
|
|
|
|
check_enable_cxx_flag(-Wextra)
|
|
|
|
check_enable_cxx_flag(-Wnon-virtual-dtor)
|
|
|
|
check_enable_cxx_flag(-Wnoexcept)
|
|
|
|
check_enable_cxx_flag(-Wlogical-op)
|
|
|
|
check_enable_cxx_flag(-Wconversion)
|
|
|
|
check_enable_cxx_flag(-Wdeprecated)
|
2019-02-12 16:31:17 +00:00
|
|
|
# This limit is supposed to be at least 1024 in C++11, but for some reason
|
|
|
|
# clang sets this to 256, and gcc to 900.
|
2019-02-16 10:10:12 +00:00
|
|
|
check_enable_cxx_flag(-ftemplate-depth=1024)
|
|
|
|
check_enable_cxx_flag(-Wold-style-cast)
|
|
|
|
check_enable_cxx_flag(-Wdisabled-optimization)
|
|
|
|
# This is useful when the compiler decides the template backtrace is too
|
|
|
|
# verbose.
|
|
|
|
check_enable_cxx_flag(-ftemplate-backtrace-limit=0)
|
|
|
|
check_enable_cxx_flag(-fstack-protector-all)
|
2019-02-12 16:31:17 +00:00
|
|
|
# A few suggestion flags.
|
2019-02-16 10:10:12 +00:00
|
|
|
check_enable_cxx_flag(-Wsuggest-attribute=pure)
|
|
|
|
check_enable_cxx_flag(-Wsuggest-attribute=const)
|
|
|
|
check_enable_cxx_flag(-Wsuggest-attribute=noreturn)
|
|
|
|
check_enable_cxx_flag(-Wsuggest-attribute=format)
|
2019-02-12 16:31:17 +00:00
|
|
|
# From GCC 5.
|
2019-02-16 10:10:12 +00:00
|
|
|
check_enable_cxx_flag(-Wodr)
|
|
|
|
check_enable_cxx_flag(-Wsuggest-final-types)
|
|
|
|
check_enable_cxx_flag(-Wsuggest-final-methods)
|
|
|
|
check_enable_cxx_flag(-Wsuggest-override)
|
2019-02-12 16:31:17 +00:00
|
|
|
# From GCC 6.
|
2019-02-16 10:10:12 +00:00
|
|
|
check_enable_cxx_flag(-Wshift-negative-value)
|
|
|
|
check_enable_cxx_flag(-Wshift-overflow=2)
|
|
|
|
check_enable_cxx_flag(-Wduplicated-cond)
|
|
|
|
check_enable_cxx_flag(-Wnull-dereference)
|
2019-02-12 16:31:17 +00:00
|
|
|
# From GCC 7.
|
2019-02-16 10:10:12 +00:00
|
|
|
check_enable_cxx_flag(-Wrestrict)
|
|
|
|
check_enable_cxx_flag(-Waligned-new)
|
2019-02-12 16:31:17 +00:00
|
|
|
# From GCC 8.
|
2019-02-16 10:10:12 +00:00
|
|
|
check_enable_cxx_flag(-Wcast-align=strict)
|
|
|
|
# This is supposed to produce a nice graphical visualization of mismatching
|
|
|
|
# template errors.
|
|
|
|
check_enable_cxx_flag(-fdiagnostics-show-template-tree)
|
|
|
|
check_enable_cxx_flag(-fdiagnostics-show-option)
|
2019-02-12 16:31:17 +00:00
|
|
|
|
2019-02-16 10:10:12 +00:00
|
|
|
check_enable_cxx_flag(-pedantic)
|
|
|
|
check_enable_cxx_flag(-Wcast-align)
|
|
|
|
check_enable_cxx_flag(-Wcast-qual)
|
|
|
|
check_enable_cxx_flag(-Wctor-dtor-privacy)
|
|
|
|
check_enable_cxx_flag(-Wdisabled-optimization)
|
|
|
|
check_enable_cxx_flag(-Wformat=2)
|
|
|
|
check_enable_cxx_flag(-Winit-self)
|
|
|
|
check_enable_cxx_flag(-Wmissing-include-dirs)
|
|
|
|
check_enable_cxx_flag(-Woverloaded-virtual)
|
|
|
|
check_enable_cxx_flag(-Wredundant-decls)
|
|
|
|
check_enable_cxx_flag(-Wsign-promo)
|
|
|
|
check_enable_cxx_flag(-Wstrict-overflow=5)
|
|
|
|
check_enable_cxx_flag(-Wundef)
|
|
|
|
check_enable_cxx_flag(-Wno-unused)
|
|
|
|
check_enable_cxx_flag(-Wno-variadic-macros)
|
|
|
|
check_enable_cxx_flag(-Wno-parentheses)
|
|
|
|
check_enable_cxx_flag(-Wstrict-null-sentinel)
|
|
|
|
check_enable_cxx_flag(-Wshadow-all)
|
2019-02-12 16:31:17 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-02-16 10:10:12 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_IS_GCC)
|
|
|
|
check_enable_cxx_flag(-fdiagnostics-color=auto)
|
|
|
|
# The -Wmaybe-uninitialized flag is enabled by -Wall,
|
|
|
|
# but it is known to emit a lot of possibly spurious warnings.
|
|
|
|
# Let's just disable it.
|
|
|
|
check_enable_cxx_flag(-Wno-maybe-uninitialized)
|
2019-02-12 16:31:17 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.999")
|
|
|
|
# NOTE: GCC >= 6 seems to be wrongly warning about visibility attributes
|
|
|
|
# in some situations:
|
|
|
|
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80947
|
|
|
|
# Let's just disable the warning for now.
|
2019-02-16 10:10:12 +00:00
|
|
|
check_enable_cxx_flag(-Wno-attributes)
|
2019-02-12 16:31:17 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "e2k")
|
2019-08-01 10:17:05 +00:00
|
|
|
check_enable_cxx_flag(-Wno-invalid-offsetof)
|
2019-02-12 16:31:17 +00:00
|
|
|
list(APPEND CMAKE_LIBRARY_PATH "/usr/lib/e2k-linux-gnu")
|
|
|
|
endif()
|