尝试使cmake add_compile_options工作

发布于 2025-02-06 17:50:52 字数 1044 浏览 0 评论 0原文

我正在尝试一个非常简单的示例与cmake使用add_compile_options指示

cmakelists.txt:

add_compile_options(-Wall)
MESSAGE("COMPILE OPTIONS ${COMPILE_OPTIONS}")
add_executable(test main.cpp)

其中main.cpp是某个(空)主函数。我进行

rm -r CMakeFiles/ cmake_install.cmake Makefile test CMakeCache.txt
cmake CMakeLists.txt
make VERBOSE=1

cmake输出,例如:

<snip>
-- The C compiler identification is GNU 7.5.0
<snip>
-- Detecting CXX compile features - done
COMPILE OPTIONS 
<snip>
-- Build files have been written to: /a_directory/test

注意行compile_options显示一个空变量,我理解add_compile_options指令应设置。回报

<snip>
[100%] Linking CXX executable test
/a_path/cmake -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=1
/usr/bin/c++    -L/a/libdir -L/another/libdir -rdynamic CMakeFiles/test.dir/main.o  -o test 
<snip>

,没有-wall

我在做什么错? NB:CMAKE版本3.15.3

I am trying a very simple example with cmake to use the add_compile_options directive

CMakeLists.txt:

add_compile_options(-Wall)
MESSAGE("COMPILE OPTIONS ${COMPILE_OPTIONS}")
add_executable(test main.cpp)

where main.cpp is some (empty) main function. I do

rm -r CMakeFiles/ cmake_install.cmake Makefile test CMakeCache.txt
cmake CMakeLists.txt
make VERBOSE=1

cmake output like:

<snip>
-- The C compiler identification is GNU 7.5.0
<snip>
-- Detecting CXX compile features - done
COMPILE OPTIONS 
<snip>
-- Build files have been written to: /a_directory/test

Note the line COMPILE_OPTIONS shows an empty variable which I understand the add_compile_options directive should set. make returns

<snip>
[100%] Linking CXX executable test
/a_path/cmake -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=1
/usr/bin/c++    -L/a/libdir -L/another/libdir -rdynamic CMakeFiles/test.dir/main.o  -o test 
<snip>

and there is no -Wall

what am I doing wrong? Nb: cmake version 3.15.3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文