Make

Warning

This integration is to be deprecated in Conan 2.0. Check the conan.tools.gnu Autotools integration.

Conan provides the Make generator to integrate with plain Makefiles

The make generator outputs all the variables related to package dependencies into a file which is named conanbuildinfo.mak. The make toolchain outputs all the variables related to settings, options, and platform into a file which is named conan_toolchain.mak.

To use the generator, indicate it in your conanfile like this:

conanfile.txt
 [generators]
 make
conanfile.py
 class MyConan(ConanFile):
     ...
     generators = "make"

Example

We are going to use the same example from Getting Started, a MD5 hash calculator app.

This is the main source file for it:

main.cpp
 #include "Poco/MD5Engine.h"
 #include "Poco/DigestStream.h"

 #include <iostream>


 int main(int argc, char** argv)
 {
     Poco::MD5Engine md5;
     Poco::DigestOutputStream ds(md5);
     ds << "abcdefghijklmnopqrstuvwxyz";
     ds.close();
     std::cout << Poco::DigestEngine::digestToHex(md5.digest()) << std::endl;
     return 0;
 }

In order to use this generator within your project, use the following Makefile as a reference:

Makefile
 #----------------------------------------
 #     Prepare flags from make generator
 #----------------------------------------

 include conanbuildinfo.mak
 $(call CONAN_BASIC_SETUP)

 #----------------------------------------
 #     Make variables for a sample App
 #----------------------------------------

 SRCS          = main.cpp
 OBJS          = main.o
 EXE_FILENAME  = main

 #----------------------------------------
 #     Make Rules
 #----------------------------------------

 .PHONY                  :   exe
 exe                     :   $(EXE_FILENAME)

 $(EXE_FILENAME)         :   $(OBJS)
     g++ $(OBJS) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -o $(EXE_FILENAME)

 %.o                     :   $(SRCS)
     g++ -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

Now we are going to let Conan retrieve the dependencies, generate the dependency information in the file conanbuildinfo.mak, and generate the options and settings information in the file conan_toolchain.mak:

$ conan install .

Then let’s call make to generate our project:

$ make exe

Now you can run your application with ./main.

See also

Complete reference for Make generator