Using cmake with Code::Blocks - c++

I have just started using Code::Blocks for editing C++ code, having used Qt Creator up until now. I want to be able to edit and compile some existing code, which comes with a CMakeLists.txt file. How can I do this?
With Qt Creator, you could specify a script which would be run when "Build" was clicked from the menu. For example, you might specify "cmake ../src", and then "make". Is there a way to do this using Code::Blocks?

You can use CMake to create a Code::Blocks project for you:
cmake -G "CodeBlocks - Unix Makefiles" ../src
This will produce a cbp project file, which you can just open with Code::Blocks. What to do when clicking on "Compile", "Run", and so on, will have been set automatically by CMake.

Related

CMake: Qt Project to CLion with MSVC 2017

I'm having a project in Qt Creator and I'm trying to port it into CLion but I found myself blocked into some problems. If any of you could help me to port this CMake project I would really appreciate it.
Qt Creator
So, here is my setup for the Qt Creator project first:
Qt: 5.14.2
Compiler: MSVC 2017 64-bits
Also, here are my custom paths and my build environment:
Also, the build (install) time in Qt Creator takes around 20-30minutes.
CLion
Now in terms of CLion and what I've tried here are the following.
and in terms of setting up the CMake:
I've also added the paths into Environment Variables from CLion
But the problem arises when I'm trying to compile the project.
I'm going to install the project via Build -> Install
After that, I need to wait for around 1h or more(even if in Qt Creator is going to take just 20-30min) to a point where the build will fail and I will receive the following error message
MASM : fatal error A1000: cannot open file : 4 [C:\PRJOJECT_NAME\build_clion\components\extern_crashpad\crashpad\util\crashpad_util.vcxproj]
but if I'm searching for that file, it exists in that folder which is specified. But the problem is that I don't understand why the same project if build with Qt Creator is working but not vice versa. Could any of you help me to understand what I'm doing wrong?
It looks like QT Creator is using Ninja as a generator and CLion is using MSVC.
Try -G Ninja in your CLion CMake Options text box. Make sure Ninja is in a path accessible by CMake.

How to manually do Run CMake & Run in QT Creator

I'm using QT Creator 3.5.1 on Ubuntu 16.0.4 for a C++ project.
"Run CMake" and "Run" commands work fine in the IDE.
I want to do these two things from a terminal without the IDE. How can I do this?
Qt creator will actually tell you in the 'compile out' pane what commands are run for cmake, usually along the line of cmake --build . -- target all. For running the application you just find the build folder and the executable, alternatively you can peek at the Projects > Run configuration (in case you specify some arguments, but clearly that's not the case)
Note that with a new cmake (>= 3.7) you want to make sure not to use cmake in the build directory that is seen by Qt Creator while that has the project open. Creator will be running cmake in server-mode and that does not like any of the cmake files being changed:-/
Creator should print exactly what it runs in the output pane. For a build that is cmake --build . --target all (in the build directory).
Make sure to run the command in the right directory. For builds that is the top level build directory, while for build targets that can be set in Project mode.
Sometimes you also need some environment variables to be set (to pick up libraries, etc.). Creator does show the environment it uses to build or run things in Project mode.

Importing a CMake project into CodeLite

I was wondering if anyone knew of a way to import an existing cmake project into the CodeLite IDE?
This is a C++ project and I have all of the .c and .h files. I have the CMake lists and what not for the project too.
I am running on Ubuntu 16.04 with CodeLite 11.0.4.
If CodeLite is not able to do this, then is there an IDE that can import a CMake project?
You can generate a CodeLite workspace with cmake by using the -G option. First, look up all available CodeLite generators by doing
cmake --help
Keep in mind that not all might work for you, depending on your system configuration. Then use one of them as you like. For example, using Ninja you can do:
cmake -G "CodeLite - Ninja" /path
where /path is the directory where your CMakeLists.txt is located.
You can generate Codelite workspace with cmake by:
cmake -G "Codelite - Unix MakeFiles" /path (where 'path' your CMakeFiles.txt is present)
For instance:
Generate Codelite workspace
cmake -G "CodeLite - Unix Makefiles" **./**
Codelite workspace is generated
Open CodeLite and build project (P.S. do not forget to set up project appropriately (e.g. compiler / workspace settings)
According to Some programmer dude, CMAKE is able to make a codeLite project. I have tested this with the version of CMAKE that you can install with sudo apt-get install in ubuntu 16.04. This works.

How can I compile Assimp with Netbeans in debug mode?

I am not a C/C++ developer, I tried to google but I couldn't find anything about.
Trying to write a simple java port of Assimp, I modified the Main.cpp code runs fine but it doesn't stop at the breakpoint, I guess because I am not compiling in debug mode.
My steps:
cloned assimp
from terminal in the directory cmake -G "Unix Makefiles"
opened the project in Netbeans from "existing sources"
compiled
This is my project Debug Property:
I don't have any other configuration other than the "Default" one.
How can I solve?
Cmake based projects are configured using the cmake configuration. Instead of switching to debug / release configuration within netbeans - as usual for "default" C/C++ Projects - you have to set CMAKE_BUILD_TYPE variable accordingly.
Using command line:
Debug: cmake -DCMAKE_BUILD_TYPE=Debug
Release: cmake -DCMAKE_BUILD_TYPE=Release
You do not need to repeat the other flags like, -G ….
Alternatively use the CMake GUI.
To get the selectable build configurations you can create them your own (go to Build -> Pre-Build and add calls as above).
TIP
It's recommended to do an out-of-source build.

How to install C++ plugin to Eclipse?

I have Eclipse Helios and wanted to code C++ using it, but I keep running into the "Launch failed. Binary Not found" error.
I installed the MingW C++ compiler using the "mingw-get-inst-20120426" file and selected the "C compiler, C++ compiler, MSYS Basic System, and MingW Developer Toolkit".
Then I went to Eclipse > project > properties > C/C++ General > Paths and Symbols, then selected the GNU C++ in the Includes tab and added the "C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++" path.
I also went to C/C++ build > Environment and appended the "C:\MinGW\bin;C:\MinGW\msys\1.0\bin" to the PATH.
Then I created a Hello World C++ project, selecting the MingW GCC under Toolchains, and then built the project using the "hammer" icon.
However, once I ran the HelloWorld program it gets the "Launch failed. Binary Not Found" error.
Here is another error:
g++ -IC:\MinGW\lib\gcc\mingw32\4.6.2\include\c++ -O0 -g3 -Wall -c -
fmessage-length=0 -osrc\HelloWorld.o ..\src\HelloWorld.cpp
Internal Builder: Cannot run program "g++": The system cannot find the
file specified.
I also downloaded the CDT (C/C++ Development Tooling) and transferred the "features" and "plugins" folder to the eclipse folder.
Can someone please give me step-by-step on how to resolve this?
Firstly, in the following examples all drive-letters should be replaced with the relevant ones on your system. Not all of these steps are really necessary, but it works (and the more the merrier).
We start with the slightly simpler release config - we want to make it compile.
Go to Project -- Properties
Look if the include directories are correct and in place.
Go to Project -- Properties -- Run/Debug Settings -- NEW -- Main Tab
Set to Release and Browse to the Release folder of the project. If the exe file is not set type in its name.
Switch to Common Tab. Check Allocate Console and Launch in Background. Don't Run yet.
Go to Project -- Properties -- C/C++ Build -- Discovery Options
Tools -- GCC C++ Compiler
"Browse" to the mingw bin folder and select the g++.exe or copy mingw32-g++.exe to g++.exe
Note: The image points to mingw32-g++.exe please use g++.exe
Right click on the project and look -- Build Configurations -- Set Active -- Release is checked.
Right click on the project -- Run As -- Run Configurations.
Under C/C++ Application select, the one which refers to the release version. Then click Run
If this works, I will show you how to set the Debug Properties. (more complicated)
Nowadays (Eclipse Juno and newer), it is much simpler. You just need to:
Install MinGW (and including C++ compiler)
Add the paths "C:\minGW\bin" and "C:\minGW\msys\1.0\bin" (or wherever you installed MinGW to) to your Windows "Path" variable
Install Eclipse. If Eclise already is installed, restart it. it will recognize that MinGW is now available.
Create a New project: "C++ Project"
For every Project type in the following dialog, you should now be able to select the "MinGW GCC" toolchain
Happy coding
See here: http://www.youtube.com/watch?v=QhvXCg2CY4Q
g++ is installed as part of MinGW. If you are getting an error in Eclipse that it cannot find g++ then your path is most likely incorrect. From a command prompt you should be able to run:
g++ --version
and it should display the version of g++ in the MinGW/bin directory.
Eclipse uses this path to locate the include files and the compiler. Once you get the path correct restart Eclipse and the problems listed in your question should be resolved.