Skip to content

Commit 47e5097

Browse files
committed
cmake: Check if compiler flags are supported before adding them
1 parent 57d570a commit 47e5097

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

cdk/cmake/platform.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ macro(add_flags LANG)
115115
set(CMAKE_${LANG}_FLAGS "${CMAKE_${LANG}_FLAGS}" PARENT_SCOPE)
116116
endmacro()
117117

118+
include(CheckCXXCompilerFlag)
119+
120+
# Set single compiler flag only if it is supported, ignore otherwise
121+
122+
macro(set_compiler_flag FLAG)
123+
unset(flag_supported CACHE)
124+
CHECK_CXX_COMPILER_FLAG(${FLAG} flag_supported)
125+
if(flag_supported)
126+
add_compile_options(${FLAG})
127+
endif()
128+
endmacro()
118129

119130
# -----------------------------------------------------------------
120131

cdk/extra/protobuf/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,20 @@ set_visibility(hidden)
9696

9797
if(GCC AND GCC VERSION_GREATER 11)
9898
# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106199
99-
add_compile_options(-Wno-stringop-overflow)
100-
add_compile_options(-Wno-stringop-overread)
99+
set_compiler_flag(-Wno-stringop-overflow)
100+
set_compiler_flag(-Wno-stringop-overread)
101101
endif()
102102

103103
if(NOT MSVC OR CLANG)
104-
add_compile_options(-Wno-unused-const-variable)
104+
set_compiler_flag(-Wno-unused-const-variable)
105105
endif()
106106

107107
if(WIN32)
108108
add_compile_definitions(_CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS)
109109
endif()
110110

111111
if(APPLE)
112-
add_compile_options(-Wno-deprecated-declarations)
112+
set_compiler_flag(-Wno-deprecated-declarations)
113113
endif()
114114

115115

cdk/extra/zlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if(WIN32)
2525
# conformant name: _open. See online help for details.
2626

2727
if(CLANG)
28-
add_compile_options(-Wno-deprecated-declarations)
28+
set_compiler_flag(-Wno-deprecated-declarations)
2929
else()
3030
add_compile_options(/wd4996)
3131
endif()

cdk/extra/zstd/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ endif()
2222
if(WIN32 AND CLANG)
2323
# This warning shows only when building with clang on Win (clang 18):
2424
# lib\compress\huf_compress.c(519,16): error : unused function 'HUF_isSorted'
25-
add_compile_options(-Wno-unused-function)
25+
set_compiler_flag(-Wno-unused-function)
2626
endif()
2727

2828

jdbc/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,8 @@ if(NOT SHOW_JDBC_WARNINGS)
215215

216216
else()
217217

218-
add_compile_options(
219-
-Wno-unused-parameter
220-
-Wno-deprecated-declarations
221-
)
218+
set_compiler_flag(-Wno-unused-parameter)
219+
set_compiler_flag(-Wno-deprecated-declarations)
222220

223221
endif()
224222

0 commit comments

Comments
 (0)