Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Visual Studio 2022 (17.12.3) for opening a CMake project #17574

Open
1 task done
schwaerz opened this issue Jan 14, 2025 · 6 comments
Open
1 task done

[question] Visual Studio 2022 (17.12.3) for opening a CMake project #17574

schwaerz opened this issue Jan 14, 2025 · 6 comments
Assignees

Comments

@schwaerz
Copy link
Contributor

What is your question?

Hi,

I wanted to use Visual Studio 2022 (v 17.12.3) for building a Conan project using the CMake generator. I am stuck with the following error message seen in Visual Studio:

grafik

I think to remember that this used to work. However it does not.

I wonder whether I am doing something wrong, or whether this is bug or incompatibilty with / between Visual Studio and Conan?

I used Conan 2.10.1, CMake 3.31.7.

The relevant part in the conanfile looks like this:

    def layout(self):
        cmake_layout(self, build_folder="build")

    def generate(self):
        CMakeToolchain(self, generator="Ninja").generate()
        CMakeDeps(self).generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()
        cmake.test(cli_args=["--verbose"])

For generating the cmake preset, I am using the following commands:

cmake_config_args="--conf tools.cmake.cmake_layout:build_folder_vars=['settings.arch'] --conf tools.cmake.cmaketoolchain:generator=Ninja"
conan install . --profile:b tools/conan/auto_build.profile --profile:h tools/conan/auto_debug.profile $cmake_config_args
conan install . --profile:b tools/conan/auto_build.profile --profile:h tools/conan/auto_release.profile $cmake_config_args

If I rename CMakeUserPresets.json to CMakePresets.json Visual Studio seems to be happy. However, according to the Conan documentation I'd have expected this to work.

Probably I am missing something?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Jan 14, 2025
@memsharded
Copy link
Member

Hi @schwaerz

Thanks for your report.

I am not sure what could be failing.
I guess that you are trying to let VS to call cmake, but what happens if you call directly cmake --list-presets or cmake --preset conan-default from the command line?

@Todiq
Copy link
Contributor

Todiq commented Jan 15, 2025

Hello,

I am encountering the exact same issue.

Here is the full log, ran from powershell 7:

Click to expand log
(venv) PS C:\Users\Todiq\Documents\CAST\basetest> cmake --version
cmake version 3.31.4

CMake suite maintained and supported by Kitware (kitware.com/cmake).
(venv) PS C:\Users\Todiq\Documents\CAST\basetest> conan version
version: 2.11.0
conan_path: C:\Users\Todiq\Documents\CAST\venv\Scripts\conan
python
  version: 3.9.13
  sys_version: 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)]
  sys_executable: C:\Users\Todiq\Documents\CAST\venv\Scripts\python.exe
  is_frozen: False
  architecture: AMD64
system
  version: 10.0.26100
  platform: Windows-10-10.0.26100-SP0
  system: Windows
  release: 10
  cpu: Intel64 Family 6 Model 186 Stepping 3, GenuineIntel
(venv) PS C:\Users\Todiq\Documents\CAST\basetest> conan install -pr:a msvc .

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows
[conf]
tools.cmake.cmake_layout:build_folder_vars=['settings.os', 'settings.compiler', 'settings.compiler.version', 'settings.arch']
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
tools.env.virtualenv:powershell=pwsh

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows
[conf]
tools.cmake.cmake_layout:build_folder_vars=['settings.os', 'settings.compiler', 'settings.compiler.version', 'settings.arch']
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
tools.env.virtualenv:powershell=pwsh


======== Computing dependency graph ========
Graph root
    conanfile.py (castbasetest/0.1): C:\Users\Todiq\Documents\CAST\basetest\conanfile.py

======== Computing necessary packages ========

======== Installing packages ========

======== Finalizing install (deploy, generators) ========
conanfile.py (castbasetest/0.1): Calling generate()
conanfile.py (castbasetest/0.1): Generators folder: C:\Users\Todiq\Documents\CAST\basetest\build\windows-msvc-194-x86_64\generators
conanfile.py (castbasetest/0.1): CMakeToolchain generated: conan_toolchain.cmake
conanfile.py (castbasetest/0.1): CMakeToolchain: Preset 'conan-windows-msvc-194-x86_64' added to CMakePresets.json.
    (cmake>=3.23) cmake --preset conan-windows-msvc-194-x86_64
    (cmake<3.23) cmake <path> -G "Ninja Multi-Config" -DCMAKE_TOOLCHAIN_FILE=generators\conan_toolchain.cmake  -DCMAKE_POLICY_DEFAULT_CMP0091=NEW
conanfile.py (castbasetest/0.1): CMakeToolchain generated: C:\Users\Todiq\Documents\CAST\basetest\build\windows-msvc-194-x86_64\generators\CMakePresets.json
conanfile.py (castbasetest/0.1): CMakeToolchain generated: C:\Users\Todiq\Documents\CAST\basetest\CMakeUserPresets.json
conanfile.py (castbasetest/0.1): Generating aggregated env files
conanfile.py (castbasetest/0.1): Generated aggregated env files: ['conanbuild.bat', 'conanbuild.ps1', 'conanrun.ps1']
Install finished successfully
(venv) PS C:\Users\Todiq\Documents\CAST\basetest> cmake --list-presets
Available configure presets:

  "conan-windows-msvc-194-x86_64" - 'conan-windows-msvc-194-x86_64' config
(venv) PS C:\Users\Todiq\Documents\CAST\basetest> cmake --preset conan-windows-msvc-194-x86_64
Preset CMake variables:

  CMAKE_POLICY_DEFAULT_CMP0091="NEW"
  CMAKE_TOOLCHAIN_FILE:FILEPATH="generators\conan_toolchain.cmake"

-- Using Conan toolchain: C:/Users/Rodolphe/Documents/CAST/basetest/build/windows-msvc-194-x86_64/generators/conan_toolchain.cmake
-- Conan toolchain: Setting CMAKE_MSVC_RUNTIME_LIBRARY=$<$<CONFIG:Release>:MultiThreadedDLL>
-- Conan toolchain: C++ Standard 17 with extensions OFF
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
-- The CXX compiler identification is MSVC 19.42.34436.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (5.0s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/Rodolphe/Documents/CAST/basetest/build/windows-msvc-194-x86_64
(venv) PS C:\Users\Todiq\Documents\CAST\basetest>

I tried your solution @memsharded, but that didn't help. Updating VS from 17.12.3 to 17.12.4 didn't do much either.
This is most likely a bug from Visual Studio, as it works with older versions of the IDE

@memsharded
Copy link
Member

Thanks very much @Todiq for the feedback.
So, if it works both from the command line and with older VS versions, then yes, it seems this could be a bug in the recent VS versions.

@schwaerz
Copy link
Contributor Author

Yes, I can confirm that it works on the command line. Hope that this was not changed on purpose in VS.

@memsharded
Copy link
Member

If anyone reports or finds any relevant link in VS issue trackers, please link it here for others to follow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants