1

I'm looking to set CMake's release mode from the command-line on any platform. I found e.g. here that the details are slightly different on the different platforms. But to simplify CI-setup I'm looking to execute the same command on Unix and Windows. I tried:

cmake . -DCMAKE_BUILD_TYPE=RELEASE
cmake --build .

But then I get on Windows:

Manually-specified variables were not used by the project:

   CMAKE_BUILD_TYPE

Is it even possible? If so, what should I use?

Tom de Geus
  • 5,625
  • 2
  • 33
  • 77
  • 1
    This is not a distinction between Linux and Windows. This is distinction between **single-configuration** and **multi-configuration** [generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html). For the first type of generator a build type is set when `cmake` is firstly run (with `CMAKE_BUILD_TYPE` parameter). For the second type the build type is set only when build the project (with `--config` option). There is hardly a common option for both type of generators. But you may choose e.g. `NMake Makefiles` generator on Windows, which is single-configuration. – Tsyvarev Nov 20 '20 at 10:07
  • Thank @Tsyvarev , that is a clear answer. It's a petty though that is seems impossible, it would be so nice to have one set of commands to run everywhere... – Tom de Geus Nov 20 '20 at 13:04
  • @Tsyvarev that would make a good answer – John McFarlane May 05 '21 at 07:43

1 Answers1

3

This is not a distinction between Linux and Windows. This is a distinction between single-configuration and multi-configuration generators.

CMake uses different specification of "build type" when configure and build a project for different type of generators:

  1. With a single-configuration generator (e.g. "Unix Makefiles") build type is specified on configuration stage using CMAKE_BUILD_TYPE variable:

    cmake -DCMAKE_BUILD_TYPE=Release <source-dir>
    cmake --build .
    
  2. With a multi-configuration generator (e.g. Visual Studio) build type is not known on configuration stage: this stage is performed for several build types at once. When build the project, one need to select appropriate build type, e.g. using --config option:

    cmake <source-dir>
    cmake --build . --config Release
    

Because build type is specified on different stages, single set of commands rarely exists for both generator types.

However, single set of commands is perfectly possible in case of selecting generator "Unix Makefiles" on Linux and generator "NMake Makefiles" on Windows: both these generators are single-configuration.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • I think point 2 is missing the directory after --build I got error `Error: /somepath/--config is not a directory` until I ran: `cmake --build . --config Release` – Peter Nimmo May 11 '22 at 17:51
  • @PeterNimmo: Yes, the option '--build' requires a value, thanks for the point. The answer is fixed now. – Tsyvarev May 15 '22 at 10:09