How to organize subdirectories?

已回答

 Hi,

I am new with CMake and CLion so I am stuck at how to organize my project. I want my project structure to look something like this

.
./my_lib1
./my_lib2
./external_lib

my_lib1 and my_lib2 are two independent sub-projects that in the end produce a single library. These libraries can then be used from the root folder. Both my_lib1 and my_lib2 depend on external_lib.

The only way I could achieve this so far is to have one single CMakeLists file in the root directory. That way, all targets including tests will be in one file which would become massive and cluttered over time.

When I create CMakeLists files in my_lib1 and my_lib2, CLion does not find the targets defined there but only targets from the root folder. If I open my_lib1 as a project in CLion, it fails to compile as the dependency on external_lib is not a subdirectory anymore.

Instructions on how to organize my project well would be appreciated.

0

Hello! We have a feature request for multiple projects support, but no ETA for now: https://youtrack.jetbrains.com/issue/CPP-1537. Feel free to comment or upvote. The workaround is the one you've already found - to create a top-level CMake file containing just add_subdirectory() projects pointing to the actual projects.

0

请先登录再写评论。