[CMake] How to correctly default initialize CMAKE_BUILD_TYPE inside CMakeLists.txt

frodak17 frodak17 at gmail.com
Mon Jan 14 12:56:05 EST 2019


On Mon, Jan 14, 2019 at 3:48 AM Kim Walisch <kim.walisch at gmail.com> wrote:

> Hi,
>
> By default I would like to set CMAKE_BUILD_TYPE=Release (inside
> CMakeLists.txt) if the user has not defined CMAKE_BUILD_TYPE himself (e.g.
> as command-line option: cmake . -DCMAKE_BUILD_TYPE=Debug). Is there a best
> practice how to do this in CMake? I have been searching the web to see how
> other people achieved this and I found that many people use code like this:
>
> if(NOT CMAKE_BUILD_TYPE)
>         set(CMAKE_BUILD_TYPE "Release" CACHE STRING
>         "Choose the type of build, options are: None Debug Release
> RelWithDebInfo MinSizeRel."
>         FORCE)
> endif()
>
> I used this code myself in one of my projects but I recently discovered
> that this code causes issues when compiling with clang-cl on Windows.
>
> Greetings,
> Kim
>
>
Which part of that causes the problem?  It sounds like there is an issue
with Release mode flags.
Wouldn't you just have the same problem if "cmake
-DCMAKE_BUILD_TYPE=Release" was used on the command line?
I guess maybe it could be a problem if it wasn't one of the first things
done and it changed mid-processing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190114/8bb00a05/attachment.html>


More information about the CMake mailing list