Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake and make in Windows

I understand that in linux cmake, make and make install can be combined together to produce a release. For example:

cmake -DCMAKE_BUILD_TYPE=Release ..
make
make install 

In windows, however, I cannot find similar commands that can do the same job. Usually, what is done is to build a .sln project first if Visual Studio is used, after that compile the .sln project and in the end run the INSTALL project. Will it be possible to make a release with several commands as it has been done in Linux. Many thanks.

like image 473
feelfree Avatar asked Jan 27 '14 17:01

feelfree


People also ask

Can you use CMake on Windows?

Installation. C++ CMake tools for Windows is installed as part of the Desktop development with C++ and Linux Development with C++ workloads. Both C++ CMake tools for Windows and Linux Development with C++ are required for cross-platform CMake development.

Is CMake same as make?

Make (or rather a Makefile) is a buildsystem - it drives the compiler and other build tools to build your code. CMake is a generator of buildsystems. It can produce Makefiles, it can produce Ninja build files, it can produce KDEvelop or Xcode projects, it can produce Visual Studio solutions.

Can CMake run Makefile?

CMake will create makefiles inside many of the folders inside a build directory and you can run make or make -j8 in any of these directories and it will do the right thing. You can even run make in your src tree, but since there is no Makefile in your source tree, only CMakeLists. txt files, nothing will happen.


2 Answers

You can use msbuild instead of make:

cmake -G"Visual Studio 12" ..
msbuild /P:Configuration=Release INSTALL.vcxproj

or you could use CMake's --build argument:

cmake -G"Visual Studio 12" ..
cmake --build . --target INSTALL --config Release

If you need the equivalent of the make command with no args (i.e. make all) you would build the ALL_BUILD target as well, but this is built as part of the INSTALL target anyway.

like image 156
Fraser Avatar answered Oct 13 '22 00:10

Fraser


In addition to Fraser's answer, to get the first solution to work, one might need to call MSBuild in CMD as Administrator from the original path

cmake ..
"C:\Program Files (x86)\Microsoft Visual Studio\YEAR\EDITION\MSBuild\15.0\Bin\MSBuild.exe" INSTALL.vcxproj -p:Configuration=Release

Replace YEAR and EDITION with your corresponding values e.g. 2017 and Community

You might receive the following error, which means your enviroment variable is not set.

error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

The enviroment variable can be set directly in the system settings or with CMD as Administrator. (Source for reference)

for Visual Studio 2015 and below:

SET VCTargetsPath="C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\vXXX\"

Replace vXXX with your corresponding version e.g. 140

for Visual Studio 2017 and above:

SET VCTargetsPath="C:\Program Files (x86)\Microsoft Visual Studio\YEAR\EDITION\Common7\IDE\VC\VCTargets\"

Replace YEAR and EDITION with your corresponding values e.g. 2017 and Community


Edit:

I've also noticed that some solutions in Visual Studio 2017 wont show their contents in the Solution Explorer if the enviroment variable is set. Just remove them again if necessary.

like image 26
AlexG Avatar answered Oct 13 '22 00:10

AlexG