12

I'm trying to convert several big makefile-based applications to CMake to use CLion on them.

Every time I open the project, however, CLion takes about a quarter of an hour to load the CMake project, while the memory indicator stays below "750 of 1987MB". I admit that I'm a CMake newbie, so I guess my CMakeLists.txt files are not optimal.

Basically every application has some specific source code in a directory of its own and is using a couple of 'common' libraries. I have made a structurally equivalent project for sharing on github:

https://github.com/pe-st/zalophus/tree/master/tree

In that project there is an application 'a' and two common librairies 'atlas' and 'greeting'. Every library contains a folder 'test' with Googletest tests.

+ common
| + atlas
| | + test
| + greeting
|   + test
+ a

In reality there are about a dozen libraries below common with about 1500 .cpp and .hpp files in total, all of them using Boost and the standard library, nothing else.

The master branch of the project on github contains my first attempt, where all directories are referenced using 'add_subdirectory'. The second attempt (in the with_ext branch) is using ExternalProject_Add for the dependent libraries. When I compile/run the tests from 'greeting' it correctly compiles also the dependency 'atlas'. However it also tries to compile/run the tests of 'atlas' (which fails...) and I couldn't work out how to just compile 'atlas' without the tests.

So how should I better design the CMake project to work with a source code base as shown?

(Note: I have asked the same question also in the Jetbrains CLion forum: https://intellij-support.jetbrains.com/hc/en-us/community/posts/207559245-Large-CMake-Project-loading-is-slow-in-CLion-)

pesche
  • 3,054
  • 4
  • 34
  • 35

2 Answers2

8

The issue is not really with the CMakeLists.txt. CLion parses all source files referenced in cmake to enable most features (navigation, code-completion, refactoring). In my experience, indexing large projects can take up to several (tens of) minutes.

A way to mitigate this issue is to mark "third party" directories of your project as such: right-click on your common directory, and Mark directory as... > Libraries. You can even exclude directories from the project if needed.

Also note that the results of CLion indexing are cached: after the initial indexing, only modified files should be reparsed, even when restarting the project (Note that modifying the build options in CMakeLists might trigger a full re-index)

etienne
  • 3,146
  • 1
  • 24
  • 45
  • I never realised it, but you're right. If I load the project twice in a row, the second time is faster (first time: CMake generation 935s, building symbols 270s; second time: CMake generation 49s, building symbols 177s). It would be nice if symbol loading the second time could have more caching too... But one problem remains: as the libraries' source code often changes daily, the caching doesn't help a lot. I still will look into marking directories as libraries... – pesche Jun 27 '16 at 09:22
1

Have you tried increasing the heap size?

https://www.jetbrains.com/help/idea/increasing-memory-heap.html

From the "Build File Properties" dialog box try increasing the Maximum heap size field.

Lincoln
  • 1,008
  • 12
  • 20