Home > Software design >  cmake build debug/release, Windows VS macOS
cmake build debug/release, Windows VS macOS

Time:04-12

Typical cmake produre here was:

cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg.cmake
cmake --build .

That worked on both Windows and macOS. But then I noticed it was building in debug mode.

To choose build mode on Windows I did

cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg.cmake
cmake --build . --config=THEMODE

While on macOS I need to do

cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg.cmake -DCMAKE_BUILD_TYPE=THEMODE
cmake --build .

Where THEMODE is either Debug/Release.

I bet I'm missing something, isn't? The Cmake is all about Multiplatform, why it works differently to choose build mode on Windows/macOS?

CodePudding user response:

Most probably, you're generating build files for a multi-configuration tool on Windows (e.g. Visual Studio) and a single-configuration tool on macOS (e.g. Makefile). That's why you need to specify:

CodePudding user response:

There are multi-config generators and others. "Others" need CMAKE_BUILD_TYPE provided explicitly per cmake configuration. Multi-config can be generated once and built in supported configurations. Visual Studio generator is a multi-config one but it isn't cross-platform. Ninja, on the other hand, is a multi-config generator and cross-platform.

So you generate and build it the same way on all platforms:

cmake -G "Ninja Multi-Config" ..
cmake --build . --config Release

On Windows you need to run this command with VS setup in the terminal aka "Developer Terminal", otherwise there is no Ninja installed by default and MSVC compiler won't be found.

  • Related