Skip to content
Snippets Groups Projects
Verified Commit 59bc36a5 authored by Martin Stump's avatar Martin Stump
Browse files

Check if compiler supports a flag before adding


Signed-off-by: default avatarMartin Stump <martin.stump@mercedes-benz.com>
parent 771fc799
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ project(
LANGUAGES CXX
)
# Options that control generation of various targets.
# Add project options
option(MantleAPI_DOC "Generate the doc target." ${MantleAPI_MAIN_PROJECT})
option(MantleAPI_INSTALL "Generate the install target." ${MantleAPI_MAIN_PROJECT})
option(MantleAPI_TEST "Generate the test target." ${MantleAPI_MAIN_PROJECT})
......@@ -37,22 +37,38 @@ option(MantleAPI_PACKAGE "Generate the package target." ${MantleAPI_MAIN_PROJECT
option(MantleAPI_ENABLE_WARNINGS "Enable compiler warnings." ${MantleAPI_MAIN_PROJECT})
option(MantleAPI_ENABLE_WERROR "Fail and stop if a warning is triggered." ${MantleAPI_MAIN_PROJECT})
# Add compiler flags
include(CheckCXXCompilerFlag)
function(add_cxx_compiler_flag)
string(TOUPPER ${ARGV0} IDENTIFIER)
string(REGEX REPLACE "^[^A-Z0-9]" "" IDENTIFIER ${IDENTIFIER})
string(MAKE_C_IDENTIFIER ${IDENTIFIER} IDENTIFIER)
check_cxx_compiler_flag(${ARGV0} HAVE_${IDENTIFIER})
if(${HAVE_${IDENTIFIER}})
add_compile_options(${ARGV0})
endif()
endfunction()
if(MSVC)
if(MantleAPI_ENABLE_WARNINGS)
add_compile_options(/W4)
add_cxx_compiler_flag(/W4)
endif()
if(MantleAPI_ENABLE_WERROR)
add_compile_options(/WX /wd4996)
add_cxx_compiler_flag(/WX)
add_cxx_compiler_flag(/wd4996)
endif()
else()
if(MantleAPI_ENABLE_WARNINGS)
add_compile_options(-Wall -Wextra)
add_cxx_compiler_flag(-Wall)
add_cxx_compiler_flag(-Wextra)
endif()
if(MantleAPI_ENABLE_WERROR)
add_compile_options(-Werror -Wno-error=deprecated-declarations)
add_cxx_compiler_flag(-Werror)
add_cxx_compiler_flag(-Wno-error=deprecated-declarations)
endif()
endif()
# Add CPM.cmake
include(CPM)
add_subdirectory(include)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment