conan-io / cmake-conan

CMake wrapper for conan C and C++ package manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[question] Invalid: 'settings.compiler.runtime' value not defined

0xlitf opened this issue · comments

What is your question?

Hello everyone,
I am trying to build a Qt application using Qt 6.6.1 and msvc on Windows.
I note the lack of 'compiler.runtime=dynamic' in Profile host, how can I fix it?

Version:
VS 2022
QtCreator 12.0.0
conan 2.0.16
cmake 3.27.7
conanfile.txt:

[requires]
[requires]
spdlog/1.12.0


[generators]
CMakeDeps
CMakeToolchain

The first error is:

[cmake] ======== Computing necessary packages ========
[cmake] Requirements
[cmake]     fmt/10.2.0#43aafa5364c2359fc45be77d2587ab15:d113baa9ee16b64f89f83676d4b5bbc0d4854ea7 - Invalid
[cmake]     spdlog/1.12.0#489e3fd4b4cb3b8ca63b89f3c97349ed:875f5d4390427fa71dffa662bcab006fdf9e775b - Invalid
[cmake] 
[cmake] ======== Installing packages ========
[cmake] ERROR: There are invalid packages:
[cmake] fmt/10.2.0: Invalid: 'settings.compiler.runtime' value not defined
[cmake] spdlog/1.12.0: Invalid: 'settings.compiler.runtime' value not defined
[cmake] CMake Error at C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/.qtc/package-manager/conan_provider.cmake:408 (message):
[cmake]   Conan install failed='6'
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:13 (conan_install)

looking for help to resolve this issue .
Thanks in advance.

full output at QtCreator General Messages when run cmake:


[cmake] Running C:\Qt\Tools\CMake_64\bin\cmake.exe -S C:/UserName/UsingSpdlog -B C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug in C:\UserName\build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug.
[cmake] CMake start 
[cmake] 	 directory name: UsingSpdlog
[cmake] -- CMAKE_MSVC_RUNTIME_LIBRARY 
[cmake] -- Qt Creator: conan package manager auto-setup. Skip this step by setting QT_CREATOR_SKIP_CONAN_SETUP to ON.
[cmake] loading initial cache file C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/qtcsettings.cmake
[cmake] -- CMake-Conan: Checking if a default profile exists
[cmake] C:\Users\QtDev\.conan2\profiles\default
[cmake] -- CMake-Conan: cmake_system_name=Windows
[cmake] -- CMake-Conan: cmake_system_processor=x86_64
[cmake] -- CMake-Conan: CMake compiler=MSVC
[cmake] -- CMake-Conan: CMake compiler version=19.38.33130.0
[cmake] -- CMake-Conan: [settings] compiler=msvc
[cmake] -- CMake-Conan: [settings] compiler.version=193
[cmake] -- CMake-Conan: Creating profile C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/conan-dependencies/conan_host_profile
[cmake] -- CMake-Conan: Profile: 
[cmake] [settings]
[cmake] arch=x86_64
[cmake] os=Windows
[cmake] compiler=msvc
[cmake] compiler.version=193
[cmake] build_type=Debug
[cmake] [conf]
[cmake] tools.cmake.cmaketoolchain:generator=Ninja
[cmake] tools.build:compiler_executables={"c":"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/HostX64/x64/cl.exe","cpp":"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/HostX64/x64/cl.exe"}
[cmake] 
[cmake] -- CMake-Conan: conan install C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/conan-dependencies -of=C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/conan-dependencies/build/conan -pr;C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/conan-dependencies/conan_host_profile;--build=missing;-s;build_type=Debug;-g;CMakeDeps
[cmake] 
[cmake] ======== Input profiles ========
[cmake] Profile host:
[cmake] [settings]
[cmake] arch=x86_64
[cmake] build_type=Debug
[cmake] compiler=msvc
[cmake] compiler.version=193
[cmake] os=Windows
[cmake] [conf]
[cmake] tools.cmake.cmaketoolchain:generator=Ninja
[cmake] tools.build:compiler_executables={'c': 'C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/HostX64/x64/cl.exe', 'cpp': 'C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.38.33130/bin/HostX64/x64/cl.exe'}
[cmake] 
[cmake] Profile build:
[cmake] [settings]
[cmake] arch=x86_64
[cmake] build_type=Release
[cmake] compiler=msvc
[cmake] compiler.cppstd=14
[cmake] compiler.runtime=dynamic
[cmake] compiler.runtime_type=Release
[cmake] compiler.version=193
[cmake] os=Windows
[cmake] 
[cmake] 
[cmake] ======== Computing dependency graph ========
[cmake] Graph root
[cmake]     conanfile.txt: C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/conan-dependencies\conanfile.txt
[cmake] Requirements
[cmake]     fmt/10.2.0#43aafa5364c2359fc45be77d2587ab15 - Cache
[cmake]     spdlog/1.12.0#489e3fd4b4cb3b8ca63b89f3c97349ed - Cache
[cmake] 
[cmake] ======== Computing necessary packages ========
[cmake] Requirements
[cmake]     fmt/10.2.0#43aafa5364c2359fc45be77d2587ab15:d113baa9ee16b64f89f83676d4b5bbc0d4854ea7 - Invalid
[cmake]     spdlog/1.12.0#489e3fd4b4cb3b8ca63b89f3c97349ed:875f5d4390427fa71dffa662bcab006fdf9e775b - Invalid
[cmake] 
[cmake] ======== Installing packages ========
[cmake] ERROR: There are invalid packages:
[cmake] fmt/10.2.0: Invalid: 'settings.compiler.runtime' value not defined
[cmake] spdlog/1.12.0: Invalid: 'settings.compiler.runtime' value not defined
[cmake] CMake Error at C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/.qtc/package-manager/conan_provider.cmake:408 (message):
[cmake]   Conan install failed='6'
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:13 (conan_install)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] CMake Warning at C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/.qtc/package-manager/auto-setup.cmake:159 (message):
[cmake]   Qt Creator's conan package manager auto-setup failed.  Consider setting
[cmake]   QT_CREATOR_SKIP_CONAN_SETUP to ON and reconfigure to skip this step.
[cmake] Call Stack (most recent call first):
[cmake]   C:/UserName/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/.qtc/package-manager/auto-setup.cmake:169 (qtc_auto_setup_conan)
[cmake]   CMakeLists.txt:28 (project)
[cmake] 
[cmake] 
[cmake] CMake Error at CMakeLists.txt:40 (find_package):
[cmake]   By not providing "Findspdlog.cmake" in CMAKE_MODULE_PATH this project has
[cmake]   asked CMake to find a package configuration file provided by "spdlog", but
[cmake]   CMake did not find one.
[cmake] 
[cmake]   Could not find a package configuration file provided by "spdlog" with any
[cmake]   of the following names:
[cmake] 
[cmake]     spdlogConfig.cmake
[cmake]     spdlog-config.cmake
[cmake] 
[cmake]   Add the installation prefix of "spdlog" to CMAKE_PREFIX_PATH or set
[cmake]   "spdlog_DIR" to a directory containing one of the above files.  If "spdlog"
[cmake]   provides a separate development package or SDK, be sure it has been
[cmake]   installed.
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] 
[cmake] CMake process exited with exit code 1.
[cmake] 
[cmake] Elapsed time: 00:02.

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide

Hi @0xlitf

Thanks very much for your report.
I think this might be an issue of the cmake-conan wrapper, not Conan itself, so I am transferring this ticket to that repo.

@memsharded Thanks for the kind help

Hi @0xlitf

I am having a look trying to understand where is the gap.
The cmake-conan code contains:

if(CMAKE_MSVC_RUNTIME_LIBRARY)
            if(CMAKE_MSVC_RUNTIME_LIBRARY MATCHES ".*DLL$")
                set(_COMPILER_RUNTIME "dynamic")
            else()
                set(_COMPILER_RUNTIME "static")
            endif()

So in theory it should be able to set the runtime too, I don't know why it is not working in your case. Lets try the following:

  • Can you please make sure you are using the latest conan_provider.cmake?
  • Can you share your CMakeLists.txt? Or at least parts of it, is it possible that you have a quite old cmake_minimum_required and CMAKE_MSVC_RUNTIME_LIBRARY is not set? You can debug this by adding a message() in the conan_provider.cmake code.

Hi @memsharded,
I checked my files as you pointed out, CMAKE_MSVC_RUNTIME_LIBRARY is null,
cmake_minimum_required(VERSION 3.27.7),

Things got mess up, because when I remove all the caches and settings of QtCreator(by deleting C:\Users\UserName\AppData\Local\QtProject C:\Users\UserName\AppData\Roaming\QtProject C:\Users\UserName\.conan2), and downgrade QtCreator to 11.0.3, conan to version 2.0.9, everything is ok even CMAKE_MSVC_RUNTIME_LIBRARY is empty.

Then I test QtCreator 12.0.0/12.0.1 + conan 2.0.16~conan 2.0.14, all of the cases failed with error I mentioned above.
I try to use QtCreator 11.0.3 + conan 2.0.16, error occurs with:

Install finished successfully
-- CMake-conan: CONAN_GENERATORS_FOLDER=C:\Users\UserName\Downloads\build-UsingSpdlog---QtCreator-11.0.3-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug\conan-dependencies\build\conan
-- Configuring done (28.1s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/UserName/Downloads/build-UsingSpdlog---QtCreator-11.0.3-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/conan-dependencies/build
CMake Error at C:/Users/UserName/Downloads/build-UsingSpdlog---QtCreator-11.0.3-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/conan-dependencies/conan_paths.cmake:2 (list):
  Syntax error in cmake code at

    C:/Users/UserName/Downloads/build-UsingSpdlog---QtCreator-11.0.3-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/conan-dependencies/conan_paths.cmake:2

  when parsing string

    C:\Users\UserName\Downloads\build-UsingSpdlog---QtCreator-11.0.3-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug\conan-dependencies\build\conan

  Invalid character escape '\U'.
Call Stack (most recent call first):
  C:/Users/UserName/Downloads/build-UsingSpdlog---QtCreator-11.0.3-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/.qtc/package-manager/auto-setup.cmake:151 (include)
  C:/Users/UserName/Downloads/build-UsingSpdlog---QtCreator-11.0.3-Desktop_Qt_6_6_1_MSVC2019_64bit-Debug/.qtc/package-manager/auto-setup.cmake:155 (qtc_auto_setup_conan)
  CMakeLists.txt:28 (project)


CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!
CMake process exited with exit code 1.

Elapsed time: 00:29.

As of now, this problem still exists on me, but it can be bypassed:

  1. Downgrade QtCreator version to 11.0.3, the link is qtcreator 11.0.3
  2. remove .conan2 folder in C:\Users\UserName
  3. remove C:\Users\UserName\AppData\Local\QtProject C:\Users\UserName\AppData\Roaming\QtProject
  4. Downgrade conan to version 2.0.9

Then it works.

Uhm, now I am little confused.

I see in the first trace that there was a message with:

CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$CONFIG:Debug:Debug>

But for some reason later the CMAKE_MSVC_RUNTIME_LIBRARY is empty. Maybe your CMakeLists.txt is doing something, could you please share your CMakeLists.txt?

@memsharded Sorry about that, I delete that code and forget to push.
image

This is the repo UsingSpdlog

It can be build at QtCreator 11.0.3 and conan 2.0.9 now.

CMakeLists.txt is simple:

cmake_minimum_required(VERSION 3.27.7)

get_filename_component(current_dir "${CMAKE_CURRENT_SOURCE_DIR}" NAME)
string(REPLACE " " "" current_dir "${current_dir}")
string(REPLACE "-" "_" current_dir "${current_dir}")

set(CMAKE_VERBOSE_MAKEFILE ON)
message("CMake start \n\t directory name: ${current_dir}")

message(STATUS "CMAKE_MSVC_RUNTIME_LIBRARY ${CMAKE_MSVC_RUNTIME_LIBRARY}")

project("${current_dir}" VERSION 0.1 LANGUAGES CXX)
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
find_package(spdlog REQUIRED)

message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB ${PROJECT_NAME_UPPER}_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
message("src: ${${PROJECT_NAME_UPPER}_SRC}")
add_executable(${PROJECT_NAME}
   ${${PROJECT_NAME_UPPER}_SRC}
)

target_include_directories(${PROJECT_NAME} PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/
)

target_link_libraries(${PROJECT_NAME}
    Qt${QT_VERSION_MAJOR}::Core
    spdlog::spdlog
)

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

CMAKE_MSVC_RUNTIME_LIBRARY is null in QtCreator's General Messages:


Running C:\Qt\Tools\CMake_64\bin\cmake.exe -S C:/Users/UserName/Downloads/UsingSpdlog -B C:/Users/UserName/Downloads/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit_with_WebEngine-Release in C:\Users\UserName\Downloads\build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit_with_WebEngine-Release.
CMake start 
	 directory name: UsingSpdlog
-- CMAKE_MSVC_RUNTIME_LIBRARY
-- Conan: Component target declared 'spdlog::spdlog'
-- Conan: Component target declared 'fmt::fmt'
CMAKE_CURRENT_SOURCE_DIR: C:/Users/UserName/Downloads/UsingSpdlog
src: C:/Users/UserName/Downloads/UsingSpdlog/main.cpp
-- Configuring done (0.6s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/UserName/Downloads/build-UsingSpdlog-Desktop_Qt_6_6_1_MSVC2019_64bit_with_WebEngine-Release
Elapsed time: 00:01.

It might be some interaction with QtCreator maybe, we need to investigate this, but it might take a bit more.

You might be able to do some quick checks without QtCreator, just comment the Qt lines and call cmake from the command line, that could be useful information to understand what is happening

@memsharded Ok, thank you for taking the time to help me do this.

Hi @0xlitf

Sorry, I am a bit confused, is the issue solved now? Why did you close the ticket? I commented that this needs more investigation, but if it is not working, it should remain in "open" state in Github.

Is the code that sets the MSVC_RUNTIME now pushed to the repo? If it is maybe we can try to reproduce.

@memsharded
Sorry, I misunderstand you.
This problem exists, and I am still working on this.

I push a conan_for_vs2022.bat which I used to generate .sln, it works fine.
Perhaps, it's a problem of QtCreator 12.0.x.

The code below is for test, it is useless:

option(STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" ON)

if (STATIC_WINDOWS_RUNTIME)
    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()
    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()

This error can be easily reproduced by UsingSpdlog under Qt6.6.1, QtCreator 12.0.1 and conan 2.0.9(or 2.0.16 with the same error).

@memsharded Hi, I do some logs, this is the difference between QtCreator 11.0.3(left) with 12.0.1(right) (conan version 2.0.9):
image

I can not trace what happend in this line execute_process(COMMAND ${CONAN_COMMAND} install ${CMAKE_SOURCE_DIR} ${CONAN_ARGS} ${ARGN} --format=json at 'function(conan_install)'

conan profile show -pr defaultshows:

Host profile:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=193
os=Windows

Build profile:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=193
os=Windows

but conan def print_profiles(profiles) no output when run cmake in QtCreator 12.0.1:

compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release

I am checking your project.

Your conan_provider.cmake is either broken or too old. Please update it to the latest one from https://github.com/conan-io/cmake-conan/blob/develop2/conan_provider.cmake

Then your https://github.com/0xlitf/UsingSpdlog/blob/main/conan_for_vs2022.bat code is not using the cmake-conan integration at all, but the "standard" and explicit conan install + cmake flow, so that removes the cmake-conan possible issues, but I guess that you still want to use this cmake-conan integration? Or maybe you would be good using conan install + cmake --preset modern flow?

If we want to do cmake-conan integration, I'd suggest start one at a time. Start with spdlog only first, no Qt at all, and lets try to make that work using the command line, that means, calling cmake on the command line, and it should manage to call Conan. I have tested it with the latest conan_provider.cmake and I managed it to install spdlog correctly. I am willing to collaborate on your Github project, but it would be good to define all the context constraints, goals, flows, because it seems there are a bit too many moving pieces at this moment and it is difficult to know where the issues come from. Thanks!

Thanks for help,
Replacing conan_provider.cmake did not solve it.
This problem is quite beyond me, so leave it to Qt Corporation.

Should I close this issue now? Or Close as not planned?

As you wish.
I can perfectly help you to make it run in your repo without the QtCreator automatic thing, commands should be pretty straightforward, and if QtCreator is using CMake then it will probably work in QtCreator, just not using the QtCreator built-in automatic setup.

So feel free to close the issue or let me know if you still want to try to set the project up to work with Conan dependencies.

Qt Creator uses the conan_provider.cmake from conan-io. It might not just be the latest version. I've opened up https://bugreports.qt.io/browse/QTCREATORBUG-30169

The fix was to forward CMAKE_MSVC_RUNTIME_LIBRARY to conan via the toolchain file used to configure the conan dependencies.

From what I have seen conan is expecting:

[cmake] ERROR: There are invalid packages:
[cmake] fmt/10.2.0: Invalid: 'settings.compiler.runtime' value not defined
[cmake] spdlog/1.12.0: Invalid: 'settings.compiler.runtime' value not defined

when compiled with MSVC. This only works if the user would explicitly set CMAKE_MSVC_RUNTIME_LIBRARY.

I think these packages should work on MSVC without having the user to set explicitly CMAKE_MSVC_RUNTIME_LIBRARY. I don't know if this is a conan issue with MSVC or if it's a spdlog/fmt package issue.

Thanks @cristianadam for your feedback.

Indeed, Conan needs the compiler.runtime setting to be defined for dependencies, because such dependencies might use other build systems and the default to use dynamic is not always evident. So it is a required setting to install dependencies. The way that Conan understand the settings definitions defaults is that not defining things is not the same meaning as defining it with the default value, not defining a setting would mean that such setting doesn't apply, but when using msvc compiler a runtime will be used, either dynamic or static, but it is mandatory.

It is true that the cmake-conan integration requires at this moment it to be defined, so it is possible that we might want to consider also it not being defined as equivalent to define the dynamic runtime, I'll check with @jcar87 about this, thanks very much for the hints!

Hi @cristianadam, thanks.
Manually specify CMAKE_MSVC_RUNTIME_LIBRARY works fine after modified auto-setup.cmake Under your direction.
I will update the repo UsingSpdlog later.

Trying to improve the default in #609

We have added default compiler.runtime to conan_provider.cmake in #609.

It would be necessary:

  • To update your conan_provider.cmake
  • If QtCreator has it embedded or something, it would need an update too

I am closing this ticket as solved, but please do not hesitate to create a new ticket for any further issue or question. Many thanks!

Thank you so much @memsharded @cristianadam , it is you who make Conan more excellent!