summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew V. Jones <andrewvaughanj@gmail.com>2021-10-28 19:06:38 +0100
committerGitHub <noreply@github.com>2021-10-28 18:06:38 +0000
commit8043314ad3a38f8764eb7850a50a387d0696d978 (patch)
tree62198c5926811cab344c6f79c83e2e3da79d0399
parent08eb3932ec2e666c40275c8eab1ca49a61158943 (diff)
Add support for checking if a `-Wno` flag exists before using it (#7514)
This PR resolves that issue by checking that a -W<error-class> flag exists before trying to use the -Wno-<error-class> flag.
-rw-r--r--CMakeLists.txt4
-rw-r--r--cmake/Helpers.cmake51
-rw-r--r--src/api/python/CMakeLists.txt16
-rw-r--r--src/parser/CMakeLists.txt11
-rw-r--r--test/unit/CMakeLists.txt6
5 files changed, 73 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2f6fa434e..f5abf6ea6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -184,7 +184,7 @@ include(Config${CMAKE_BUILD_TYPE})
add_check_c_cxx_flag("-O${OPTIMIZATION_LEVEL}")
add_check_c_cxx_flag("-Wall")
-add_check_c_cxx_flag("-Wno-unused-private-field")
+add_check_c_cxx_supression_flag("-Wno-unused-private-field")
add_check_c_flag("-fexceptions")
add_check_cxx_flag("-Wsuggest-override")
add_check_cxx_flag("-Wnon-virtual-dtor")
@@ -198,7 +198,7 @@ add_check_cxx_flag("-fno-extern-tls-init")
# Temporarily disable -Wclass-memaccess to suppress 'no trivial copy-assignment'
# cdlist.h warnings. Remove when fixed.
-add_check_cxx_flag("-Wno-class-memaccess")
+add_check_cxx_supression_flag("-Wno-class-memaccess")
if (WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,100000000")
diff --git a/cmake/Helpers.cmake b/cmake/Helpers.cmake
index 283828e29..465967f21 100644
--- a/cmake/Helpers.cmake
+++ b/cmake/Helpers.cmake
@@ -49,8 +49,8 @@ endmacro()
# Check if C flag is supported and add to global list of C flags.
macro(add_check_c_flag flag)
string(REGEX REPLACE "[-=]" "_" flagname ${flag})
- check_c_compiler_flag("${flag}" HAVE_FLAG${flagname})
- if(HAVE_FLAG${flagname})
+ check_c_compiler_flag("${flag}" HAVE_C_FLAG${flagname})
+ if(HAVE_C_FLAG${flagname})
add_c_flag(${flag})
endif()
endmacro()
@@ -58,8 +58,8 @@ endmacro()
# Check if CXX flag is supported and add to global list of CXX flags.
macro(add_check_cxx_flag flag)
string(REGEX REPLACE "[-=]" "_" flagname ${flag})
- check_cxx_compiler_flag("${flag}" HAVE_FLAG${flagname})
- if(HAVE_FLAG${flagname})
+ check_cxx_compiler_flag("${flag}" HAVE_CXX_FLAG${flagname})
+ if(HAVE_CXX_FLAG${flagname})
add_cxx_flag(${flag})
endif()
endmacro()
@@ -70,12 +70,47 @@ macro(add_check_c_cxx_flag flag)
add_check_cxx_flag(${flag})
endmacro()
+# Check if C warning suppression flag is supported and add to global list of C
+# flags.
+macro(add_check_c_supression_flag supression_flag)
+ # Obtain the non-supression warning flag name
+ string(REGEX REPLACE "^-Wno-" "-W" warning_flag ${supression_flag})
+ string(REGEX REPLACE "[-=]" "_" warning_flagname ${warning_flag})
+ # Check if we have the warning flag
+ check_c_compiler_flag("${warning_flag}" HAVE_C_FLAG${warning_flagname})
+ # Only add the supression flag if we have the warning flag
+ if(HAVE_C_FLAG${warning_flagname})
+ add_c_flag(${supression_flag})
+ endif()
+endmacro()
+
+# Check if CXX warning suppression flag is supported and add to global list of
+# CXX flags.
+macro(add_check_cxx_supression_flag supression_flag)
+ # Obtain the non-supression warning flag name
+ string(REGEX REPLACE "^-Wno-" "-W" warning_flag ${supression_flag})
+ string(REGEX REPLACE "[-=]" "_" warning_flagname ${warning_flag})
+ # Check if we have the warning flag
+ check_cxx_compiler_flag("${warning_flag}" HAVE_CXX_FLAG${warning_flagname})
+ # Only add the supression flag if we have the warning flag
+ if(HAVE_CXX_FLAG${warning_flagname})
+ add_cxx_flag(${supression_flag})
+ endif()
+endmacro()
+
+# Check if C/CXX warning supression flag is supported and add to global list of
+# C/CXX flags.
+macro(add_check_c_cxx_supression_flag supression_flag)
+ add_check_c_supression_flag(${supression_flag})
+ add_check_cxx_supression_flag(${supression_flag})
+endmacro()
+
# Add required CXX flag. Configuration fails if the CXX flag is not supported
# by the compiler.
macro(add_required_cxx_flag flag)
string(REGEX REPLACE "[-=]" "_" flagnamename ${flag})
- check_cxx_compiler_flag("${flag}" HAVE_FLAG${flagname})
- if (NOT HAVE_FLAG${flagname})
+ check_cxx_compiler_flag("${flag}" HAVE_C_FLAG${flagname})
+ if (NOT HAVE_C_FLAG${flagname})
message(FATAL_ERROR "Required compiler flag ${flag} not supported")
endif()
add_cxx_flag(${flag})
@@ -85,8 +120,8 @@ endmacro()
# the compiler.
macro(add_required_c_flag flag)
string(REGEX REPLACE "[-=]" "_" flagname ${flag})
- check_c_compiler_flag("${flag}" HAVE_FLAG${flagname})
- if (NOT HAVE_FLAG${flagname})
+ check_c_compiler_flag("${flag}" HAVE_CXX_FLAG${flagname})
+ if (NOT HAVE_CXX_FLAG${flagname})
message(FATAL_ERROR "Required compiler flag ${flag} not supported")
endif()
add_c_flag(${flag})
diff --git a/src/api/python/CMakeLists.txt b/src/api/python/CMakeLists.txt
index 74d1d84fc..96fcd67a0 100644
--- a/src/api/python/CMakeLists.txt
+++ b/src/api/python/CMakeLists.txt
@@ -95,13 +95,25 @@ target_include_directories(pycvc5
target_link_libraries(pycvc5 cvc5-shared)
# Disable -Werror and other warnings for code generated by Cython.
+set(PY_SRC_FLAGS "")
+check_cxx_compiler_flag("-Werror" HAVE_CXX_FLAGWerror)
+if(HAVE_CXX_FLAGWerror)
+ set(PY_SRC_FLAGS "${PY_SRC_FLAGS} -Wno-error")
+endif()
+check_cxx_compiler_flag("-Wshadow" HAVE_CXX_FLAGWshadow)
+if(HAVE_CXX_FLAGWshadow)
+ set(PY_SRC_FLAGS "${PY_SRC_FLAGS} -Wno-shadow")
+endif()
+check_cxx_compiler_flag("-Wimplicit-fallthrough" HAVE_CXX_FLAGWimplicit_fallthrough)
+if(HAVE_CXX_FLAGWimplicit_fallthrough)
+ set(PY_SRC_FLAGS "${PY_SRC_FLAGS} -Wno-implicit-fallthrough")
+endif()
# Note: Visibility is reset to default here since otherwise the PyInit_...
# function will not be exported correctly
# (https://github.com/cython/cython/issues/3380).
set_target_properties(pycvc5
PROPERTIES
- COMPILE_FLAGS
- "-Wno-error -Wno-shadow -Wno-implicit-fallthrough"
+ COMPILE_FLAGS "${PY_SRC_FLAGS}"
CXX_VISIBILITY_PRESET default
VISIBILITY_INLINES_HIDDEN 0
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pycvc5")
diff --git a/src/parser/CMakeLists.txt b/src/parser/CMakeLists.txt
index e2cf3d64e..92648638c 100644
--- a/src/parser/CMakeLists.txt
+++ b/src/parser/CMakeLists.txt
@@ -88,8 +88,17 @@ foreach(lang Smt2 Tptp)
set_source_files_properties(${gen_src_files} PROPERTIES GENERATED TRUE)
# We don't want to enable -Wall for code generated by ANTLR.
+ set(GEN_SRC_FLAGS "")
+ check_cxx_compiler_flag("-Wall" HAVE_CXX_FLAGWall)
+ if(HAVE_CXX_FLAGWall)
+ set(GEN_SRC_FLAGS "${GEN_SRC_FLAGS} -Wno-all")
+ endif()
+ check_cxx_compiler_flag("-Werror" HAVE_CXX_FLAGWerror)
+ if(HAVE_CXX_FLAGWerror)
+ set(GEN_SRC_FLAGS "${GEN_SRC_FLAGS} -Wno-error")
+ endif()
set_source_files_properties(
- ${gen_src_files} PROPERTIES COMPILE_FLAGS "-Wno-all -Wno-error")
+ ${gen_src_files} PROPERTIES COMPILE_FLAGS "${GEN_SRC_FLAGS}")
# Add generated source files to the parser source files
list(APPEND libcvc5parser_src_files ${gen_src_files})
diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 2e15cff4b..bbfc2a74b 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -53,9 +53,11 @@ macro(cvc5_add_unit_test is_white name output_dir)
if(${is_white})
target_compile_options(${name} PRIVATE -fno-access-control)
endif()
+
# Disable the Wunused-comparison warnings for the unit tests.
- check_cxx_compiler_flag("-Wno-unused-comparison" HAVE_FLAGWno_unused_comparison)
- if(HAVE_FLAGWno_unused_comparison)
+ # We check for `-Wunused-comparison` and then add `-Wno-unused-comparison`
+ check_cxx_compiler_flag("-Wunused-comparison" HAVE_CXX_FLAGWunused_comparison)
+ if(HAVE_CXX_FLAGWunused_comparison)
target_compile_options(${name} PRIVATE -Wno-unused-comparison)
endif()
add_dependencies(build-units ${name})
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback