cmake-conan
cmake-conan copied to clipboard
[bug][develop2] Issue with latest changes to conan_support.cmake
The latest change to the conan_support.cmake (commit 448d58a0c3531f75cbd4cad0b4c3be924ac00c19) has modified the way the CMAKE_PREFIX_PATH variable is updated. Previously this variable was set with every call to find_package, now it is only set when the conan install command is run i.e. the first find_package enountered.
Since this change I am seeing issues whereby calling find_package in a hierarchical CMakeLists structure using add_subdirectory is only successful for CMakeLists files that are close in the hierarchy to the file that made the first find_package call. In find_package calls from distance CMakeLists files the CMAKE_PREFIX_PATH variable is empty and CMake is unable to find the appropriate packagename-config.cmake file.
Thanks for reporting @simonimpey
cc/ @tim-goto
One fix that works locally for me as a stopgap is just to use the new method but not limit it to the single invocation where conan install is run e.g.
macro(conan_provide_dependency package_name)
get_property(CONAN_INSTALL_SUCCESS GLOBAL PROPERTY CONAN_INSTALL_SUCCESS)
if(NOT CONAN_INSTALL_SUCCESS)
find_program(CONAN_COMMAND "conan" REQUIRED)
message(STATUS "CMake-Conan: first find_package() found. Installing dependencies with Conan")
conan_profile_detect_default()
detect_host_profile(${CMAKE_BINARY_DIR}/conan_host_profile)
if(NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "CMake-Conan: Installing single configuration ${CMAKE_BUILD_TYPE}")
conan_install(-pr ${CMAKE_BINARY_DIR}/conan_host_profile --build=missing -g CMakeDeps)
else()
message(STATUS "CMake-Conan: Installing both Debug and Release")
conan_install(-pr ${CMAKE_BINARY_DIR}/conan_host_profile -s build_type=Release --build=missing -g CMakeDeps)
conan_install(-pr ${CMAKE_BINARY_DIR}/conan_host_profile -s build_type=Debug --build=missing -g CMakeDeps)
endif()
else()
message(STATUS "CMake-Conan: find_package(${ARGV1}) found, 'conan install' aready ran")
endif()
get_property(CONAN_INSTALL_SUCCESS GLOBAL PROPERTY CONAN_INSTALL_SUCCESS)
if (CONAN_INSTALL_SUCCESS)
get_property(CONAN_GENERATORS_FOLDER GLOBAL PROPERTY CONAN_GENERATORS_FOLDER)
list(PREPEND CMAKE_PREFIX_PATH "${CONAN_GENERATORS_FOLDER}")
endif()
find_package(${ARGN} BYPASS_PROVIDER)
endmacro()
Hey, sorry for the troubles. I wrote a test for that, will create a PR in a second. It seems like it works if you do add_subdirectory after all your find_packages (which is what I did for my local testing before submitting this change).
This would be fixed by https://github.com/conan-io/cmake-conan/pull/514, that has been merged.
Could you please update @simonimpey and give it a try? Thanks!