Project settings apply to the current project only. They are stored in the .xml format together with other project files in the .idea directory. Project settings can include VCS configuration, code style options, the list of language inspections, and so on.
To configure project settings, select CLion | Preferences for macOS (Ctrl+Alt+S) or File | Settings for Windows and Linux.
In the Settings/Preferences dialog, settings that are marked with the icon apply only to the current project. Other settings are global and apply to all existing projects.
If you want to share settings between the already existing projects, you can use Settings Repository or the Settings Sync plugin. You can also export the settings into a ZIP archive and import them later to another IDE instance.
Create or update a CMake CACHE entry. When CMake is first run in an empty build tree, it creates a CMakeCache.txt file and populates it with customizable settings for the project. This option may be used to specify a setting that takes priority over the project's default value. The option may be repeated for as many CACHE entries as desired. Here is an image of the relevant section of the CMakeSettings.json file after the change: We will further simplify the process for enabling ASan in CMake projects in a future update. Contributions to ASan Runtime.
Default settings for new projects
You can configure settings not only for the current project, but also for all the projects that will be created later. For example, you can set particular CMake profiles as default for all new projects.
From the main menu, select File | New Projects Settings | Settings/Preferences for New Projects.
The above firmware builds include support for the class libraries and features marked below. Click to expand! The initial-cache is a file containing variables set in the following way, e.g. For the install prefix: set (CMAKEINSTALLPREFIX '/my/install/prefix' CACHE PATH ') Then just pass this file while populating the cache with cmake. Easy, but I didn't know that and found no good sample.
Share project settings through VCS
This information is valid for Git and Mercurial. If you use another version control system, refer to How to manage projects under Version Control Systems for information on how to share projects manually.
Project settings are stored in the project directory as a set of XML files under the .idea folder. This folder contains both user-specific settings that shouldn't be placed under version control and project settings that are normally shared among developers working in a team, for example, the code style configuration.
When you place a project under version control, your personal settings are automatically ignored. CLion moves workspace.xml— the file with your personal settings — to the list of ignored files to avoid conflicts with other developers' settings.
Configuration files are processed according to your choice. Once you modify the project settings, and a new configuration file is created, the IDE shows a notification at the bottom of the screen prompting you to select how you want to treat configuration files in this project:
View files: view the list of created configuration files and select, which of them you want to place under version control. After that, the selected files will be scheduled for addition to VCS.
Always Add: silently schedule all configuration files created in the .idea directory for addition to VCS (applies only to the current project).
Don't Ask Again: never schedule configuration files for addition to VCS; they will have the unversioned status until you manually add them to VCS (applies only to the current project).
If you close the notification without selecting any option, it will appear again after a new configuration file is created. The new file will also go to the list that will be there until you select one of the options even if you restart the IDE.
If the misc.xml or the .ipr file is already under version control, project configuration files are silently scheduled for addition to VCS.
CLion identifies configuration files and adds them to the list of ignored files automatically. However, if you are sharing your project manually, we recommend that you avoid placing these files and folders under version control:
- .idea/workspace.xml
- .idea/usage.statistics.xml
.idea/dictionaries folder
.idea/shelf folder
For the full list of files, refer to How to manage projects under Version Control Systems and JetBrains.gitignore.
Copy global settings to the project level
Global (IDE) settings are stored separately from projects. That is why, these settings are not shared through version control together with the project.
Some settings, however, can be copied to the project level. For example, you can create a copy of your code style configuration or inspection profiles. If you do so, the IDE creates the corresponding configuration files in the .idea directory that you can share together with the project through VCS.
CLion also provides several ways of sharing settings between different IDE instances. See Share IDE settings for details.
Visual Studio 2017 introduced an new feature: integrating with CMake directly from the IDE itself. You'll no longer have to worry about running commands separately from CMake and then opening Visual Studio. Everything can be done from Visual Studio.
In this blog post, I'll describe how to get set up quickly with Visual Studio and CMake.
Note: This blog post assumes you have basic knowledge of CMake and Visual Studio.
Note: Ensure you have Visual Studio 2017 installed (CMake comes embedded within Visual Studio).
Setting Up
In order to get started, we first need to create a empty directory (this can anywhere, I generally like to put all my C++ projects in the root C: location like C:CppDev so in this case it would be C:CppDevVsCmakeExample). Then right click on the directory and you should have a option to Open in Visual Studio. Click that and wait for Visual Studio to initialize itself.
Once that is done, Visual Studio will show a empty Solution Explorer. Right click on the directory name and select Add > New Item. Add a CMakeLists.txt. Unfortunately, it seems that Visual Studio does not understand a CMakeLists file if its extension is .cmake. I hope they'll address that, but it is a minor caveat of mine.
Now let's type this into CMakeLists.txt file:
This is a sufficiently basic example to get CMake working with Visual Studio. Visual Studio should immediately (when you save the file) invoke CMake and place output in the Output window. If you don't see it, select CMake from the dropdown.
Then add a CMakeSettings.json file to the directory by clicking on the directory and select Add > New Item. Now a CMakeSettings.json file is to give extra control over the generated files by having Visual Studio manage these generated options for you. Note that you can specify these flags within CMake itself, but this considered bad practice. This is done via the set(CMAKE_CONSTANT 'value')[1]. Why it is bad practice? Because it sets global variable and this, in turn, can lead to unintended side-effects. What Visual Studio does, is pass these settings to CMake via the -D flag (example below code snippet). Type the following into the CMakeSettings.json file:
Command line call to CMake from and by Visual Studio:
Cmake Set Environment Variable
(I have split out the commands to improve readability)
Visual Studio will internally then call CMake and will pass along the necessary parameters to CMake. A CMakeSettings.json is:
- 'configurations' – Specifies the list of configurations (targets) for which Visual Studio must compile. Various combinations are possible, the code snippet suffices for basic scenarios.
- 'name' – The name of the configuration which will appear in Visual Studio's configuration dropdown.
- 'generator' – For CMake to know which kind of files to generate.
- 'buildRoot' – The directory location where CMake must place the generated files. Visual Studio has a bunch of ${} macros which can be used [2].
- 'cmakeCommandArgs' – Extra command line arguments for CMake.
- 'buildCommandArgs' – Command line arguments for MSBuild.
Now lets add a src directory under the main directory so right click on it and click Add > New Folder and type in src. Right click on src and click Add > New Item and type in main.cpp. Inside main.cpp, type in:
Now usually pressing F7 to build the project won't work because the target has not been set correctly (it usually defaults to 'Current Document'). You'll have switch it to the 'vs_cmake_example.exe' target from the dropdown. Now we can press F7 (and then F5) to compile the project or F5 to compile and run the executable. The Output window should read that the program exited with code 0.
This concludes this blog post on using CMake and Visual Studio in cohesion. This is easily my favorite feature of Visual Studio at the moment and I'm making all my projects use this approach now and switching out old projects from Visual Studio's .vcxproj format to CMake.
Copy global settings to the project level
Global (IDE) settings are stored separately from projects. That is why, these settings are not shared through version control together with the project.
Some settings, however, can be copied to the project level. For example, you can create a copy of your code style configuration or inspection profiles. If you do so, the IDE creates the corresponding configuration files in the .idea directory that you can share together with the project through VCS.
CLion also provides several ways of sharing settings between different IDE instances. See Share IDE settings for details.
Visual Studio 2017 introduced an new feature: integrating with CMake directly from the IDE itself. You'll no longer have to worry about running commands separately from CMake and then opening Visual Studio. Everything can be done from Visual Studio.
In this blog post, I'll describe how to get set up quickly with Visual Studio and CMake.
Note: This blog post assumes you have basic knowledge of CMake and Visual Studio.
Note: Ensure you have Visual Studio 2017 installed (CMake comes embedded within Visual Studio).
Setting Up
In order to get started, we first need to create a empty directory (this can anywhere, I generally like to put all my C++ projects in the root C: location like C:CppDev so in this case it would be C:CppDevVsCmakeExample). Then right click on the directory and you should have a option to Open in Visual Studio. Click that and wait for Visual Studio to initialize itself.
Once that is done, Visual Studio will show a empty Solution Explorer. Right click on the directory name and select Add > New Item. Add a CMakeLists.txt. Unfortunately, it seems that Visual Studio does not understand a CMakeLists file if its extension is .cmake. I hope they'll address that, but it is a minor caveat of mine.
Now let's type this into CMakeLists.txt file:
This is a sufficiently basic example to get CMake working with Visual Studio. Visual Studio should immediately (when you save the file) invoke CMake and place output in the Output window. If you don't see it, select CMake from the dropdown.
Then add a CMakeSettings.json file to the directory by clicking on the directory and select Add > New Item. Now a CMakeSettings.json file is to give extra control over the generated files by having Visual Studio manage these generated options for you. Note that you can specify these flags within CMake itself, but this considered bad practice. This is done via the set(CMAKE_CONSTANT 'value')[1]. Why it is bad practice? Because it sets global variable and this, in turn, can lead to unintended side-effects. What Visual Studio does, is pass these settings to CMake via the -D flag (example below code snippet). Type the following into the CMakeSettings.json file:
Command line call to CMake from and by Visual Studio:
Cmake Set Environment Variable
(I have split out the commands to improve readability)
Visual Studio will internally then call CMake and will pass along the necessary parameters to CMake. A CMakeSettings.json is:
- 'configurations' – Specifies the list of configurations (targets) for which Visual Studio must compile. Various combinations are possible, the code snippet suffices for basic scenarios.
- 'name' – The name of the configuration which will appear in Visual Studio's configuration dropdown.
- 'generator' – For CMake to know which kind of files to generate.
- 'buildRoot' – The directory location where CMake must place the generated files. Visual Studio has a bunch of ${} macros which can be used [2].
- 'cmakeCommandArgs' – Extra command line arguments for CMake.
- 'buildCommandArgs' – Command line arguments for MSBuild.
Now lets add a src directory under the main directory so right click on it and click Add > New Folder and type in src. Right click on src and click Add > New Item and type in main.cpp. Inside main.cpp, type in:
Now usually pressing F7 to build the project won't work because the target has not been set correctly (it usually defaults to 'Current Document'). You'll have switch it to the 'vs_cmake_example.exe' target from the dropdown. Now we can press F7 (and then F5) to compile the project or F5 to compile and run the executable. The Output window should read that the program exited with code 0.
This concludes this blog post on using CMake and Visual Studio in cohesion. This is easily my favorite feature of Visual Studio at the moment and I'm making all my projects use this approach now and switching out old projects from Visual Studio's .vcxproj format to CMake.
Cmakesettings.json Visual Studio
Extra Info:
Cmake Set Path
[1] – CMake Set Command
[2] – Microsoft blog post on CMake and Visual Studio