conan: [question] Conan 1.45.0 does not add root folders to `CMAKE_PREFIX_PATH`

I just read the following in the documentation for CMakeToolchain:

Note

In Conan 1.45 the CMakeToolchain doesn’t append the root package folder of the dependencies (declared in the cpp_info.builddirs) to the CMAKE_PREFIX_PATH variable. That interfered with the find_file, find_path and find_program, making, for example, impossible to locate only the executables from the build context. In Conan 2.0, the cppinfo.builddirs won’t contain by default the ‘’ entry (root package).

I am running conan 1.45.0, and this behavior inteferes highly with the possibility to locate <deps>Config.cmake files. CMake has the following behavior: Find<Dep>.cmake are located in CMAKE_MODULE_PATH, while <Dep>Config.cmake files are searched for in certain subfolders of CMAKE_PREFIX_PATH.

I am not sure, if the problem you are describing will explicitly be solved by not setting the CMAKE_PREFIX_PATH. In general, for cross compile scenarios, you control cmake variables like CMAKE_FIND_ROOT_PATH_MODE_PROGRAM and CMAKE_FIND_ROOT_PATH_MODE_LIBRARY to customize the find_library behavior.

I guess Conan knows, what packages are build requirements, and which ones regular requirements, and thus can control the build. However, not setting the CMAKE_PREFIX_PATH will certainly break our workflow.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

@lpapp Just to clarify, the CMakeToolchain sets the CMAKE_PREFIX_PATH, both to the generators folder to locate any XXXConfig.cmake file there and to thecpp_info.builddirs declared at the dependencies.

Said that, there is a difference between Conan 1.X and Conan 2. In Conan 1.X even if ["."] (root of the package) is declared at the cpp_info.builddirs of the dependencies, it will be skipped, (because the ["."] is the default). In Conan 2, the default of cpp_info.builddirs will be empty, but if it is explicitly filled with the ["."] it will set the CMAKE_PREFIX_PATH to the root of the packages.

@lasote It appears this is no longer true? I’m setting self.cpp_info.builddirs = ['xyz'], and I see ~/.conan/data/.../package/.../xyz prepended to CMAKE_MODULE_PATH by the CMakeToolchain generator, but nothing I do can change the line that touches CMAKE_PREFIX_PATH:

# Definition of CMAKE_PREFIX_PATH, CMAKE_XXXXX_PATH
# The Conan local "generators" folder, where this toolchain is saved.
list(PREPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_LIST_DIR} )

I guess it’s ok and we can live with the current approach 😄