question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[bug] Visual Studio 17.4.x doesn't provide CMAKE_BUILD_TYPE and generators are broken as a result

See original GitHub issue

Environment Details (include every applicable attribute)

  • Windows 10 / Windows 11:
  • Visual Studio 17.4.x (Visual studio 17.3.x did not have this issue)
  • Conan version: 1.54.0
  • Python version: 3.9

Steps to reproduce (Include if Applicable)

https://github.com/lakinwecker/cuddly-rotary-phone/

I made a minimal reproducing example. The above code compiles fine in Linux, but not in Visual studio 17.4.x. The core reason seems to be that the TARGET configuration is using CMAKE_BUILD_TYPE variable lookup to setup various things like the include directories. For example:

set_property(TARGET nlohmann_json::nlohmann_json
             PROPERTY INTERFACE_INCLUDE_DIRECTORIES
             $<$<CONFIG:Debug>:${nlohmann_json_INCLUDE_DIRS_DEBUG}>
             $<$<CONFIG:Release>:${nlohmann_json_INCLUDE_DIRS_RELEASE}>
             $<$<CONFIG:RelWithDebInfo>:${nlohmann_json_INCLUDE_DIRS_RELWITHDEBINFO}>
             $<$<CONFIG:MinSizeRel>:${nlohmann_json_INCLUDE_DIRS_MINSIZEREL}>)

In the latest visual studio, the CMAKE_BUILD_TYPE variable seems to be completely ignored. I’ve also tried with the CMakeDeps generator (which suffers from the same problem). I’ve even tried explicitly setting SET(CMAKE_BUILD_TYPE RelWithDebInfo) before find_package and it still fails.

Logs (Executed commands with output) (Include/Attach if Applicable)

Logs

conan install output (With CMakeDeps generator)

C:\Users\lakin\Source\repos\cuddly-rotary-phone>conan install . -if build/deps/conan --build missing --profile cuddly-rotary-phone -s build_type=RelWithDebInfo -pr:b=dev-windows-vs2022
Configuration (profile_host):
[settings]
arch=x86_64
arch_build=x86_64
build_type=RelWithDebInfo
compiler=Visual Studio
compiler.runtime=MD
compiler.version=17
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=17
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

conanfile.txt: Installing package
Requirements
    nlohmann_json/3.9.1 from 'conancenter' - Cache
Packages
    nlohmann_json/3.9.1:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache

Installing (downloading, building) binaries...
nlohmann_json/3.9.1: Already installed!
conanfile.txt: Generator 'CMakeDeps' calling 'generate()'
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Aggregating env generators
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo

msbuild output

>------ Build All started: Project: cuddly-rotary-phone, Configuration: dev-windows-vs2022 ------
  MSBuild version 17.4.0+18d5aef85 for .NET Framework
    Checking Build System
    Building Custom Rule C:/Users/lakin/Source/repos/cuddly-rotary-phone/CMakeLists.txt
    main.cpp
C:\Users\lakin\Source\repos\cuddly-rotary-phone\src\main.cpp(2,1): fatal error C1083: Cannot open include file: 'nlohmann/json.hpp': No such file or directory 

Build All failed.

CMake Configuration Output

1> CMake generation started for configuration: 'dev-windows-vs2022'.
1> Environment settings:
1>     CommandPromptType=Native
1>     DevEnvDir=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\
1>     ExtensionSdkDir=C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs
1>     EXTERNAL_INCLUDE=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\ATLMFC\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt
1>     Framework40Version=v4.0
1>     FrameworkDir=C:\Windows\Microsoft.NET\Framework64\
1>     FrameworkDir64=C:\Windows\Microsoft.NET\Framework64\
1>     FrameworkVersion=v4.0.30319
1>     FrameworkVersion64=v4.0.30319
1>     INCLUDE=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\ATLMFC\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt
1>     is_x64_arch=true
1>     LIB=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\ATLMFC\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\lib\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\\lib\10.0.19041.0\\um\x64
1>     LIBPATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\ATLMFC\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\lib\x86\store\references;C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0;C:\Program Files (x86)\Windows Kits\10\References\10.0.19041.0;C:\Windows\Microsoft.NET\Framework64\v4.0.30319
1>     Path=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\HostX64\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\VCPackages;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\bin\Roslyn;C:\Program Files\Microsoft Visual Studio\2022\Community\Team Tools\Performance Tools\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\\x64;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\;C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\\x64;C:\Program Files (x86)\Windows Kits\10\bin\\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\CMake\bin;C:\Users\lakin\AppData\Local\Microsoft\WindowsApps;C:\Users\lakin\AppData\Local\Programs\Python\Python310;C:\Users\lakin\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\lakin\software;;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\Linux\bin\ConnectionManagerExe
1>     PROMPT=$P$G
1>     UCRTVersion=10.0.19041.0
1>     UniversalCRTSdkDir=C:\Program Files (x86)\Windows Kits\10\
1>     VCIDEInstallDir=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\
1>     VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\
1>     VCToolsInstallDir=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\
1>     VCToolsRedistDir=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.34.31931\
1>     VCToolsVersion=14.34.31933
1>     VS170COMNTOOLS=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\
1>     VSCMD_ARG_app_plat=Desktop
1>     VSCMD_ARG_HOST_ARCH=x64
1>     VSCMD_ARG_no_logo=1
1>     VSCMD_ARG_TGT_ARCH=x64
1>     VSCMD_DEBUG=5 
1>     VSCMD_VER=17.4.1
1>     VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Community\
1>     WindowsLibPath=C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0;C:\Program Files (x86)\Windows Kits\10\References\10.0.19041.0
1>     WindowsSdkBinPath=C:\Program Files (x86)\Windows Kits\10\bin\
1>     WindowsSdkDir=C:\Program Files (x86)\Windows Kits\10\
1>     WindowsSDKLibVersion=10.0.19041.0\
1>     WindowsSdkVerBinPath=C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\
1>     WindowsSDKVersion=10.0.19041.0\
1>     __DOTNET_ADD_64BIT=1
1>     __DOTNET_PREFERRED_BITNESS=64
1>     __VSCMD_PREINIT_PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\CMake\bin;C:\Users\lakin\AppData\Local\Microsoft\WindowsApps;C:\Users\lakin\AppData\Local\Programs\Python\Python310;C:\Users\lakin\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\lakin\software;
1>     SystemDrive=C:
1>     ProgramFiles(x86)=C:\Program Files (x86)
1>     VSAPPIDDIR=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\
1>     ProgramW6432=C:\Program Files
1>     PROCESSOR_IDENTIFIER=AMD64 Family 23 Model 1 Stepping 1, AuthenticAMD
1>     TMP=C:\Users\lakin\AppData\Local\Temp
1>     PROCESSOR_ARCHITECTURE=AMD64
1>     ThreadedWaitDialogDpiContext=-4
1>     PkgDefApplicationConfigFile=C:\Users\lakin\AppData\Local\Microsoft\VisualStudio\17.0_29741712\devenv.exe.config
1>     PROCESSOR_REVISION=0101
1>     ServiceHubLogSessionKey=610E1847
1>     FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
1>     FPS_BROWSER_USER_PROFILE_STRING=Default
1>     LOGONSERVER=\\DESKTOP-RAJ240F
1>     TEMP=C:\Users\lakin\AppData\Local\Temp
1>     USERNAME=lakin
1>     SystemRoot=C:\Windows
1>     VSSKUEDITION=Community
1>     OneDrive=C:\Users\lakin\OneDrive
1>     USERDOMAIN_ROAMINGPROFILE=DESKTOP-RAJ240F
1>     CommonProgramFiles=C:\Program Files\Common Files
1>     VisualStudioDir=C:\Users\lakin\OneDrive\Documents\Visual Studio 2022
1>     ProgramData=C:\ProgramData
1>     RlsSvcPort=22112
1>     HOMEPATH=\Users\lakin
1>     OneDriveConsumer=C:\Users\lakin\OneDrive
1>     COMPUTERNAME=DESKTOP-RAJ240F
1>     ALLUSERSPROFILE=C:\ProgramData
1>     CommonProgramW6432=C:\Program Files\Common Files
1>     AMDRMPATH=C:\Program Files\AMD\RyzenMaster\
1>     VisualStudioEdition=Microsoft Visual Studio Community 2022
1>     SignInWithHomeTenantOnly=False
1>     SESSIONNAME=Console
1>     DriverData=C:\Windows\System32\Drivers\DriverData
1>     HOMEDRIVE=C:
1>     windir=C:\Windows
1>     NUMBER_OF_PROCESSORS=16
1>     OS=Windows_NT
1>     ProgramFiles=C:\Program Files
1>     ComSpec=C:\Windows\system32\cmd.exe
1>     VSAPPIDNAME=devenv.exe
1>     PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
1>     VSLANG=1033
1>     PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
1>     APPDATA=C:\Users\lakin\AppData\Roaming
1>     USERDOMAIN=DESKTOP-RAJ240F
1>     PROCESSOR_LEVEL=23
1>     USERPROFILE=C:\Users\lakin
1>     LOCALAPPDATA=C:\Users\lakin\AppData\Local
1>     VisualStudioVersion=17.0
1>     CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
1>     PUBLIC=C:\Users\Public
1>     ForceIdentityAuthenticationType=Embedded
1>     MSBuildLoadMicrosoftTargetsReadOnly=true
1> Command line: "C:\Windows\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Visual Studio 17 2022" -A x64  -DCMAKE_MODULE_PATH:STRING="C:/Users/lakin/Source/repos/cuddly-rotary-phone/build/deps/conan/" -DCMAKE_PREFIX_PATH:STRING="C:/Users/lakin/Source/repos/cuddly-rotary-phone/build/deps/conan/" -DCMAKE_FIND_PACKAGE_PREFER_CONFIG:STRING="TRUE" -DCMAKE_CXX_FLAGS:STRING="/W4 /permissive- /utf-8 /volatile:iso /EHsc /Zc:__cplusplus /Zc:throwingNew /Zc:preprocessor /wd5105 /MP12" -DCMAKE_CXX_EXTENSIONS:STRING="OFF" -DCMAKE_CXX_STANDARD:STRING="17" -DCMAKE_CXX_STANDARD_REQUIRED:STRING="ON" -DCMAKE_BUILD_TYPE:STRING="RelWithDebInfo"  "C:\Users\lakin\Source\repos\cuddly-rotary-phone" 2>&1"
1> Working directory: C:/Users/lakin/Source/repos/cuddly-rotary-phone/build/dev
1> [CMake] -- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
1> [CMake] -- Conan: Target declared 'nlohmann_json::nlohmann_json'
1> [CMake] -- 2
1> [CMake] -- C:/Users/lakin/.conan/data/nlohmann_json/3.9.1/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include
1> [CMake] -- 1
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: C:/Users/lakin/Source/repos/cuddly-rotary-phone/build/dev
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lakinweckercommented, Nov 22, 2022

Thanks again for the help, I really appreciate it!

1reaction
lakinweckercommented, Nov 22, 2022

I have tried the same transition on my real project:

  • switched to CMakeDeps and CMakeToolchain
  • added in an explicit build preset for visual studio (this is what allows it to tell that you’re using Release/RelWithDebInfo etc)

Currently rebuilding from scratch, but it’s working so far. 🤞

Read more comments on GitHub >

github_iconTop Results From Across the Web

CMake Tools 1.4.0 doesn't define CMAKE_BUILD_TYPE in ...
I am using Visual Studio Code and CMake Tools to build a simple C++ project using OpenCV. The project relies on OpenCV's opencv_world430d.dll ......
Read more >
CMAKE_BUILD_TYPE variable not set - Visual Studio Feedback
I need it because of another inconsistency with CMake and Visual Studio: CMAKE_CURRENT_BINARY_DIR variable does not point to the actual directory of binaries, ......
Read more >
How can I have CMAKE_BUILD_TYPE being propagated ...
The issue is that CanTp is always built with build type Debug regardless of CMAKE_BUILD_TYPE. CMAKE_BUILD_TYPE does have an effect on the build ......
Read more >
CMake option -DCMAKE_BUILD_TYPE=Debug does not ...
This works a bit different dependent on generator. "* Makefiles" are single-config generators, Visual Studio and Xcode are multi-config. After a ...
Read more >
Ninja Multi-Config sets up wrong dependencies (#23272)
If I configure my source tree using the Ninja Multi-Config generator, but have targets who's dependency list changes based on the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found