Skip to content

VS: Generator does not add UseDebugLibraries in the .vcxproj file

Visual Studio projects have a setting that indicates whether the configuration is a debug or a release configuration, which holds true regardless of the actual configuration name. This is extremely useful when one wants to link against debug or release libraries, such as when injecting libraries via Nuget packages or in custom scripts. However, CMake generates debug configurations without this setting.

Note that despite wide-spread belief, this setting isn't necessarily changing how the build is made, but rather provides an indication whether it's a release or a debug build. All VS configurations come with this flag properly set and when they are copied for new configurations this flag is copied as well, so in the normal VS workflow one never finds themselves without this flag properly set.

Steps to reproduce. Copy CMake tutorial:

https://cmake.org/cmake/help/latest/guide/tutorial/index.html

Generate projects as follows:

cd Complete
cmake -S . -B build -G "Visual Studio 17 2022" -A x64

Open the generated solution, navigate to the Turorial project and go to its Properties > Advanced. You will see that Use Debug Libraries is not set and defaults to No.

This is what this configuration is supposed to look like in XML, when it is configured correctly.

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <CharacterSet>MultiByte</CharacterSet>
    <PlatformToolset>v143</PlatformToolset>
    <UseDebugLibraries>true</UseDebugLibraries>
  </PropertyGroup>

CMake should set UseDebugLibraries to true for all debug configurations that use other debug properties, such as using debug CRT, disable optimizations, don't have NDEBUG, etc., regardless of configuration name.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information