CMake `SYSTEM` 标志不抑制来自 Boost 仅标头库的警告

问题描述 投票:0回答:2

我正在尝试使用 CMake 编译一个项目。该项目有一些仅包含头文件的库,我像这样包含它们:

target_include_directories(cartogram
  PRIVATE
    ${PROJECT_SOURCE_DIR}/include
  SYSTEM
    ${Boost_INCLUDE_DIRS}
    PkgConfig::fftw
    PkgConfig::cairo
    $<$<BOOL:${APPLE}>:/opt/homebrew/include>
)

但是,尽管使用了

SYSTEM
标志,我仍然收到来自
boost
的警告,如下所示:

In file included from /Users/adi/Desktop/github/cartogram-cpp/src/inset_state/write_inset_to_geojson.cpp:1:
In file included from /Users/adi/Desktop/github/cartogram-cpp/include/inset_state.hpp:6:
In file included from /Users/adi/Desktop/github/cartogram-cpp/include/geo_div.hpp:4:
In file included from /Users/adi/Desktop/github/cartogram-cpp/include/ellipse.hpp:4:
In file included from /Users/adi/Desktop/github/cartogram-cpp/include/cgal_typedef.hpp:11:
In file included from /opt/homebrew/include/CGAL/Polyline_simplification_2/simplify.h:29:
In file included from /opt/homebrew/include/CGAL/Modifiable_priority_queue.h:20:
In file included from /opt/homebrew/include/boost/heap/pairing_heap.hpp:21:
/opt/homebrew/include/boost/heap/detail/stable_heap.hpp:100:32: warning: unused parameter 'rhs' [-Wunused-parameter]
  100 |     size_holder(size_holder && rhs) BOOST_NOEXCEPT

理想情况下,我想从外部库中删除所有错误,但仅使用

SYSTEM
标志似乎无法做到这一点。

当我额外包含 boost 库时(再次,总共两次)

target_include_directories
,如下所示:

  target_compile_options(cartogram PRIVATE -isystem ${Boost_INCLUDE_DIRS})

警告消失。

这是我运行后得到的结果

cmake -B build

❯ cmake -B build && sudo make install -j -C build
-- The CXX compiler identification is AppleClang 16.0.0.16000026
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /opt/homebrew/lib/cmake/Boost-1.86.0/BoostConfig.cmake (found version "1.86.0") found components: unit_test_framework
-- Found PkgConfig: /opt/homebrew/bin/pkg-config (found version "0.29.2")
-- Checking for one of the modules 'fftw3'
-- Checking for one of the modules 'cairo'
-- Configuring done (0.5s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/adi/Desktop/github/cartogram-cpp/build
c++ cmake boost
2个回答
1
投票

PRIVATE
/
PUBLIC
/
INTERFACE
关键字不同,这些关键字可以在
target_include_directories
命令中随时发出并且仅影响命令的以下参数,
SYSTEM
关键字应作为 第一个参数,它会影响命令中指定的所有目录

非系统包含目录和系统包含目录的规范应使用单独的

target_include_directories
调用:

# Non-system includes
target_include_directories(cartogram
  PRIVATE
    ${PROJECT_SOURCE_DIR}/include
)
# System includes
target_include_directories(cartogram
  SYSTEM
  PRIVATE
    ${Boost_INCLUDE_DIRS}
    $<$<BOOL:${APPLE}>:/opt/homebrew/include>
)

SYSTEM
关键字作为
target_include_directories
命令的非第一个参数发出时,它会被默认视为目录名称。


0
投票

SYSTEM
关键字应该是第一个,请参阅语法。恕我直言,在您的情况下,最详细的方法是:

target_include_directories(cartogram PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_include_directories(cartogram SYSTEM PRIVATE
    ${Boost_INCLUDE_DIRS}
    PkgConfig::fftw
    PkgConfig::cairo
    $<$<BOOL:${APPLE}>:/opt/homebrew/include>
)
© www.soinside.com 2019 - 2024. All rights reserved.