.. _cmake_paths_generator: ``cmake_paths`` generator ========================= This generator is especially useful if you are using ``CMake`` based only on the ``find_package`` feature to locate the dependencies. The ``cmake_paths`` generator creates a file named ``conan_paths.cmake`` declaring: - ``CMAKE_MODULE_PATH`` with the folders of the required packages, to allow CMake to locate the included cmake scripts and ``FindXXX.cmake`` files. The folder containing the ``conan_paths.cmake`` (`self.install_folder` when used in a recipe) is also included, so any custom file will be located too. Check :ref:`cmake_find_package ` generator. - ``CMAKE_PREFIX_PATH`` used by ``FIND_LIBRARY()`` to locate library files (.a, .lib, .so, .dll) in your packages. .. code-block:: text :caption: conanfile.txt [requires] zlib/1.2.11@conan/stable ... [generators] cmake_paths .. code-block:: cmake :emphasize-lines: 4 :caption: CMakeList.txt cmake_minimum_required(VERSION 3.0) project(helloworld) add_executable(helloworld hello.c) find_package(Zlib) if(ZLIB_FOUND) include_directories(${ZLIB_INCLUDE_DIRS}) target_link_libraries (helloworld ${ZLIB_LIBRARIES}) endif() In the example above, the ``zlib/1.2.11@conan/stable`` package is not packaging a custom ``FindZLIB.cmake`` file, but the ``FindZLIB.cmake`` included in the CMake installation directory (`/Modules`) will locate the zlib library from the Conan package because of the ``CMAKE_PREFIX_PATH`` used by the ``FIND_LIBRARY()``. If the ``zlib/1.2.11@conan/stable`` would had included a custom ``FindZLIB.cmake`` in the package root folder or any declared :ref:`self.cpp_info.builddirs `, it would have been located because of the ``CMAKE_MODULE_PATH`` variable. You can use the generated ``conan_paths.cmake`` file as a **cmake toolchain** or including it in a **CMakeLists.txt** of even including it in another toolchain: Included as a toolchain ----------------------- Without modifying your **CMakeLists.txt** file you can use the ``conan_paths.cmake`` as a toolchain: .. code-block:: bash :emphasize-lines: 3 $ mkdir build && cd build $ conan install .. $ cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_paths.cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release $ cmake --build . Included using the CMAKE_PROJECT__INCLUDE ------------------------------------------------------- With ``CMAKE_PROJECT__INCLUDE`` you can specify a file to be included by the project() command. If you already have a toolchain file you can use this variable to include the ``conan_paths.cmake`` and insert your toolchain with the ``CMAKE_TOOLCHAIN_FILE``. .. code-block:: bash $ mkdir build && cd build $ conan install .. $ cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_PROJECT_helloworld_INCLUDE=build/conan_paths.cmake $ cmake --build . Included in your CMakeLists.txt ------------------------------- .. code-block:: cmake :emphasize-lines: 3 :caption: CMakeList.txt cmake_minimum_required(VERSION 3.0) project(helloworld) include(${CMAKE_BINARY_DIR}/conan_paths.cmake) add_executable(helloworld hello.c) find_package(Zlib) if(ZLIB_FOUND) include_directories(${ZLIB_INCLUDE_DIRS}) target_link_libraries (helloworld ${ZLIB_LIBRARIES}) endif() .. code-block:: bash $ mkdir build && cd build $ conan install .. $ cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release $ cmake --build . .. seealso:: Check the section :ref:`Reference/Generators/cmake_paths ` to read more about this generator. .. note:: The ``CMAKE_MODULE_PATH`` and ``CMAKE_PREFIX_PATH`` contain the paths to the ``builddirs`` of every required package. By default, the root package folder is the only declared ``builddirs`` directory. Check the :ref:`Reference/conanfile.py/attributes `.