From 37cdc26762e4f5436c3e1403c92d4bc825eeced2 Mon Sep 17 00:00:00 2001 From: Aina Niemetz Date: Mon, 13 Aug 2018 15:22:07 -0700 Subject: [PATCH] cmake: Fixed compiler flag macros. --- CMakeLists.txt | 55 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c54ddfd87..26aa10f89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,36 +49,61 @@ include(CheckCXXCompilerFlag) macro(add_c_flag flag) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}") + message(STATUS "Configuring with C flag '${flag}'") +endmacro() + +macro(add_cxx_flag flag) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") + message(STATUS "Configuring with CXX flag '${flag}'") +endmacro() + +macro(add_c_cxx_flag flag) + add_c_flag(${flag}) + add_cxx_flag(${flag}) endmacro() macro(add_check_c_flag flag) - check_c_compiler_flag("${flag}" HAVE_FLAG_${flag}) - if(HAVE_FLAG_${flag}) + string(REGEX REPLACE "[-=]" "_" flagname ${flag}) + check_c_compiler_flag("${flag}" HAVE_FLAG${flagname}) + if(HAVE_FLAG${flagname}) add_c_flag(${flag}) endif() endmacro() -macro(add_cxx_flag flag) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") -endmacro() - macro(add_check_cxx_flag flag) - check_cxx_compiler_flag("${flag}" HAVE_FLAG_${flag}) - if(HAVE_FLAG_${flag}) + string(REGEX REPLACE "[-=]" "_" flagname ${flag}) + check_cxx_compiler_flag("${flag}" HAVE_FLAG${flagname}) + if(HAVE_FLAG${flagname}) add_cxx_flag(${flag}) endif() endmacro() -macro(add_c_cxx_flag flag) - add_c_flag(${flag}) - add_cxx_flag(${flag}) - message(STATUS "Configure with flag '${flag}'") -endmacro() - macro(add_check_c_cxx_flag flag) add_check_c_flag(${flag}) add_check_cxx_flag(${flag}) - message(STATUS "Configure with flag '${flag}'") +endmacro() + +macro(add_required_cxx_flag flag) + string(REGEX REPLACE "[-=]" "_" flagnamename ${flag}) + check_cxx_compiler_flag("${flag}" HAVE_FLAG${flagname}) + if (NOT HAVE_FLAG${flagname}) + message(FATAL_ERROR "Required compiler flag ${flag} not supported") + endif() + add_cxx_flag(${flag}) +endmacro() + +macro(add_required_c_flag flag) + string(REGEX REPLACE "[-=]" "_" flagname ${flag}) + check_c_compiler_flag("${flag}" HAVE_FLAG${flagname}) + if (NOT HAVE_FLAG${flagname}) + message(FATAL_ERROR "Required compiler flag ${flag} not supported") + endif() + add_c_flag(${flag}) +endmacro() + +macro(add_required_c_cxx_flag flag) + add_required_c_flag(${flag}) + add_required_cxx_flag(${flag}) endmacro() macro(cvc4_link_library library) -- 2.30.2