c – cpplint.py&cmake:如何指定包含文件

c – cpplint.py&cmake:如何指定包含文件,第1张

概述假设我有一个具有以下目录结构的项目: myproject├── .git [...]├── CMakeLists.txt└── src ├── CMakeLists.txt ├── foo.cc └── foo.h 如果在src / foo.cc中我包含#include“foo.h”之类的头文件,然后在其上运行Google的cpplint.py,它会抱怨 src/fo 假设我有一个具有以下目录结构的项目:

myproject├── .git [...]├── CMakeLists.txt└── src    ├── CMakeLists.txt    ├── foo.cc    └── foo.h

如果在src / foo.cc中我包含#include“foo.h”之类的头文件,然后在其上运行Google的cpplint.py,它会抱怨

src/foo.cc:8:  Include the directory when naming .h files  [build/include] [4]

所以我把它包含在#include“./foo.h”中.现在我又得到了一个抱怨:

src/foo.cc:8:  src/foo.cc should include its header file src/foo.h  [build/include] [5]

但是,如果我将它包含在#include“src / foo.h”中,编译器将无法使用我当前的CMake设置找到它.这是我的两个CMakeLists.txt文件的样子:

的CMakeLists.txt:

project(myproject)add_subdirectory(src)

SRC /的CMakeLists.txt:

set(SRCS foo.cc)add_executable(foo ${SRCS})

我使用CMake的方式是否从根本上错了?我应该完全删除src / CMakeLists.txt文件,并使用完整路径指定基本CMakeLists.txt中的所有源文件吗?

或者我应该忽略cpplint的抱怨,因为它们不适合如何设置CMake项目?

解决方法 在您的顶级CMakeLists.txt中添加include_directorIEs(${CMAKE_SOURCE_DIR}),就像Wander建议的那样:

project(myproject)include_directorIEs(${CMAKE_SOURCE_DIR})add_subdirectory(src)
总结

以上是内存溢出为你收集整理的c – cpplint.py&cmake:如何指定包含文件全部内容,希望文章能够帮你解决c – cpplint.py&cmake:如何指定包含文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1224987.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存