Setting CMake default generator in Windows - c++

I'm trying to learn CMake so I started with the tutorial on their website. Some functioniality like versioning with .h.in files I couldn't get to work in Visual Studio so I decided to just use CMD and CMake. Due to VS being installed CMake defaulted to creating a VS solution, after uninstalling VS it now defaults to NMake Makefiles. I want to use the MinGW generator. I know I can pass this by using the -G flag but I would like to make this to CMake's default behavior.
So that:
cmake . would behave the same as cmake -G "MinGW Makefiles" .
I've tried the solution suggested here but it seems to not work. Setting default compiler in CMake
Maybe I set the environtment variable wrong I don't know. Here is how I proceeded:
open CMake GUI
open the Environment Tab
add new Entry
set name to CMAKE_GENERATOR
set value to MinGW Makefiles
press OK
But still if I create a new project and run CMake it still defaults to the NMake generator.
Do you have any suggestions.

I had to create the CMAKE_GENERATOR variable in the Windows environment variables not in CMake.

Related

Unable to run C++ cmake project in Clion [duplicate]

I'm trying to make CLion use the same version of CMake that I'm using from the command line. In Preferences > Build, Execution, Deployment > Toolchains, I tried setting a custom CMake executable path to /usr/local/Cellar/cmake/3.7.0/bin, but CMake displays a "not found" error on the same page.
For now, I had brew install the same version of CMake that CLion is using: brew switch cmake 3.6.2
But is there a way to make CLion use the version of cmake installed with brew?
Yes, you can set your own cmake binary for use in Clion.
You're on the right track, go to Preferences > Build, Execution, Deployment > Toolchains just as you did, and set CMake executabl -> Custom to
/usr/local/Cellar/cmake/3.7.0/bin/cmake
Note, your're supposed to put the absolute name of your own cmake here, not only the path to the directory containing cmake.

Building .SLN files on Windows without Visual Studio?

I have recently been trying to set up my CMake environment and some 'hello world' code in C++. I added a CMakeLists.txt and added my configurations, but when I ran cmake . in the command line, something was different from all of the tutorials.
The people on the tutorials were using a Unix based system, so the command cmake . was producing a 'makefile'. They then built the makefile using the command make.
Since I'm on windows, it generated a msvc .sln file instead of a makefile. My question is - how can I build the .sln file, similar to how they did it on Linux? I want to do it without Visual Studio 2019 and preferably in the command prompt.
I have tried searching for this question, but haven't found what I'm looking for. Thank you in advance.
First of all, you should never do an in-tree build with cmake .. It invites problems in the form of name clashes and makes it nearly impossible to get a clean rebuild.
If you're using a recent version of CMake (which you should be), the standard way to build a project varies on whether the backend generator is single-config or multi-config.
If it's single-config (like Make or Ninja), then the commands are:
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S /path/to/sources -B /path/to/build
$ cmake --build /path/to/build
The directory /path/to/build doesn't need to exist when you invoke CMake. If you wanted a Debug build, rather than Release, you would just replace that in the first line. You should never run a single-config generator without setting CMAKE_BUILD_TYPE.
If it's multi-config, like Visual Studio, then the commands are:
$ cmake -G "Visual Studio 16 2019" -A x64 -Thost=x64 -S /path/to/sources -B /path/to/build
$ cmake --build /path/to/build --config Release
The major difference here is that the config is specified in the second (build) command, rather than the first (configure).

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.

CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles"

I am trying to use cmake to build the Box2D library for c++. When I run cmake gui I get the error:
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
Configuring incomplete, errors occurred!
Most questions like these people have answered by saying "Add MinGw/bin to the PATH" but I already have that on the PATH. What else could be causing this error?
mingw32-make.exe can be installed with the standard MinGW32 installer via the appropriate checkbox:
As rubenvb points out, you'll still need to ensure that it makes it into your PATH. If you edit your environment variables via System Properties, be sure to close and reopen the CMake GUI.
If you're more accustomed to using make.exe, install MSYS and use MSYS Makefiles as the CMake generator. You'll also need to put both mingw\bin and msys\1.0\bin into your PATH.
I had the same problem and I added these three to my system path and errors were solved.
C:\Program Files\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin
C:\Program Files\CMake\bin
C:\opencv\build\install\x64\mingw\bin
You can check this answer: https://stackoverflow.com/a/74240235/3110429
Firstly check the system.
Install MINGW https://www.msys2.org/
Install gcc, g++, gdb, and cmake using pacman.
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-gdb
pacman -S mingw-w64-x86_64-cmake
Check installation:
gcc --version
g++ --version
gdb --version
Edit environment variables for your account (PATH)
C:\msys64\mingw64\bin
For cmake project on Vscode:
Create a cmake project: https://code.visualstudio.com/docs/cpp/cmake-linux#_create-a-cmake-project
Choose the Kit (Toolchain) which was installed before
Set cmake.cmakePath (If you installed with pacman, the path should be same as gcc/g++.
"cmake.cmakePath": "C:\msys64\mingw64\bin\cmake.exe"
Reset VScode: Ctrl+shift+P and type "CMake:Reset CMake Tools for Extension State"
Configure project: Ctrl+shift+P and type "CMake: Configure". You will see "built" directory and generated files.
In the path MinGW\bin try to find make.exe or mingw32-make.exe. If you don't have it then mingw32-make.exe can be installed with the standard MinGW32 installer as shown in the pervious answer.
Then have a second copy of make.exe or mingw32-make.exe to have identical two files with those names make.exe and mingw32-make.exe
and it solved my problem.

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.