Building .SLN files on Windows without Visual Studio? - c++

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).

Related

Setting CMake default generator in Windows

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.

CMake does not create make file [duplicate]

This question already has an answer here:
Why isn't the command "cmake ." generating a makefile? [closed]
(1 answer)
Closed 3 years ago.
I am using cmake to build the project. I am new to c++ so there can be mistakes as i am unaware of how it internally works.
When i run cmake command in build directory then the response does not give any error. The output is as shown in next image.image after cmake command
Now when i go to the test directory then i see these files.
image of test directory
As i already said i don't know how it internally works but following some online tutorials i expect that there should be a make file but i'm not getting that.
Any help would be great for as i am stucked in this setup from 3 days.
This is what is want to do next:
First, standard build files should be created from
these configuration files:
cd test/ && mkdir build && cd build,
cmake ..
Note that you have to run these commands only once. Next, you can use your platform’s native build tools
for the actual building:
make -j10
And train a single decision tree or bagging classifier with:
./DecisionTreeTest, and
./BaggingTest,
If you have Visual Studio 2019 you will want to run your cmake (from the build directory) as
cmake -G "Visual Studio 16 2019" ..
and you will get a new configuration and .sln generated in your build folder.
From there you can open the .sln in visual studio, or run (in your build directory)
cmake --build .
to begin compilation of a debug build or
cmake --build . --config Release
for a release build.

Visual Studio Compile Source

I would like to compile the source:
https://github.com/Benjamin-Dobell/Heimdall
I'm have downloaded the source launch visual studio and open heimdall/main.cpp
However when trying F5 nothing happening.
Please help
Have a look at the Readmes (e.g. Win32):
Appendix B - Installing Heimdall Suite from Source
Heimdall and Heimdall Frontend both utilise CMake for managing the build
process. CMake can generate files for various build systems including GNU
Make and Visual Studio. However, official packages are compiled with GNU
Make and MinGW-W64 GCC/G++.
NOTE: Official builds use MinGW-W64 simply because on-going cross-platform
development is simpler when using just the one IDE (Jetbrain's CLion)
and similar toolchains.
1. Setup a MinGW-W64 build environment by utilising MSYS2:
http://msys2.github.io/
2. After installing MSYS2 a command prompt will launch, enter:
Pacman -Syu
Pacman -S mingw-w64-x86_64 mingw-w64-x86_64-clang mingw-w64-x86_64-cmake mingw-w64-x86_64-libusb mingw-w64-x86_64-qt5-static make
3. Add the MinGW-W64 binaries to your PATH environment variable:
export PATH="/mingw64/bin:$PATH"
4. Build Heimdall & Heimdall Frontend
mkdir build
cd build
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DQt5Widgets_DIR=/c/msys64/mingw64/qt5-static/lib/cmake/Qt5Widgets ..
make
You can checkout v1.4.0 tag, open msvc2012.sln and build that code instead.
You will need Qt Developer Framework (4.7 or later, but prior to 5.0) to build it

using CMake to build Google Test

I am trying to use CMake to build Google Test.
As mentioned in the README of Google Test,
I have issued following commands:
mkdir mybuild # Create a directory to hold the build output.
cd mybuild
cmake D:\gtest-1.6.0 # (in the README this was set as:cmake ${GTEST_DIR}, but since on my machine D:\gtest-1.6.0 is where I have downloaded gtest, I have used that in command prompt.
And here is the error I get:
Any help? any help would be greatly appreciated as I am stuck with it and can't move forward...... Thanks.
ps. I have Visual Studio 10 installed on my machine.
If you use Visual c++ compiler with cmake you must launch it from the Visual c++ command prompt. Otherwise cmake will not found your compiler.

Code::blocks cmake makefile nothing to be done when building

I've downloaded PhysFS and attempted to build it with Cmake. The option I
generated with is Code::Blocks makefiles, which generated a project file.
I supposed it was as easy as opening that project file and trying to build but
that didn't happen.
Upon building the project I get
-------------- Build: all in PhysicsFS ---------------
Using makefile: Makefile
Execution of 'make.exe -s -f Makefile all' in
'C:\Documents and Settings\Stefan.MONA-H6H4KPUJNF\Desktop\build' failed.
Nothing to be done.
I've tried checking out a similar question, but the options in the answer
were already good, and it didn't work.
I'm on windows XP SP3