2020-05-02 17:56:21 +03:00
|
|
|
# Sets cache variable QBT_ADDITIONAL_FLAGS and QBT_ADDITONAL_CXX_FLAGS to list of additional
|
|
|
|
# compiler flags for C and C++ (QBT_ADDITIONAL_FLAGS) and for C++ only (QBT_ADDITONAL_CXX_FLAGS)
|
2017-04-27 15:35:28 +03:00
|
|
|
# and appends them to CMAKE_XXX_FLAGS variables.
|
|
|
|
|
|
|
|
# It could use add_compile_options(), but then it is needed to use generator expressions,
|
|
|
|
# and most interesting of them are not compatible with Visual Studio :(
|
|
|
|
|
|
|
|
macro(qbt_set_compiler_options)
|
2020-05-02 17:56:21 +03:00
|
|
|
# if (NOT QBT_ADDITIONAL_FLAGS)
|
2017-04-27 15:35:28 +03:00
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
#-Wshadow -Wconversion ?
|
|
|
|
set(_GCC_COMMON_C_AND_CXX_FLAGS "-Wall -Wextra"
|
2019-07-18 09:34:39 +03:00
|
|
|
"-Wcast-qual -Wcast-align"
|
|
|
|
"-Winvalid-pch -Wno-long-long"
|
2018-05-05 15:57:05 +03:00
|
|
|
#"-fstack-protector-all"
|
|
|
|
#"-Werror -Wno-error=deprecated-declarations"
|
2017-04-27 15:35:28 +03:00
|
|
|
)
|
2018-05-05 15:57:05 +03:00
|
|
|
set(_GCC_COMMON_CXX_FLAGS "-fexceptions -frtti"
|
2018-02-26 21:18:18 +03:00
|
|
|
"-Woverloaded-virtual -Wold-style-cast"
|
2019-07-18 09:34:39 +03:00
|
|
|
"-Wnon-virtual-dtor"
|
2018-05-05 15:57:05 +03:00
|
|
|
#"-Weffc++"
|
|
|
|
#"-Werror -Wno-error=cpp"
|
2017-04-27 15:35:28 +03:00
|
|
|
# we should modify code to make these ones obsolete
|
2018-05-05 15:57:05 +03:00
|
|
|
#"-Wno-error=sign-conversion -Wno-error=float-equal"
|
2017-04-27 15:35:28 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
# check for -pedantic
|
|
|
|
check_cxx_compiler_flag(-pedantic _PEDANTIC_IS_SUPPORTED)
|
|
|
|
if (_PEDANTIC_IS_SUPPORTED)
|
|
|
|
list(APPEND _GCC_COMMON_CXX_FLAGS "-pedantic -pedantic-errors")
|
|
|
|
else (_PEDANTIC_IS_SUPPORTED)
|
|
|
|
list(APPEND _GCC_COMMON_CXX_FLAGS "-Wpedantic")
|
|
|
|
endif (_PEDANTIC_IS_SUPPORTED)
|
|
|
|
|
|
|
|
if (CMAKE_SYSTEM_NAME MATCHES Linux)
|
2020-01-18 17:37:56 +03:00
|
|
|
add_definitions(-D_DEFAULT_SOURCE)
|
|
|
|
endif()
|
2017-04-27 15:35:28 +03:00
|
|
|
|
2020-01-18 17:37:56 +03:00
|
|
|
# Clang 5.0 still doesn't support -Wstrict-null-sentinel
|
2018-02-26 21:18:18 +03:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
check_cxx_compiler_flag(-Wstrict-null-sentinel _STRICT_NULL_SENTINEL_IS_SUPPORTED)
|
|
|
|
if (_STRICT_NULL_SENTINEL_IS_SUPPORTED)
|
|
|
|
list(APPEND _GCC_COMMON_CXX_FLAGS "-Wstrict-null-sentinel")
|
|
|
|
endif (_STRICT_NULL_SENTINEL_IS_SUPPORTED)
|
|
|
|
|
|
|
|
# Code should be improved to render this not needed
|
2019-07-18 10:10:14 +03:00
|
|
|
list(APPEND _GCC_COMMON_CXX_FLAGS "-Wno-error=unused-function")
|
2018-02-26 21:18:18 +03:00
|
|
|
else ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
# GCC supports it
|
|
|
|
list(APPEND _GCC_COMMON_CXX_FLAGS "-Wstrict-null-sentinel")
|
|
|
|
endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
|
2017-04-27 15:35:28 +03:00
|
|
|
string(REPLACE ";" " " _GCC_COMMON_C_AND_CXX_FLAGS_STRING "${_GCC_COMMON_C_AND_CXX_FLAGS}")
|
|
|
|
string(REPLACE ";" " " _GCC_COMMON_CXX_FLAGS_STRING "${_GCC_COMMON_CXX_FLAGS}")
|
|
|
|
|
|
|
|
string(APPEND CMAKE_C_FLAGS " ${_GCC_COMMON_C_AND_CXX_FLAGS_STRING}")
|
|
|
|
string(APPEND CMAKE_CXX_FLAGS " ${_GCC_COMMON_C_AND_CXX_FLAGS_STRING} ${_GCC_COMMON_CXX_FLAGS_STRING}")
|
|
|
|
endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
|
|
|
|
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
2020-05-02 17:56:21 +03:00
|
|
|
set(QBT_ADDITIONAL_FLAGS "/wd4251 /wd4275 /wd4290 /W4" CACHE STRING "Additional qBittorent compile flags")
|
2017-04-27 15:35:28 +03:00
|
|
|
endif ()
|
|
|
|
|
2020-05-02 17:56:21 +03:00
|
|
|
string(APPEND CMAKE_C_FLAGS " ${QBT_ADDITIONAL_FLAGS}")
|
|
|
|
string(APPEND CMAKE_CXX_FLAGS " ${QBT_ADDITIONAL_FLAGS}")
|
2019-08-02 15:19:13 +03:00
|
|
|
|
2020-05-02 17:56:21 +03:00
|
|
|
# endif (NOT QBT_ADDITIONAL_FLAGS)
|
2017-04-27 15:35:28 +03:00
|
|
|
endmacro(qbt_set_compiler_options)
|