conan.tools.layout

Predefined layouts

There are some pre-defined common layouts, ready to be simply used in recipes:

The pre-defined layouts define the Conanfile .folders and .cpp attributes with typical values. To check which values are set by these pre-defined layouts please check the reference for the layout() method. For example in the cmake_layout() the source folder is set to ".", meaning that Conan will expect the sources in the same directory where the conanfile is (most likely the project root, where a CMakeLists.txt file will be typically found). If you have a different folder where the CMakeLists.txt is located, you can use the src_folder argument:

  1. from conan.tools.cmake import cmake_layout
  2. def layout(self):
  3. cmake_layout(self, src_folder="mysrcfolder")

Even if this pre-defined layout doesn’t suit your specific projects layout, checking how they implement their logic shows how you could implement your own logic (and probably put it in a common python_require if you are going to use it in multiple packages).

To learn more about the layouts and how to use them while developing packages, please check the Conan package layout tutorial.

basic_layout

Usage:

  1. from conan.tools.layout import basic_layout
  2. def layout(self):
  3. basic_layout(self)

The current layout implementation is very simple, basically sets a different build folder for different build_types and sets the generators output folder inside the build folder. This way we avoid to clutter our project while working locally.

  1. def basic_layout(conanfile, src_folder="."):
  2. conanfile.folders.build = "build"
  3. if conanfile.settings.get_safe("build_type"):
  4. conanfile.folders.build += "-{}".format(str(conanfile.settings.build_type).lower())
  5. conanfile.folders.generators = os.path.join(conanfile.folders.build, "conan")
  6. conanfile.cpp.build.bindirs = ["."]
  7. conanfile.cpp.build.libdirs = ["."]
  8. conanfile.folders.source = src_folder