Skip to content

Commit 13146b2

Browse files
author
steven varga
committed
Merge remote-tracking branch 'origin/291-fix-wattributes' into staging
2 parents e8226d0 + 32b14c7 commit 13146b2

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,30 @@ if(MSVC)
226226
target_compile_options(h5cpp INTERFACE /Zc:__cplusplus)
227227
endif()
228228

229+
# The h5cpp-compiler reflection annotations ([[h5::doc]], [[h5::chunk]],
230+
# [[h5::compress]], [[h5::name]], [[h5::ignore]], ...) live in the `h5::`
231+
# attribute namespace. A plain compiler — i.e. one not running the h5cpp-compiler
232+
# preprocessing pass — does not know that namespace, ignores the attributes, and
233+
# emits -Wattributes for every annotated struct. Declare the namespace
234+
# intentional so consumers that annotate their own types build cleanly. Scoped
235+
# to `h5::` where the compiler supports it (GCC 11+); Clang/older GCC fall back
236+
# to the broader unknown-attribute switch; MSVC silences C5030. Guarded by
237+
# check_cxx_compiler_flag so unsupported toolchains are left untouched. (#291)
238+
if(MSVC)
239+
target_compile_options(h5cpp INTERFACE /wd5030)
240+
else()
241+
include(CheckCXXCompilerFlag)
242+
check_cxx_compiler_flag("-Wno-attributes=h5::" H5CPP_HAS_WNO_ATTRIBUTES_NS)
243+
if(H5CPP_HAS_WNO_ATTRIBUTES_NS)
244+
target_compile_options(h5cpp INTERFACE -Wno-attributes=h5::)
245+
else()
246+
check_cxx_compiler_flag("-Wno-unknown-attributes" H5CPP_HAS_WNO_UNKNOWN_ATTRIBUTES)
247+
if(H5CPP_HAS_WNO_UNKNOWN_ATTRIBUTES)
248+
target_compile_options(h5cpp INTERFACE -Wno-unknown-attributes)
249+
endif()
250+
endif()
251+
endif()
252+
229253
if(H5CPP_HAVE_ROS3_VFD)
230254
target_compile_definitions(h5cpp INTERFACE H5CPP_HAVE_ROS3_VFD=1)
231255
endif()

0 commit comments

Comments
 (0)