Clion multiple debug configurations in cmake - c++

I have project with qt-gui and command line only version.
I have release and debug configuration for both gui and non gui version. I want to have different names for debug configuration in gui and non gui version. But when configuration has different name than Debug, debugging does not work and it behaves like release build.
Is there any possibility to have multiple debug configurations, each with different name?

Note, if you click on "Debug" configuration, the following hint is shown up underneath the "CMake options":
-DCMAKE_BUILD_TYPE=Debug will be passed automatically
So, you shouldn try to add -DCMAKE_BUILD_TYPE=Debug into "CMake options" expliticly when you create your own configuration with a different name, which is inherently a Debug configuration

Related

How to define multi-config in KDevelop with CMake?

I'm working with KDevelop and CMake.
When I need to debug my program, I have to switch the value of "CMAKE_BUILD_TYPE" from "Release" to "Debug" in the Project Configure dialog, and rebuild all programs in order to add debugging symbol info into programs.
When I need to release my program, I have to switch back the value to "Release", and rebuild all things again.
It's tedious and long-waiting to re-build all programs.
My question:
Is there a way, by it I can define multiple configurations for my project, and let one conf for "Debug" and another for "Release"?
Thanks!!!
I'm using KDevelop-5.2.1, but I think this method should be applicable with later versions.
Open menu: "Project" -> "Open Configuration..."
In the "Configure Project" dialog, create a new Configuration for our project.
Now we have two Configurations for our project, therefore we can set one for debugging, and another for releasing.

QtCreator 4 and CMake parameters

I used to open a CMake-based C++ project with QtCreator and pass my custom CMake command line parameters when configuring the project. In the recent versions of QtCreator (QtCreator 4 to be precise), this does not seem to be possible anymore - QtCreator configures the project with its own set of CMake variables and their default values. This is extremely annoying, because the only way to change the values of certain CMake variables is to click on 'Projects' and modify the variables one by one, which is really tedious. I have the configuration parameters for specific machine and setup on that machine in a text file that I could just paste in the configuration dialog of Qtcreator and then run CMake, but this dialog now disappeared. Do you know if there's a way of passing custom CMake values while opening a new project?
I tried to clean the build directory, remove CMakeLists.txt.user in the source tree, run CMake with my parameters and then open the project with QtCreator. Unfortunately, QtCreator ignores the cached values and generates its own ...
"Tools" > "Options" > "Build & Run" > "Your kit" > "CMake configuration"
Add a line and rebuild. You can go the short way Ctrl+5 (Projects mode) > "Manage Kits...", too.
#Manuel's answer is ideal for me when I have toolkit-specific CMake variables without project-specific variables.
When you have project-specific CMake variables, the options I have seen/used with recent QtCreator versions (~4+) are:
From QtCreator
Open the project
go to Projects (on left) and select Build Settings
Under CMake, use the "Add" button to add new settings
"Apply Configuration Changes"
"Build" menu, "Run CMake"
Notes:
if your project updates CMake variables (as most do), you may need to "Apply Configuration Changes" again.
if you have enabled the feature to automatically run CMake, it may fire off in the background, further confusing things. This can create chicken and egg situations - boo!
Outside QtCreator
Go to the build directory
Run CMake with your commands as usual
Open QtCreator
Open the project
Under Projects - Build Settings:
Confirm that the "Build directory:" is as expected
Confirm that your CMake variables appear in the list of variables
Sadly, I find both of these profoundly unsatisfying...
Since QtCreator 4.13 it is possible to set CMake parameters per project (finally):
Project > Build Settings > CMake > Initial CMake parameters

Qt Creator creates both a debug and a release folder inside the designated debug folder

I am using the default build directory in Qt Creator which is something like build-project-blah-blah-Debug. However, when I build my app in debug mode both a debug and and a release folder are created inside. If I set the build directory as build-project-blah-blah for both the debug and release builds Qt Creator does not behave properly, i.e. it complaints and it does not clean the built files.
I deduced the solution from this answer to the reverse question.
In your .pro file, add the following line to prevent the subdirectories being created:
CONFIG -= debug_and_release debug_and_release_target
This issue only occurs on Windows, not on Unix-based OS's. Windows sets these flags by default, whereas Unix implementations of QT don't. To me it was mainly a problem due to compatibility of my project between both environments.
You can choose folder for debug and release builds on the projects mode (Ctrl + 5)
There you have a combo box which says "Edit build configuration", and lets you choose Release or Debug, and then you can edit the build directory of each one

Makefile-based Eclipse CDT with run/debug launch configuration depend on release/debug build configuration

I have a Makefile that based on given target (all/debug) generates executable in release/debug directories on the project folder.
I have setup the Eclipse-CDT C/C++ build behavior mechanism to generate the right output depending on the active build configuration.
For example the "release" build configuration will call "make" with "all" as the behavior, that makes release/output file, "debug" configuration makes a debug version at debug/output
So far so good, but when I need to setup the "run configurations" I should enter the path for the binary (search project just does not show anything), Variable ${ConfigName} also does not expand there so I cannot use something like ${ConfigName}/output as binary to run/debug.
I also tried adding release and debug to the "Paths and symbols"/"Output location" and that not help either.
I can enter the relative/absolute path (for examle ./release/output) there and if I hit run, it runs the binary or if I hit debug it debugs it. However, because of the reliance on the path I have to have two launch configurations one for debug and one for release.
The problem is that run and debug configurations are basically the same only one has the option to customize gdb, which makes it very confusing. Regardless of whether it is debug or release active, one can run/debug any of the four combinations!
Is there anyway I can run/debug what actually is built? so if the debug build is active one can run/debug the debug build? I am not even constraining the debug build to be non-runnable or the release build to be non-debuggable, I guess that is asking too much. The problem is because of the two launch configurations, and I cannot find anyway to make it just one that depends on the build configuration.

copy build configuration to release configuration (Eclipse)

Once I have set the include directories and linking directories for an Eclipse project in debug configuration, is there an easy way to copy them over to the release configuration without entering them in again manually (or vice versa)?
In the project properties, in the field Configuration, you should choose between Debug, Release and All Configuration. If you select "All configurations", everything you set will be applied to Debug and Release.
The issue is that, sometimes, include and linking directories depends on the configuration. For instance : ".../Include/Debug" or ".../Include/Release". In this case, you can still use "All Configurations" and write ".../Include/${ConfigName}"
ConfigName is an Eclipse variable that is automatically preset to Debug or Release according to the configuration.
${Var} means that you want to include the value of Var. In the example above, the string will be understand by Eclipse as ".../Include/Debug" or ".../Include/Release" according to the configuration.
You can add your own variable in Properties / C/C++ Build / Build Variables, in order to do more powerful things.