MakeDeps

Warning

This feature is experimental and subject to breaking changes. See the Conan stability section for more information.

MakeDeps is the dependencies generator for make. It generates a Makefile file named conandeps.mk containing a valid make file syntax with all dependencies listed, including their components.

This generator can be used by name in conanfiles:

conanfile.py

  1. class Pkg(ConanFile):
  2. generators = "MakeDeps"

conanfile.txt

  1. [generators]
  2. MakeDeps

And it can also be fully instantiated in the conanfile generate() method:

  1. from conan import ConanFile
  2. from conan.tools.gnu import MakeDeps
  3. class App(ConanFile):
  4. settings = "os", "arch", "compiler", "build_type"
  5. requires = "zlib/1.2.13"
  6. def generate(self):
  7. pc = MakeDeps(self)
  8. pc.generate()

Generated files

make format file named conandeps.mk, containing a valid makefile file syntax. The prefix variable is automatically adjusted to the package_folder:

  1. CONAN_DEPS = zlib
  2. # zlib/1.2.13
  3. CONAN_NAME_ZLIB = zlib
  4. CONAN_VERSION_ZLIB = 1.2.13
  5. CONAN_REFERENCE_ZLIB = zlib/1.2.13
  6. CONAN_ROOT_ZLIB = /home/conan/.conan2/p/b/zlib273508b343e8c/p
  7. CONAN_INCLUDE_DIRS_ZLIB = $(CONAN_INCLUDE_DIR_FLAG)$(CONAN_ROOT_ZLIB)/include
  8. CONAN_LIB_DIRS_ZLIB = $(CONAN_LIB_DIR_FLAG)$(CONAN_ROOT_ZLIB)/lib
  9. CONAN_BIN_DIRS_ZLIB = $(CONAN_BIN_DIR_FLAG)$(CONAN_ROOT_ZLIB)/bin
  10. CONAN_LIBS_ZLIB = $(CONAN_LIB_FLAG)z
  11. CONAN_INCLUDE_DIRS = $(CONAN_INCLUDE_DIRS_ZLIB)
  12. CONAN_LIB_DIRS = $(CONAN_LIB_DIRS_ZLIB)
  13. CONAN_BIN_DIRS = $(CONAN_BIN_DIRS_ZLIB)
  14. CONAN_LIBS = $(CONAN_LIBS_ZLIB)

Properties

Makefile variables will be generated for each property set in package_info() of all dependencies and their components. Let’s take following receipt:

  1. from conan import ConanFile
  2. class MyLib(ConanFile):
  3. name = "mylib"
  4. version = "1.0"
  5. def package_info(self):
  6. self.cpp_info.set_property("my.prop", "some vale")
  7. self.cpp_info.components["mycomp"].set_property("comp_prop", "comp_value")

The resulting makefile variable assignments would look like this:

  1. # mylib/1.0
  2. #[...]
  3. CONAN_PROPERTY_MYLIB_MY_PROP = some value
  4. CONAN_PROPERTY_MYLIB_MYCOMP_COMP_PROP = comp_value

When substituting package names, component names and property names into makefile variable names, the names are converted to uppercase and all characters except A-Z, 0-9 and _ are replaced with _ (see example above with a dot in the property name). The property value is not modified, it is put to the right side of the variable assignment literally. Any whitespace and special character remain unchagend, no quotation or escaping is applied, because GNU Make is not consistent in escaping spaces and cannot handle whitespaces in path names anyway. Because values with newlines would break the makefile they are skipped and a warning is displayed.

Customization

Flags

By default, the conandeps.mk will contain all dependencies listed, including their cpp_info information, but will not pass any flags to the compiler.

Thus, the consumer should pass the following flags to the compiler:

  • CONAN_LIB_FLAG: Add a prefix to all libs variables, e.g. -l

  • CONAN_DEFINE_FLAG: Add a prefix to all defines variables, e.g. -D

  • CONAN_SYSTEM_LIB_FLAG: Add a prefix to all system_libs variables, e.g. -l

  • CONAN_INCLUDE_DIR_FLAG: Add a prefix to all include dirs variables, e.g. -I

  • CONAN_LIB_DIR_FLAG: Add a prefix to all lib dirs variables, e.g. -L

  • CONAN_BIN_DIR_FLAG: Add a prefix to all bin dirs variables, e.g. -L

Those flags should be appended as prefixes to flags variables. For example, if the CONAN_LIB_FLAG is set to -l, the CONAN_LIBS variable will be set to -lz.

Reference

class MakeDeps(conanfile)

Generates a Makefile with the variables needed to build a project with the specified.

  • Parameters:

    conanfile< ConanFile object > The current recipe object. Always use self.

  • generate() → None

    Collects all dependencies and components, then, generating a Makefile