conan: CMAKE_MODULE_PATH not updated in multi-configuration project
Hello, I’d like to create Visual Studio project with Debug and Release mode. In CMakeLists.txt file I have searching for Protobuf (since I have to generate necessary files from *.proto file). Without explicitly setting CMAKE_BUILD_TYPE to either Debug or Release CMAKE_MODULE_PATH isn’t updated with packages root paths and due to that fact searching for library fails.
Code in conanbuildinfo_multi.cmake:
macro(conan_set_find_paths)
if(CMAKE_BUILD_TYPE)
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(CMAKE_PREFIX_PATH ${CONAN_CMAKE_MODULE_PATH_DEBUG} ${CMAKE_PREFIX_PATH})
set(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH_DEBUG} ${CMAKE_MODULE_PATH})
else()
set(CMAKE_PREFIX_PATH ${CONAN_CMAKE_MODULE_PATH_RELEASE} ${CMAKE_PREFIX_PATH})
set(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH_RELEASE} ${CMAKE_MODULE_PATH})
endif()
endif()
endmacro()
For my needs, I had to hack it to this form:
macro(conan_set_find_paths)
set(CMAKE_PREFIX_PATH ${CONAN_CMAKE_MODULE_PATH_RELEASE} ${CMAKE_PREFIX_PATH})
set(CMAKE_MODULE_PATH ${CONAN_CMAKE_MODULE_PATH_RELEASE} ${CMAKE_MODULE_PATH})
endmacro()
Do you think, that something should be improved? I don’t want to specify CMAKE_BUILD_TYPE, because it will enable only one configuration in Visual project.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 18 (8 by maintainers)
This is a known limitation of cmake. Paths for modules, and cmake config files, cannot be multiple, they don’t work for multi-config environments like visual studio. So the
cmake_multi
generator cannot help with this, because CMake is only able to find the path to 1 variant, the debug or the release one, but not both.I suggest to try these two different approaches:
It is possible that what you might be suffering (regarding the first approach), is something related to the protobuf package. If the protobuf package just adds itself to the path in
env_info
consumers can directly invokeprotoc
without having to do anything special, directly in the conanfile, something that I find really convenient.