I have a project with following structure:
MyProject/
├─ CMakeLists.txt (A)
├─ foo.h
├─ ThirdParty/
│ ├─ CMakeLists.txt (B)
│ ├─ bar.h
│ ├─ ThirdPartySourceOne/
│ │ ├─ CMakeLists.txt (C)
│ │ ├─ boo.h
│ ├─ ThirdPartySourceTwo/
│ │ ├─ CMakeLists.txt (D)
│ │ ├─ far.h
CMakeLists A "includes" CMakeLists B by
add_subdirectory(ThirdParty)
CMakeLists B "includes" CMakeLists C and D
add_subdirectory(ThirdPartySourceOne)
add_subdirectory(ThirdPartySourceTwo)
far.h
includes boo.h
When I build it like this, the whole project builds fine (including the third party source).
But when I add #include ThirdParty/ThirdPartySourceTwo/far.h
to foo.h
I get an error from the far.h
along the lines of:
fatal error: ThirdPartySourceOne/boo.h: No such file or directory
25 | #include <ThirdPartySourceOne/boo.h>
| ^~~~~~~~~~~~~~~~
So how do I include the Third Party code correctly? Thank you in advance.
- I tried to search for a similar problem on Google
- I tried
include(ThirdParty/CMakeLists.txt)
which caused the (untouched) thirdparty Library's CMakeLists(B) not to find the subdirectories anymore:
CMakeLists.txt:19: error: add_subdirectory given source "ThirdPartySourceOne" which is not an existing directory. CMakeLists.txt:17 (include)
- Trial and error with Paths in CMakeLists(B) that just broke more further down the road