-
Notifications
You must be signed in to change notification settings - Fork 260
Description
For multi-config generators (such as Ninja multi-config, Visual Studio), should Conan run install once with -s &:build_type=xxx for each config that the user might use?
As far as I know, -s build_type is used to specify the config for installing dependencies, and -s &:build_type is used to specify the config for the project. The Conan CMakeDeps generator will generate the corresponding xxx-Target-xxconfig.cmake based on -s &:build_type for finding libraries.
Multi-config generators do not explicitly specify the config when configuring the project, but rather specify the config at build time, so Conan should prepare the CMake files for finding libraries for all possible configs that might be used.
Currently, I have made some temporary modifications in my project to solve this problem:
# conan_provider.cmake
foreach(_build_config IN LISTS _build_configs)
set(_self_build_config "")
if(NOT _multiconfig_generator AND NOT _build_config STREQUAL "${CMAKE_BUILD_TYPE}")
set(_self_build_config -s &:build_type=${CMAKE_BUILD_TYPE})
endif()
# ++
if(DEFINED CONAN_INSTALL_SELF_CONFIGURATIONS)
foreach(_self_config ${CONAN_INSTALL_SELF_CONFIGURATIONS})
conan_install(${_host_profile_flags} ${_build_profile_flags} -s build_type=${_build_config} -s &:build_type=${_self_config} ${CONAN_INSTALL_ARGS} ${generator})
endforeach()
else()
conan_install(${_host_profile_flags} ${_build_profile_flags} -s build_type=${_build_config} ${_self_build_config} ${CONAN_INSTALL_ARGS} ${generator})
endif()
# --
endforeach()
# project cmake
set(CONAN_INSTALL_BUILD_CONFIGURATIONS "Release" CACHE STRING "" FORCE)
if (${generator_is_multi_config})
set(CONAN_INSTALL_SELF_CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES} CACHE STRING "" FORCE)
else ()
set(CONAN_INSTALL_SELF_CONFIGURATIONS ${CMAKE_BUILD_TYPE} CACHE STRING "" FORCE)
endif ()
set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES ${CMAKE_SOURCE_DIR}/conan_provider.cmake CACHE PATH "" FORCE)If not modified this way, Conan will only generate the corresponding CMake files based on the install configuration. For example, if I set CONAN_INSTALL_BUILD_CONFIGURATIONS to Release, but use RelWithDebInfo config for building, the dependency libraries will not be found. This is because Conan only generates xxx-Target-Release.cmake to locate the libraries. More critically, all related target properties are wrapped with generator expressions like $<$<CONFIG:Release>:xxx>. Even if you try to use CMAKE_MAP_IMPORTED_CONFIG for remapping, it won’t work because CMAKE_MAP_IMPORTED_CONFIG is ineffective against generator expressions.
I wonder why the official Conan-provided conan_provider.cmake does not handle this case?