0

I have cmake and make set up on macOS and Linux and I am trying to port this build system to Windows.

On Windows I installed cmake and was able to run cmake with the -G "Visual Studio 17 2022" option, which works, but then I don't know what to do with the files it outputs. There is no makefile, so even when I installed make with choco install make I was not able to use make. There is a Visual Studio solution .sln file and some .vcxproj files, but I can't find any information on what command I'm supposed to run next, since make does not work.

The documentation for Running CMake says to run cmake-gui.exe, which isn't helpful to me. The command line instructions mostly describe the cmake command, and also mentions the make command, but it does not mention what command to use on Windows since make does not work.

Aaron Franke
  • 3,268
  • 4
  • 31
  • 51
  • If you want to compile from the command line, `Visual Studio ...` is probably the wrong generator. Prefer `-G Ninja` (on all platforms), and build with `cmake --build`, or directly with `ninja`. (But it should be possible to build a solution from command line using `devenv.exe`, and perhaps `cmake --build` can invoke it for you conveniently). – HolyBlackCat Jul 19 '23 at 22:43
  • Thanks, `cmake --build` with Ninja works, and it's cross-platform so I can use this on Mac and Linux too. – Aaron Franke Jul 19 '23 at 22:50
  • If you do have to build a Visual Studio solution from the command line at some point: [How do I compile a Visual Studio project from the command-line?](https://stackoverflow.com/questions/498106/how-do-i-compile-a-visual-studio-project-from-the-command-line) – Retired Ninja Jul 19 '23 at 23:15

1 Answers1

0

The solution as mentioned by HolyBlackCat in the comments is to use cmake --build followed by a path, instead of make. This works cross-platform and should work with any generator, while make only works when CMake is told to output "Unix Makefiles".

Also, the Ninja generator is preferred in this case, since it works cross-platform and (in my experience) results in faster builds than using the Visual Studio* generators.

These things are not mentioned in the documentation, so hopefully this helps someone.

Aaron Franke
  • 3,268
  • 4
  • 31
  • 51