[CMake] How force cmake debug/release

Simon Richter Simon.Richter at hogyros.de
Fri Dec 7 07:10:29 EST 2018


Hi,

On 06.12.18 09:50, Andy wrote:

> If I call "cmake ." it write: "Warning:Debug"
> Debug is default and I must call "cmake . -DCMAKE_BUILD_TYPE=Release"
> for release?

That depends on the generator used. Some generators require the build
type at configuration time, some at build time. For example, the Visual
Studio generator should generate files containing both Debug and Release
configurations, and neither of your code blocks should be run.

Ideally, you should never do anything directly that depends on the build
type, but only prepare things. So rather than

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()

you'd use

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")

so generators that handle multiple build types at the same time can work.

   Simon

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://cmake.org/pipermail/cmake/attachments/20181207/9f5241c2/attachment.sig>


More information about the CMake mailing list