cmake build directory, Windows VS macOS - c++

Typical cmake produre here was:
cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg.cmake
cmake --build .
That worked on both Windows and macOS.
Howver on Windows the binary in placed under build/Debug/mylib.dll while on macOS it is placed directly under build/libmylib.dylib. How can I make it on build/Debug/libmylib.dylib on macOS too?

You could simply manually reproduce the same directory structure yourself on the Mac.
However, I would definitely make sure to only put a Debug configuration in a directory called Debug, lest you confuse yourself in the future:
mkdir Debug
cd Debug
cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg.cmake
cmake --build .

Related

Error building BGFX on windows for mingw-gcc

I am trying to build bgfx on windows 64-bit with mingw-gcc and not Visual Studio. While trying to build I got errors
I tried to build the bgfx library with make mingw-gcc-debug64 and I got errors while running the command. I got the following output: command line error My gcc is installed at C:\llvm-mingw\bin\gcc.exe. Please let me know how I can fix this. Thanks!
Try this way (note if your OS Linux you dont need install MSYS2- this is for Windows only)
install git, cmake.
Install mingw64 via "MSYS2" devtools manager. this is manual how to do it https://www.devdungeon.com/content/install-gcc-compiler-windows-msys2-cc , install MSYS2 with all dev tools (gcc toollchanain, cmake, make, mc.. )
clone to your folder on your pc cmake-version of bgfx via command "git clone --recursive https://github.com/bkaradzic/bgfx.cmake.git"
make build folder inside bgfx.cmake
from the build folder in command terminal type cmake "-G "MinGW Makefiles" .." (if your system is Linux just type "cmake .." )
"type cmake --build . --target examples" after type "cmake --build . --target tools"
That is all!

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

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.

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.