Skip to content

Commit b8eb28d

Browse files
authored
cleanup: Simplify some clauses involving old compilers (#2016)
Our minimum gcc 9 and clang 5 lets us simplify a few preprocessor conditionals. Also give more clear cmake messages when too-old compilers are encountered, for gcc, clang, and Apple clang. Define OSL_GCC_ONLY_PRAGMA, which is handy in the future. Signed-off-by: Larry Gritz <[email protected]>
1 parent 5d8dc32 commit b8eb28d

File tree

6 files changed

+31
-40
lines changed

6 files changed

+31
-40
lines changed

src/cmake/compiler.cmake

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ if (CMAKE_COMPILER_IS_GNUCC)
4949
OUTPUT_VARIABLE GCC_VERSION
5050
OUTPUT_STRIP_TRAILING_WHITESPACE)
5151
message (VERBOSE "Using gcc ${GCC_VERSION} as the compiler")
52+
if (GCC_VERSION VERSION_LESS 9.0)
53+
message (ERROR "gcc minimum version is 9.0")
54+
endif ()
5255
else ()
5356
set (GCC_VERSION 0)
5457
endif ()
@@ -67,6 +70,9 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER MATCHES "[Cc]lan
6770
string (REGEX REPLACE ".* version ([0-9]+\\.[0-9]+).*" "\\1" APPLECLANG_VERSION_STRING ${clang_full_version_string})
6871
set (ANY_CLANG_VERSION_STRING ${APPLECLANG_VERSION_STRING})
6972
message (VERBOSE "The compiler is Clang: ${CMAKE_CXX_COMPILER_ID} version ${APPLECLANG_VERSION_STRING}")
73+
if (APPLECLANG_VERSION_STRING VERSION_LESS 5.0)
74+
message (ERROR "Apple clang minimum version is 5.0")
75+
endif ()
7076
elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
7177
set (CMAKE_COMPILER_IS_INTELCLANG 1)
7278
string (REGEX MATCH "[0-9]+(\\.[0-9]+)+" INTELCLANG_VERSION_STRING ${clang_full_version_string})
@@ -77,6 +83,9 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER MATCHES "[Cc]lan
7783
string (REGEX REPLACE ".* version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})
7884
set (ANY_CLANG_VERSION_STRING ${CLANG_VERSION_STRING})
7985
message (VERBOSE "The compiler is Clang: ${CMAKE_CXX_COMPILER_ID} version ${CLANG_VERSION_STRING}")
86+
if (CLANG_VERSION_STRING VERSION_LESS 5.0)
87+
message (ERROR "clang minimum version is 5.0")
88+
endif ()
8089
endif ()
8190
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
8291
set (CMAKE_COMPILER_IS_INTEL 1)
@@ -180,9 +189,7 @@ if (CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_I
180189
add_compile_options ("-Wno-error=strict-overflow")
181190
add_compile_options ("-Wno-unused-local-typedefs")
182191
add_compile_options ("-Wno-unused-result")
183-
if (NOT ${GCC_VERSION} VERSION_LESS 6.0)
184-
add_compile_options ("-Wno-error=misleading-indentation")
185-
endif ()
192+
add_compile_options ("-Wno-error=misleading-indentation")
186193
endif ()
187194

188195
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
@@ -276,10 +283,8 @@ endif ()
276283
# legit problem later.
277284
#
278285
set (GLIBCXX_USE_CXX11_ABI "" CACHE STRING "For gcc, use the new C++11 library ABI (0|1)")
279-
if (CMAKE_COMPILER_IS_GNUCC AND ${GCC_VERSION} VERSION_GREATER_EQUAL 5.0)
280-
if (NOT ${GLIBCXX_USE_CXX11_ABI} STREQUAL "")
281-
add_compile_definitions (_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI})
282-
endif ()
286+
if (CMAKE_COMPILER_IS_GNUCC AND NOT ${GLIBCXX_USE_CXX11_ABI} STREQUAL "")
287+
add_compile_definitions (_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI})
283288
endif ()
284289

285290

src/include/OSL/platform.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@
208208
# define OSL_GCC_PRAGMA(UnQuotedPragma) OSL_PRAGMA(UnQuotedPragma)
209209
# if defined(__clang__)
210210
# define OSL_CLANG_PRAGMA(UnQuotedPragma) OSL_PRAGMA(UnQuotedPragma)
211+
# define OSL_GCC_ONLY_PRAGMA(UnQuotedPragma)
211212
# else
212213
# define OSL_CLANG_PRAGMA(UnQuotedPragma)
214+
# define OSL_GCC_ONLY_PRAGMA(UnQuotedPragma) OSL_PRAGMA(UnQuotedPragma)
213215
# endif
214216
# if defined(__INTEL_COMPILER)
215217
# define OSL_INTEL_CLASSIC_PRAGMA(UnQuotedPragma) OSL_PRAGMA(UnQuotedPragma)
@@ -228,6 +230,7 @@
228230
# define OSL_PRAGMA_VISIBILITY_PUSH /* N/A on MSVS */
229231
# define OSL_PRAGMA_VISIBILITY_POP /* N/A on MSVS */
230232
# define OSL_GCC_PRAGMA(UnQuotedPragma)
233+
# define OSL_GCC_ONLY_PRAGMA(UnQuotedPragma)
231234
# define OSL_CLANG_PRAGMA(UnQuotedPragma)
232235
# define OSL_INTEL_CLASSIC_PRAGMA(UnQuotedPragma)
233236
# define OSL_INTEL_LLVM_PRAGMA(UnQuotedPragma)
@@ -238,6 +241,7 @@
238241
# define OSL_PRAGMA_VISIBILITY_PUSH
239242
# define OSL_PRAGMA_VISIBILITY_POP
240243
# define OSL_GCC_PRAGMA(UnQuotedPragma)
244+
# define OSL_GCC_ONLY_PRAGMA(UnQuotedPragma)
241245
# define OSL_CLANG_PRAGMA(UnQuotedPragma)
242246
# define OSL_INTEL_CLASSIC_PRAGMA(UnQuotedPragma)
243247
# define OSL_INTEL_LLVM_PRAGMA(UnQuotedPragma)

src/liboslcomp/osllex.l

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,12 @@ using namespace OSL::pvt;
103103

104104
// flex itself will generate fatal warnings about signed vs unsigned.
105105
// Bypass that nonsense.
106-
#if OSL_GNUC_VERSION >= 60000
107-
#pragma GCC diagnostic ignored "-Wsign-compare"
108-
#endif
106+
OSL_GCC_ONLY_PRAGMA(GCC diagnostic ignored "-Wsign-compare")
109107

110108
// flex uses the 'register' keyword, warned because it's deprecated in C++17.
111-
#if defined(__clang__)
112-
#pragma GCC diagnostic ignored "-Wdeprecated-register"
113-
#pragma GCC diagnostic ignored "-Wregister"
114-
#endif
115-
#if OSL_GNUC_VERSION >= 90000
116-
#pragma GCC diagnostic ignored "-Wregister"
117-
#endif
109+
OSL_CLANG_PRAGMA(GCC diagnostic ignored "-Wdeprecated-register")
110+
OSL_CLANG_PRAGMA(GCC diagnostic ignored "-Wregister")
111+
OSL_GCC_ONLY_PRAGMA(GCC diagnostic ignored "-Wregister")
118112

119113
#if defined(__GNUC__) || defined(__clang__)
120114
#pragma GCC visibility push(hidden)

src/liboslexec/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,10 @@ foreach(batched_target ${BATCHED_TARGET_LIST})
440440

441441
if (${TARGET_OPT_ISA} STREQUAL "AVX512")
442442
list (APPEND TARGET_CXX_OPTS "-march=skylake-avx512")
443-
if (NOT ${GCC_VERSION} VERSION_LESS 8.1)
444-
if (${TARGET_BATCH_SIZE} STREQUAL "16")
445-
list (APPEND TARGET_CXX_OPTS "-mprefer-vector-width=512")
446-
else ()
447-
list (APPEND TARGET_CXX_OPTS "-mprefer-vector-width=256")
448-
endif ()
443+
if (${TARGET_BATCH_SIZE} STREQUAL "16")
444+
list (APPEND TARGET_CXX_OPTS "-mprefer-vector-width=512")
445+
else ()
446+
list (APPEND TARGET_CXX_OPTS "-mprefer-vector-width=256")
449447
endif ()
450448
elseif (${TARGET_OPT_ISA} STREQUAL "AVX2")
451449
list (APPEND TARGET_CXX_OPTS "-march=haswell")

src/liboslexec/constfold.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,10 +2866,8 @@ DECLFOLDER(constfold_noise)
28662866
return 0; // optional args starting, we don't fold them yet
28672867
}
28682868

2869-
#if OSL_GNUC_VERSION >= 90000
2870-
# pragma GCC diagnostic push
2871-
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
2872-
#endif
2869+
OSL_PRAGMA_WARNING_PUSH
2870+
OSL_GCC_ONLY_PRAGMA(GCC diagnostic ignored "-Wmaybe-uninitialized")
28732871
if (name == u_cellnoise || name == u_cell) {
28742872
CellNoise cell;
28752873
if (outdim == 1) {
@@ -2901,9 +2899,7 @@ DECLFOLDER(constfold_noise)
29012899
return 1;
29022900
}
29032901
}
2904-
#if OSL_GNUC_VERSION >= 90000
2905-
# pragma GCC diagnostic pop
2906-
#endif
2902+
OSL_PRAGMA_WARNING_POP
29072903

29082904
return 0;
29092905
}

src/liboslexec/osolex.l

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,12 @@ OSL_NAMESPACE_END
111111
112112
// flex itself will generate fatal warnings about signed vs unsigned.
113113
// Bypass that nonsense.
114-
#if OSL_GNUC_VERSION >= 60000
115-
#pragma GCC diagnostic ignored "-Wsign-compare"
116-
#endif
114+
OSL_GCC_ONLY_PRAGMA(GCC diagnostic ignored "-Wsign-compare")
117115
118116
// flex uses the 'register' keyword, warned because it's deprecated in C++17.
119-
#if defined(__clang__)
120-
#pragma GCC diagnostic ignored "-Wdeprecated-register"
121-
#pragma GCC diagnostic ignored "-Wregister"
122-
#endif
123-
#if OSL_GNUC_VERSION >= 90000
124-
#pragma GCC diagnostic ignored "-Wregister"
125-
#endif
117+
OSL_CLANG_PRAGMA(GCC diagnostic ignored "-Wdeprecated-register")
118+
OSL_CLANG_PRAGMA(GCC diagnostic ignored "-Wregister")
119+
OSL_GCC_ONLY_PRAGMA(GCC diagnostic ignored "-Wregister")
126120
127121
#if defined(__GNUC__) || defined(__clang__)
128122
#pragma GCC visibility push(hidden)

0 commit comments

Comments
 (0)