conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] CMakeToolchain in combination with visual studio won't allow the Ninja generator?

Open edwardvandevorst-philips opened this issue 3 years ago • 8 comments

I want to use the CMakePresets with Visual studio 2022 and use a native CMake project with Ninja generator.

However, using CMakeToolchain, I am unable to get the Ninja generator. The CMakePresets.json always has the Visual Studio generator, even with [conf] tools.cmake.cmaketoolchain:generator=Ninja and/or [general] cmake_generator = Ninja.

I tried, conan 1.50, 1.51 and 1.52.beta but with all the same result. Is it possible to enable Ninja and how should that be done?

(I tried to change it manually to Ninja, but in that case cmake fails with a platform error).

Manually removing set(CMAKE_GENERATOR_PLATFORM "x64" CACHE STRING "" FORCE) from the toolchain file and altering the CMakePresets.json resolves the issue. Would be nice if this can be fixed.

This is weird, we have several tests using Windows + Ninja generator, and one of them is explicitly checking that the generator in the CMakePresets.json is Ninja. Could you attach the profile and conan command used? Thanks

lasote avatar Aug 03 '22 07:08 lasote

conan command: conan create . -pr:b vs2022_x64_profile -pr:h vs2022_x64_profile --build=missing

conan profile:

[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.runtime=MT
compiler.version=17
build_type=Release
[options]
[build_requires]
[env]

conan config:

[log]
run_to_output = True        # environment CONAN_LOG_RUN_TO_OUTPUT
run_to_file = False         # environment CONAN_LOG_RUN_TO_FILE
level = critical            # environment CONAN_LOGGING_LEVEL
print_run_commands = False  # environment CONAN_PRINT_RUN_COMMANDS

[general]
default_profile = vs2022_x64_profile
compression_level = 9                 # environment CONAN_COMPRESSION_LEVEL
sysrequires_sudo = True               # environment CONAN_SYSREQUIRES_SUDO
request_timeout = 60                  # environment CONAN_REQUEST_TIMEOUT (seconds)
default_package_id_mode = semver_direct_mode # environment CONAN_DEFAULT_PACKAGE_ID_MODE
cmake_generator = Ninja
revisions_enabled = 1

[storage]
path = ./data

[proxies]

[hooks]
attribute_checker

[conf]
tools.cmake.cmaketoolchain:generator=Ninja

Oh, now I see. The [conf] elements go in the profile or directly (without the [conf]) in a file called global.conf instead of the conan.conf

lasote avatar Aug 04 '22 06:08 lasote

Thanks, I cannot test it right now, I will do that later. One additional question: the cmake_generator = Ninja in general section is ignored in this case?

One additional question: the cmake_generator = Ninja in general section is ignored in this case?

Not sure if ignored or fail, but it won't work. The new "conf" should be declared in the global.conf or the profile at [conf] or with -c to the conan install or conan create commands.

lasote avatar Aug 08 '22 09:08 lasote

The configuration in conan.conf is not used by the new generators, only the one from global.conf and profiles [conf]. conan.conf dissapears in 2.0, it is recommended to migrate to global.conf configuration.

memsharded avatar Aug 09 '22 08:08 memsharded

Thanks