CMAKE_BUILD_TYPE is defined if CXX language enabled
This report is similar to ISSUE: #20983; Just not quite the same. I also found this after I submitted, it seems to be a possible answer, ISSUE: #19247 (closed)
I am new to using CMake in a MS Windows environment. I am used to working on Linux system.
I have found an issue (see below) of the CMAKE_BUILD_TYPE
being set (defined to Debug
) after the project
function has been called when using the LANGUAGE CXX
in the arguments of the project
function.
I have provided three generators cases used with one being NOT
DEFINED
and two being DEFINED
(NMake and Ninja Generators).
For the past ten years in Linux, I have not seen the behavior of DEFINED
in this case. Usually, CMAKE_BUILD_TYPE
has been NOT
DEFINED
after the call to the project
function using CXX
. I am not sure what is the correct behavior intended, but for me the DEFINED
is unexpected for my CMake scripts. I do have a workaround, yet it is not very appealing.
Any help or clarification would be appreciated?
Sincerely, Terry Adams
cmake_minimum_required(VERSION 3.17)
project(minimal LANGUAGES CXX)
if (DEFINED CMAKE_BUILD_TYPE)
message("It is defined as [${CMAKE_BUILD_TYPE}]")
else()
message("It is NOT defined")
endif()
# cmake version 3.17.20032601-MSVC_2
#
# project(minimal LANGUAGES CXX)
# When VS is used:
#-- Building for: Visual Studio 16 2019
#-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
#
# This is CXX configureation:
#-- The CXX compiler identification is MSVC 19.26.28806.0
#-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx86/x86/cl.exe
#-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx86/x86/cl.exe - works
#
# -G
# "" [VS] [Not Defined]
# "NMake Makefiles" [Defined Debug] **** Unexpected Behavior to me.
# "Ninja" [Defined Debug] **** Unexpected Behavior to me.
# I tried with LANGUAGES NONE and only saw NOT DEFINED.
# project(minimal LANGUAGES NONE)
# -G
# "" [VS] [Not Defined]
# "NMake Makefiles" [Not Defined]
# "Ninja" [Not Defined]