Issue
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?
Solution
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:
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 .
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.
Answered By - Tsyvarev Answer Checked By - David Marino (WPSolving Volunteer)