Building in CLion - clion

Is it possible to build a single file in CLion and see the actual compiler command line being used?
I have a large existing project, which CLion managed to load however it fails to build, I suspect because of various CmakLists.txt setting. However as far as I can tell you can only build an entire project and it gets built using -j 8 so you get a lot of output which does not include the command line being used so it's hard to know what to fix. i know CLion does create a temporary build directory in .clion10 but I was hoping not to have to go a fish around in that.
Also as a newbie to CLion I can't seem to work out how to undock Clion Windows ( on a Windows 7 box ). The "Floating" option doesn't seem to let me drag a Window outside of the main Clion window.

You have to use add_executable command multiple times.
Here an example :
cmake_minimum_required(VERSION 3.3)
project(test_build)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(BUILD_1 main)
set(SOURCE_FILES_1 main.cc)
add_executable(${BUILD_1} ${SOURCE_FILES_1})
set(BUILD_2 main_2)
set(SOURCE_FILES_2 main_2.cc)
add_executable(${BUILD_2} ${SOURCE_FILES_2})
Old anwser :
You can use add_subdirectory(path_to_directory) to use an other CMakeLists and have multiples building process. ie: you have your cmakelists at the root of your project and multiple other in some files of your project. You just use add_subdirectory and you get other build options.
For your other question, on ubuntu i have to split the view and after i can drag in another floating window.
Under you can see one of my projects and the main CMakeLists.txt on the right
And the build options on CLion with this structure.
The CMakeLists.txt under the files are like full project builders.

Related

How do cmake configuration and default build task configuration play together in VSCode?

I'm compiling this PCL Library example. For reference, it consists of a simple cpp file that includes some PCL headers and does some basic data manipulation, and a CMakeLists.txt file.
Using the command line, I am able to build it using cmake -> make. I want to build it also using VSCode IDE. When I open this project on VSCode, it detects I'm using cmake, and if I clean/build it using the cmake extension, everything seems to work as expected (including autocompletion by intellisense, etc).
However, this takes some time as it builds the whole project in the same way you would do it from the command line, only from VSCode. I wanted to understand if I can also configure a "default build task" (via the tasks.json file) to build files using Ctrl + Shift + B, and be able to build individual files, and have a more IDE-Like experience (something like the incremental compiler of Eclipse with Java, for example).
If I add a C++ configuration, it fails to find .h files, and errors are highlighted on the open file, until I clean/rebuild via de cmake extension.
My question is, are this two options (cmake extension vs build tasks) compatible or mutually exclusive? Is defining and compiling via a task in fact more agile than building via the cmake extension?
Thanks!

How to avoid qmake Build Step if using QT Creator

I have a Qt project file (.pro) and a Makefile (self-written).
The project file is simply used for editing the source files in the IDE:
/home/project/
./src/fooApp.pro
TEMPLATE=app
CONFIG-=qt
TARGET=fooApp
SOURCES+=...
HEADERS+=...
./src/main.c
./src/foo.c
./src/foo.h
./build/Makefile
I would like to build the project via IDE QT Creator 3.5.1
Therefore I would like to invoke make on the Makefile.
During the build process I always get the error that no Makefile can be found hence no build was triggered.
The solution is to always invoke qmake first, then make (even if a Makefile is still present and custom setting make -C ../build in /home/project/)
Could someone please explain, why it is not possible ignore qmake and directly invoke make on the already existing Makefile?
(No Qt library is used for the project)
Regards
This is quite easy, I use makefile only project alot because I like qt-creator as an IDE. In the IDE goto the projects tab on the left.
Select the "build" tab near the top of that page, looks like: (build | run).
In the build steps:
remove the qmake build step by press hovering the mouse over that step and clicking the X that appears.
Edit the build directory so that it is the same directory as your makefile.
Note: you will have to click the shadow build check box next to it to enable it.
remove any other steps you don't want (infact just remove them all for now).
Add a new step make step. It will try to use the default make, but you can override that if you want. Also add any arguments like debug or -j4 etc...
Then you are done :)
Next time you hit build it will simply invoke that make command.
Note: You will need to do the same for any other configurations you have (like release, debug, etc...). You can also just add loads more configurations for doing other make options (if you have them) for instance make doxygen or such...
Just remembered you can also either:
I am not sure why, but when I tested it (as OP did) you can't seem to just setup a make step with parameters -C ../, it seems to want to look in the "build directory" first.
I tend to use the build location since its a nice feature of the IDE.
Note an issue with newer versions of Qtcreator as a makefile IDE is that you cant share your build settings with other people (i.e. can't configure control them) because they are locked to your PC profile... long story... but its very sad and I no longer use qt creator for that one reason.

running cpp project with cmake (mac)

My question is very naive. Every time I ran an algorithm, it's with an IDE so I don't know exactly what is generated in backgrown.
I try to run with my MacBook an algorithm that I didn't write and I'm blocked !
In the readme file: they said "Use cmake to generate desired projects on different platforms. (See “CM.txt” in the
“src” folder)"
In the CM.txt:
project(BlProj)
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
add_executable(BlProj
main.cpp
thi.cpp
thu.cpp
mat.cpp
Config.cpp
Stringer.cpp
)
I did: cmake CM.txt
A CM directory is generated. I will not list all the files inside: it's some cmake, bin, out, cpp, c, cxx, log, txt files.
I don't know what I can do with that!
I'm supposed to generate a compiled binary and run it with the command:
./BlProj data1 data2 10 config output
But it wasn't generated...
So I don't know how I can have the BlProj executable. Could you help me?
How do the cpp compilation work? What did cmake exactly?
Is cmake CM.txt is a good practice or not?
You can use cmake-gui to build sources.
go to CMAKE installation directory and inside bin folder run cmake-gui
Provide input where the source code is and provide an input where to build.
hit on configure and then generate.
you might need to select IDE version as well as provide additional input, it depends.
once done open generated project files with your IDE and build.

Code::blocks verbose build

I want to see the actual commands sent to g++ during a Code::Blocks build. I want to see exactly what command-line arguments it uses in the compile and link steps, and I don't want to have to poke around in the build settings GUI to do it.
Alternatively, converting the Code::Blocks project to an equivalent Makefile would work, but I see nowhere where I can do that, either...
Edit
I ended up using a Code::Blocks plugin, "cbMakeGen", to generate a makefile from which I removed some #s. Then I was able to see the commands. Surely there is an easier way...
I see you already solved the problem, but there's still a bit more to that.
Code::Blocks can write a build log when the following option is checked:
Settings->Compiler and debugger->Global compiler settings->{slide tabs to the right}->Build options tab->Save build log to HTML.
Besides, you can use "cbp2make" to convert Code::Blocks projects to makefiles. This is not a plugin like "cbMakeGen", but a stand-alone command-line tool. See also http://forums.codeblocks.org/index.php/topic,13675.0.html .
Besides the logging to html you can also go to
Settings->Compiler and debugger->Global compiler settings->{slide tabs to the right}->Other Settings and in that tab set 'Compiler Logging:' to 'full command line' (from drop down menu).
Now you can see the gcc command line in the console when you build.

setting up qt for xcode debugging

I just installed QT 4.6 on snow leopard 10.6.3. I wrote a really simple program. I can generate a xcode project using qmake, but I can't step into QT function. How can I set it up?
By default, qt is built with a debug and a non-debug library. This is my understanding. For example,
% ls /Library/Frameworks/QtCore.framework/
Contents/ Headers# QtCore# QtCore.prl QtCore_debug# QtCore_debug.dSYM/ QtCore_debug.prl Versions/
Also, my default from source build of Qt 4.7 branch also has the *_debug libs.
Setting up for Xcode is cake, you just set up your project and
% qmake -spec macx-xcode
This -spec is the default for the official mac distribution, but if you build your own from source the default is macx-g++ which creates a Makefile project.
This generates a MyProject.xcodeproj that comes preconfigured to link all the necessary Qt frameworks, sets up paths, and has a Release and Debug build target set to the same options as the official SDK's.
This is all assuming you have your qt project file set up, if you need to generate that first from a raw source directory:
% qmake -project
Debugging works "out of the box" for these generated *.xcodeproj files. However, there's one little "hitch". Since Qt is full of custom data types, Xcode doesn't know how to display their "values" in the debugger's summary pane. So you can't see what value a QString has, for example.
There's a method of entering custom macros for display, but I've found these often (always?) don't work for QObjects.
To get that working, I've started a project that uses xcode's debugger c callbacks (also mentioned in the above linked article, though their example doesn't even work o.O). I call it Qt4DataFormatters.
I've just started it and have been adding types as the need arises. It's dirt simple to create one using the existing functions as a template though.
I haven't tried this on Mac, but on Linux you need to take the following process:
First, you need to setup Qt so that it has debugging symbols available to you:
./configure -debug-and-release separate-debug-info # other options
With the debugging symbols available, you should now be able to get valid stack traces.
When building your application with qmake, you need to have the debug (or debug_and_release) flag set in your project file:
CONFIG += debug
Once you've done that, you should only need to tell the debugger where the Qt source is located:
(gdb) dir /path/to/qt/src
After that, list should show you the actual Qt source code. You may need to add additional directories under the src directory for the debugger to pick it all up.

Resources