Is there a way to work on multiple projects in CLion?
Asked Answered
C

3

21

I'm looking for a way to work on multiple projects in parallel in CLion IDE.

For now I can only work on each project in a window at a time, but I'm looking for a solution similar to Eclipse IDE (see below) - being able to see my different projects' directories on a side bar and choosing the one I want, compiling it by itself, etc.

enter image description here

Is there a way to do it?

Chianti answered 6/4, 2016 at 6:22 Comment(1)
C
25

Yes: CLion doesn't allow you to open multiple projects from the menu because it uses the CMake system, which is script based.

However, CMake is quite capable of encompassing multiple projects, and CLion will correctly parse your CMake file and show all relevant directories in the project explorer.

Example

To do this, just like in Visual Studio, you need a parent "solution" and one or more child "projects".

Here is a simple CMake example in which "my_solution" references two child projects, "my_application" and "my_library". Here, my three folders are arranged:

  • xxx/my_solution/CMakeLists.txt
  • xxx/my_application/CMakeLists.txt
  • xxx/my_library/CMakeLists.txt

And xxx/my_solution/CMakeLists.txt simply reads:

cmake_minimum_required(VERSION 3.7)
project(my_solution)

add_subdirectory("${PROJECT_SOURCE_DIR}/../my_library" "${PROJECT_SOURCE_DIR}/my_library_output")
add_subdirectory("${PROJECT_SOURCE_DIR}/../my_application" "${PROJECT_SOURCE_DIR}/my_application_output")

Note that it is also permitted to put my_application and my_library within the my_solution directory, as in Visual Studio.

Crucifix answered 24/7, 2018 at 16:26 Comment(4)
I've done this before with CLion. It's not as turnkey a solution as Eclipse or Visual Studio, but it gets the job done!Cissiee
Thanks, this solution works fine. I've added some screenshots in another response below, works 100%Oviparous
trying to get this to output to one single directory doesn't seem to work.Hagerty
see youtrack.jetbrains.com/issue/CPP-1537Davenport
S
19

No. CLion either:

  • opens a new window with the other project you want to work on
  • closes your current project and opens the new one in the current window

as you can see in the documentation. I think this is wanted in their design; probably to maintain CLion fast and reactive...

Stutter answered 28/4, 2016 at 8:34 Comment(1)
you can do that on linuxUptown
O
7

Adding some visual clues based on the answer from @c-z

This is how my project structure looking - enter image description here

This is how my root level CMakeLists.txt is looking - enter image description here

Finally, this is how my sub-directory level CMakeLists.txt is looking - enter image description here

NOTE: You may choose to remove the outer level main.cpp file (I've deleted it) Also, you can remove the project level executable to remove it from the run configuration.

Oviparous answered 24/6, 2020 at 18:53 Comment(2)
Unfortunately, Jetbrains has not yet added this feature, because this workaround is there and they are not getting enough usecase to prioritize this feature request. If you have a compelling use case, you can post it in that ticket. (Sorry, couldn't post the link, but you could find it easily.)Oviparous
see youtrack.jetbrains.com/issue/CPP-1537Davenport

© 2022 - 2024 — McMap. All rights reserved.