Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cpplint.py & cmake: how to specify include files

Assume I have a project of the following directory structure:

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

If in src/foo.cc I include the header file like #include "foo.h" and then run Google's cpplint.py on it, it complains with

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

So I include it as #include "./foo.h". Now I get another complaint:

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

However, if I include it as #include "src/foo.h", the compiler won't find it, with my current setup of CMake. This is how my two CMakeLists.txt files look like:

CMakeLists.txt:

project(myproject)
add_subdirectory(src)

src/CMakeLists.txt:

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

Is the way I'm using CMake somehow fundamentally wrong? Should I remove the src/CMakeLists.txt file entirely, and specify all source files in the base CMakeLists.txt with their full path?

Or should I simply ignore cpplint's complaints, as they don't really fit to how CMake projects are to be set up?

like image 678
Georg P. Avatar asked Nov 08 '22 06:11

Georg P.


1 Answers

Add include_directories(${CMAKE_SOURCE_DIR}) in your top level CMakeLists.txt, like Wander suggested:

project(myproject)
include_directories(${CMAKE_SOURCE_DIR})
add_subdirectory(src)
like image 129
cphurley82 Avatar answered Nov 15 '22 11:11

cphurley82