I'm trying to use cmake, but I'm new both to cmake and c++. I'd like to have a piece of code to use in different other programs. The folder structure is like this:
/modules/foo
/modules/foo/src
/modules/foo/include/foo
/cmake
/apps/bar
/apps/bar/src
/apps/bar/include
My problem is that in the bar main I can include (and compiling and running) both
#include "foo.h"
#include "foo/foo.h"
I think this is a symptom that something is wrong. What I'm looking for is something like
#include "foo.h" // only inside the foo source code
#include "foo/foo.h" // outside
If I remove include_directories(include/foo)
from /modules/foo/CMakeLists.txt I get a compiling error that says 'foo.h' file not found in /modules/foo/src/foo.cpp
While if I remove include_directories(${CMAKE_CURRENT_LIST_DIR}/../modules/foo/include)
from FindFoo.cmake I get the error in 'foo/foo.h' file not found /apps/bar/src/main.cpp
What can I do? What is the common practice to resolve this kind of problems? Do I have to ignore the fact that in apps/bar/src/main.cpp I can include both foo.h
and foo/foo.h
? Do I have to write the include_directories
only once and use #include "foo/foo.h
also in foo.cpp?