CLion 2019.3 EAP: Ninja or Another Generator of Your Choice in CMake

Posted on by Anastasia Kazakova

Hi,

A new CLion 2019.3 EAP (build 193.4697.8) is now available! Get it from our website, via the Toolbox App, or as a snap package (if you are using Ubuntu). A patch-update for anyone using the previous EAP build will be available shortly.

DOWNLOAD CLION 2019.3 EAP

CMake remains the most deeply integrated project model in CLion. However, from the very beginning, we supported only the Makefiles generator. This limitation was caused by the fact that CLion was parsing the output of CMake command run with parameters such as -G “CodeBlocks – Unix Makefiles”, -G "CodeBlocks – MinGW Makefiles", or -G "CodeBlocks – NMake Makefiles" to get information about the project, which made it impossible to change the generator used.

This obviously caused some problems:

  • Ninja is known to be a much faster generator and is one of the most requested alternatives (CPP-2659).
  • With the Visual Studio toolchain, CLion was using something very similar to Makefiles – NMake, but the community expected Visual Studio CMake generators (CPP-14730).

As a solution, we considered supporting the CMake server first, but later found a better alternative – the new CMake File API, which was added by the CMake authors as a new and better way to query project information. And now, we are happy to present to you the new CLion 2019.3 build with this new API supported!

In practice, this gives you an opportunity to use any CMake generator of your choice!

Let’s look at the details.

How can I change the generator?

A very simple action is required to change the generator – just go to the CMake Profile settings in Settings / Preferences | Build, Execution, Deployment | CMake and pass the generator name in the CMake options, for example, -G Ninja:
cmake_generator

After successfully reloading your project, you can see some similar output via the generation path:
ninja_output

This works for all platforms, remote mode, and the WSL, and for all generators supported by CMake (Ninja, Xcode, Visual Studio, and Makefiles). And you can use different generators in different CMake Profiles if necessary.

There are, however, a few things to bear in mind:

  • While CMake File API first appeared in CMake 3.14, CLion supports the feature only with CMake 3.15 or higher. (Currently, CMake 3.15.3 is bundled into the 2019.3 EAP builds, so you don’t have to install anything additionally, if you simply rely on a bundled version.)
  • Make sure you have the generator itself installed on your machine (like Ninja, for example).
  • Recompiling individual files is not supported in cases where the generator was changed as CLion can’t restore the build rules information easily (CPP-17622).

How do build type settings work for multi-configuration generators?

Xcode and Visual Studio are so-called multi-configuration generators, which means the project files for all build types will be generated by CMake. However, CLion will only use the build type specified in the CMake Profile settings for indexing and the actual building (in the build command line arguments, you can find the proper config is passed by CLion, for example: –config Debug).

That’s it for today! The full release notes are available here.

DOWNLOAD CLION 2019.3 EAP

Your CLion Team
JetBrains
The Drive to Develop

Comments below can no longer be edited.

72 Responses to CLion 2019.3 EAP: Ninja or Another Generator of Your Choice in CMake

  1. Taw says:

    October 16, 2019

    Strange, I did not receive any notification email, like I used to.
    Question: is the “IDE slowness” fixed (IDEA-224636)? I cannot determine, because there so many issues linked to it and I cannot find it in the changelog.
    Thanks

    • Anastasia Kazakova says:

      October 16, 2019

      Notification email is on the way) You are just too quick.

      yes, should be. We are still trying to test is properly on our side, but if you can check it for your case and report the state in the comments to the ticket, we’ll greatly appreciate your help.

      • Taw says:

        October 16, 2019

        Indeed, I received it after I posted.:-)
        Great, I will test it tomorrow.

  2. Roman says:

    October 16, 2019

    Fantastic! Instead of waiting 10 seconds each time, now it just prints “ninja: no work to do.
    ” and launches immediately!

    Hopefully CPP-17622 can be fixed, I’m surprised CMake does not supports it.

    • Anastasia Kazakova says:

      October 16, 2019

      That’s not about CMake. There is just no clear way to understand what were the actual build rules for the file. When only one generator was allowed, it was clear enough, but here the story is much more complicated. Feel free to upvote the ticket if you consider it really important for your workflow.

      • Dmitry Nezhevenko says:

        October 17, 2019

        Could you please at least add some way to provide command to compile single file? Something like ‘build_file.sh {filename}’?

        PS. Most likely you can use compile_commands.json for this

        • Anastasia Kazakova says:

          October 17, 2019

          This might be a way to resolve it, but it definitely requires an effort. Please upvote the ticket. BTW, what do you use it for usually, just to check that the compilation of a single file is ok?

          • Dmitry Nezhevenko says:

            October 17, 2019

            Hi,

            Yes. Usually it’s used to avoid rebuilds (or heavy linker calls) when editing code.

            PS. I really like this feature for header files. CLion tries to find related cpp file that includes header file and compiles it. It saves a lot of time when editing general headers.

            PPS. I would also like to see ‘preprocess file and open result’ in editor. I know that it’s very compiler-specific..

            • Anastasia Kazakova says:

              October 17, 2019

              Thank you for the explanation!

        • Pavel Samolysov says:

          November 14, 2019

          If I right understand, the feature exists in the Intellij Bazel plugin (bridge from the IntelliJ products including CMake to the Bazel build system): you can compile a single file even a header one and all Bazel targets where the file included in srcs or hdrs will be rebuilt.

  3. Roman Popov says:

    October 17, 2019

    Looks like it does not work on Windows. I see .cmake file API directory, but Clion shows no targets. Trying to run “Build Project” ends immediately with “Cannot find any Cmake profile”

    • Miha Rozina says:

      October 17, 2019

      Same for me. Also if I use Visual Studio toolchain and Ninja generator, Ninja finds gcc compiler instead of the Visual C++ compiler set in CLion.

      • Anastasia Kazakova says:

        October 17, 2019

        Could you please check, when you build which CMake profiler is selected in the switcher in top right corner? Is it a CMake Profiler with the VS toolchain? Could you please show the compilation command CLion invoked for that case?

        • Miha Rozina says:

          October 17, 2019

          Unfortunately I cannot build anything because I cannot select the CMake configurations with custom generators (same problem as Roman Popov above).

          However the CMake configure command still runs for all configurations. This is the command CLion runs: “C:\Program Files\JetBrains\CLion 193.3519.24\bin\cmake\win\bin\cmake.exe” -DCMAKE_BUILD_TYPE=Debug -G Ninja C:\
          This is for Visual Studio toolchain with Ninja generator.

          And this is the result:
          — The C compiler identification is GNU 8.1.0
          — The CXX compiler identification is GNU 8.1.0

          • Anastasia Kazakova says:

            October 17, 2019

            Do you mean you don’t see it in the switcher?

          • Miha Rozina says:

            October 17, 2019

            In the drop down menu left of the Run button. Is that the switcher?

            • Anastasia Kazakova says:

              October 17, 2019

              yes, exactly

          • Ahmed Yarub Hani Al Nuaimi says:

            April 16, 2020

            I can confirm that when I have c++.exe in PATH, it is picked as the compiler regardless of the configured toolchain. I had to remove it from the PATH and only then it could find Visual Studio’s compiler.

      • Markus Böck says:

        October 17, 2019

        This is due to cmake not knowing which compiler to choose. Just also specify – DCMAKE_CXX_COMPILER=cl.exe and likewise for C

        • Anastasia Kazakova says:

          October 17, 2019

          CMake Profile is using the VS toolchain and the toolchain should know the compiler. You can check which compiler is in use in Settings | Build, Execution, Deployment | Toolchains | VS toolchain, which should be selected for the dedicated CMake profile.

    • Anastasia Kazakova says:

      October 17, 2019

      Could you please try Tools | CMake | Reset Cache and Reload Project? If still doesn’t work, then we probably need some more details to investigate the case as we can’t simply reproduce it on our side.

      • Miha Rozina says:

        October 17, 2019

        I have tried CMake reset cache and the result is the same. CMake configurations with custom generators are not shown in the drop down menu with CMake targets so it is not possible to build the project with those configurations.

        • Anastasia Kazakova says:

          October 17, 2019

          Let’s move to discussion to the corresponding ticket to make it easier https://youtrack.jetbrains.com/issue/CPP-17735

        • Anastasia Kazakova says:

          October 17, 2019

          Could you please do the same as requested here: https://youtrack.jetbrains.com/issue/CPP-17735#focus=streamItem-27-3742504.0-0 ?

          • Anastasia Kazakova says:

            October 17, 2019

            And please check if there is maybe this exception in your case https://youtrack.jetbrains.com/issue/CPP-17728 ?

            • Anastasia Kazakova says:

              October 17, 2019

              To check the exception, you might see an exclamation icon in the bottom right corner, press it and see if there is this exception with NMake appeared.
              For now, we managed to reproduce smth similar but with this exception happening. So wondering if that’s the same case on your side.

          • Miha Rozina says:

            October 17, 2019

            Yes, I get the same exception upon CMake reload.

          • Roman Popov says:

            October 18, 2019

            Looks like CPP-17728 is also root cause in my case.

      • Pavel Samolysov says:

        November 14, 2019

        Anastasia, do you have any info when the Clang toolchain (at least the compiler and linker may be without debugging) will be supported on Windows? Now when I pass CMAKE_CXX_COMPILER and CMAKE_C_COMPILER, CMake works fine but then Clion tries to check something and fails because uses -I with paths containing spaces

        Cannot get compiler information:
        	Compiler exited with error code 1: ...
        
        clang-cl: error: no such file or directory: 'Files\'
        	clang-cl: error: no such file or directory: '(x86)/Microsoft\'
        	clang-cl: error: no such file or directory: 'Visual\'
        	clang-cl: error: no such file or directory: 'Studio/2019/BuildTools/DIA\'
        	clang-cl: error: no such file or directory: 'SDK/include'
        

        I can open an issue in YouTrack but I believe I’m not the first who asking about it.

        Thank you.

        • Anastasia Kazakova says:

          November 14, 2019

          Clang on Windows works when installed from MinGW or Cygwin. As a separate installation, it’s not supported and unfortunately, I can’t provide an estimation. But you can upvote and follow this ticket for the updates: https://youtrack.jetbrains.com/issue/CPP-10711

  4. khancyr says:

    October 17, 2019

    Very nice ! It works for me on linux.
    A nice addition would be to have an option on Settings to force output coloration on Ninja !

  5. Wiktor Żurawik says:

    October 17, 2019

    Fantastic update. We had a special plugin to support XCode CMake generator, however, this feature will take that weight off our shoulders. 🙂 Thank you.

  6. Sanny Sanoff says:

    October 17, 2019

    This is great! Works with Ninja (linux, had to remove build dir) ! But to appreciate it fully, we need another easy improvement.

    My (any i think mostly anyone’s) workflow is “change/compile/run”. So what happens is I changed few lines and then I press run. It begins to compile. But at the same time, 90% of CPU is eaten by background code analysis. You know, that CIDR stuff. I have all my cores filled with:

    at com.jetbrains.cidr.lang.symbols.symtable.FileSymbolTable$1Builder.process(FileSymbolTable.java:332)
    at com.jetbrains.cidr.lang.symbols.symtable.FileSymbolTable.processFile(FileSymbolTable.java:291)
    at com.jetbrains.cidr.lang.symbols.symtable.FileSymbolTable.processSymbols(FileSymbolTable.java:482)
    at com.jetbrains.cidr.lang.psi.impl.symbols.OCFileGlobalSymbolsCache.processFileImpl(OCFileGlobalSymbolsCache.java:159)
    at com.jetbrains.cidr.lang.psi.impl.symbols.OCFileGlobalSymbolsCache.processFile(OCFileGlobalSymbolsCache.java:109)

    it’s eating all cores for good 15 seconds after each little change in file (even adding empty line between methods), so compilation is slowed down noticeably.

    Easy solution: could you enable option to stop analysis if compilation is launched?

  7. Martin Pecka says:

    October 17, 2019

    My Jetbrains Toolbox on Windows reported this new version and installed it automatically, but the linux one doesn’t know about this EAP version. It shows 193.4386 and no updates available. And I have the EAP installation enabled, and the toolbox had already installed a few EAP versions on this machine.

    • Anastasia Kazakova says:

      October 17, 2019

      193.4697.8 is the latest build. Probably, your Linux is already updated (maybe automatic updates are enabled).

  8. Robin Thoni says:

    October 17, 2019

    I’ve been waiting for this since 2017, THANK YOU!

  9. Kevin Bro says:

    October 17, 2019

    Make sure that the configured toolchain does not have a make executable set, otherwise ninja will not work!

    • Anastasia Kazakova says:

      October 17, 2019

      Do you mean you’ve changed the Make detected by the CMake and then Ninja doesn’t work?

    • Anastasia Kazakova says:

      October 17, 2019

      Interesting bug! Thanks for pointing this. We’ve created a report: https://youtrack.jetbrains.com/issue/CPP-17749

  10. Roman Popov says:

    October 17, 2019

    Is it possible to add existing build directory to Clion? In a company I work for build is automated with gradle : it builds all project components written in various languages. For C++ sub-projects it uses CMake with ninja generator. C++ build takes 10 minutes. Currently I have to run it twice : one time with gradle, and one time in Clion.
    It was not possible before, when Clion only supported makefiles, but now since you have Ninja support, can I use existing build instead of creating new build directory from Clion?

    • Anastasia Kazakova says:

      October 18, 2019

      Now not, it was working for build directories with Makefiles generator previously, but now the task became more complicated, as now more than one generator is allowed. However, it might be a good feature to put back. Please create a feature request with your use case description. Thanks

  11. Pavel Král says:

    October 18, 2019

    Does it mean that files navigation may now respect project model context as described in https://youtrack.jetbrains.com/issue/CPP-8268 ? Thank you.

    • Anastasia Kazakova says:

      October 18, 2019

      That’s a different problem.

  12. Martin O'Shea says:

    October 18, 2019

    This definitely has moved my CLion satisfaction needle in the right direction, good job CLion team 🙂

    • Anastasia Kazakova says:

      October 18, 2019

      Thanks a lot!

  13. Olof says:

    October 18, 2019

    I’m excited to try ninja, but alas, I can’t.

    OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.

    (process:10878): Gtk-WARNING **: Locale not supported by C library.
    Using the fallback ‘C’ locale.
    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil to method sun.java2d.SunGraphicsEnvironment.isUIScaleEnabled()
    WARNING: Please consider reporting this to the maintainers of com.intellij.util.ReflectionUtil
    WARNING: Use –illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release

    I’m on Centos7

    • Anastasia Kazakova says:

      October 19, 2019

      That’s just a warning. It doesn’t affect the IDE functionality. So just simply ignore for now.

      • Olof says:

        October 22, 2019

        Aaah, yes, it does work. It starts.

        But I can’t open the settings dialog. Ctrl-Alt-s.

        • Anastasia Kazakova says:

          October 22, 2019

          Could you open it by clicking to the menu item still?

          • Olof says:

            October 22, 2019

            I tried mouse click and mnemonics as well.

          • olof says:

            October 22, 2019

            Oh, and I’ll add. Other menu options to open windows works.

            • Anastasia Kazakova says:

              October 23, 2019

              Could you please report the issue to the tracker? I assume we’ll need some more details.

  14. JSZ says:

    October 18, 2019

    Thanks for adding Ninja support! There is an issue with it though, that certain targets cannot be built from within CLion but build fine with Make. From what I can tell, usually targets that call a Python script suffer from this issue. If I hit ‘Build’, it will open the ‘Edit Configurations’ dialog with that target selected and a red X mark appears in the corner of the target. I can still build such target from the command line using ninja just fine. Could this be looked at?

    • Anastasia Kazakova says:

      October 19, 2019

      Could you please create a bug report here: https://youtrack.jetbrains.com/issues/CPP ?
      Add a screenshot of the Run configuration and an IDE log (Help | Show Log). We’ll investigate the problem. Thanks.

  15. ilya b says:

    October 20, 2019

    First of all, thank you for the long awaited Ninja generator feature!

    I had an issue setting it up, but I worked around it pretty quickly

    My setup:

    – Bundled cmake (3.15.3)
    – ninja is built locally and linked in /usr/local/bin/ninja

    Before I made any changes to CMake settings, the command line for recreating the project was

    “/Applications/CLion 2019.3 EAP.app/Contents/bin/cmake/mac/bin/cmake” -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/make -G “CodeBlocks – Unix Makefiles” /…/my/project/path/

    After I added -G Ninja it became

    “/Applications/CLion 2019.3 EAP.app/Contents/bin/cmake/mac/bin/cmake” -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/make -G Ninja /…/my/project/path/

    As you can see, -DCMAKE_MAKE_PROGRAM=/usr/bin/make is still present. This makes CMake think that make binary is Ninja, leading to a failure during project file generation

    Then I changed my CMake options to

    -G Ninja -DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja

    This prevents CMake from seeing an incorrect binary, which is still present in the command line CLion attempts to execute

    “/Applications/CLion 2019.3 EAP.app/Contents/bin/cmake/mac/bin/cmake” -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/make -G Ninja -DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja /…/my/project/path/

    As you can see, -DCMAKE_MAKE_PROGRAM appears twice, however, the latter is taking precedence.

    After this change, Ninja build works fine.

  16. Roman Popov says:

    October 22, 2019

    How I specify build command? Need to run Ninja build with Incredibuild.

Subscribe

Subscribe for updates