#Why don't my CMake Tools custom build variants work properly?

6 messages · Page 1 of 1 (latest)

wet tendon
#

I am trying to set up custom build variants in vs code with CMake Tools extension. I have found some documentation about it here: https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/variants.md. This is the content of cmake-variants.yaml file:

buildType:
default: debug
description: Build variants
choices:
debug:
short: Debug
long: Build with all debugging information included
buildType: Debug
release:
short: Release
long: Build with all debugging information stripped out
buildType: Release

As the documentation says, buildType is a string that will be set for CMAKE_BUILD_TYPE. So, for debug variant it should be set to "Debug" and for release it will be "Release". In my CMakeLists.txt I have this piece of code:

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(Sandbox PRIVATE "T_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /Zi /Od")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_definitions(Sandbox PRIVATE "T_RELEASE")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /MD")
endif()

None of this if statements ever work, so I guess CMAKE_BUILD_TYPE is either empty string or something other from "Debug" and "Release". What is the problem here? Is there some decent tutorial on how to set up the build variants correctly?

vernal acornBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

barren shale
#

What tool chain are you on? Build type is not set for multi config setups like msbuild(msvc)

wet tendon
barren shale
wet tendon
#

So, the build variant is unknown before the actual build, right? I don’t quite understand what generator expressions are and what do they even do