|
| 1 | +.. _make: |
| 2 | + |
| 3 | +Make |
| 4 | +==== |
| 5 | + |
| 6 | +Conan provides integration with plain Makefiles by means of the ``make`` generator. If you are using ``Makefile`` to build your project you |
| 7 | +could get the information of the dependencies in a *conanbuildinfo.mak* file. All you have to do is indicate the generator like this: |
| 8 | + |
| 9 | +.. code-block:: text |
| 10 | + :caption: *conanfile.txt* |
| 11 | +
|
| 12 | + [generators] |
| 13 | + make |
| 14 | +
|
| 15 | +.. code-block:: text |
| 16 | + :caption: *conanfile.py* |
| 17 | +
|
| 18 | + class MyConan(ConanFile): |
| 19 | + ... |
| 20 | + generators = "make" |
| 21 | +
|
| 22 | +Example |
| 23 | +------- |
| 24 | + |
| 25 | +We are going to use the same example from :ref:`getting_started`, a MD5 Encrypter app. |
| 26 | + |
| 27 | +This is the main file for it: |
| 28 | + |
| 29 | +.. code-block:: cpp |
| 30 | + :caption: main.cpp |
| 31 | +
|
| 32 | + #include "Poco/MD5Engine.h" |
| 33 | + #include "Poco/DigestStream.h" |
| 34 | +
|
| 35 | + #include <iostream> |
| 36 | +
|
| 37 | +
|
| 38 | + int main(int argc, char** argv) |
| 39 | + { |
| 40 | + Poco::MD5Engine md5; |
| 41 | + Poco::DigestOutputStream ds(md5); |
| 42 | + ds << "abcdefghijklmnopqrstuvwxyz"; |
| 43 | + ds.close(); |
| 44 | + std::cout << Poco::DigestEngine::digestToHex(md5.digest()) << std::endl; |
| 45 | + return 0; |
| 46 | + } |
| 47 | +
|
| 48 | +As this project relies on the Poco Libraries we are going to create a *conanfile.txt* with our requirement and declare there the Make |
| 49 | +generator too: |
| 50 | + |
| 51 | +.. code-block:: text |
| 52 | + :caption: conanfile.txt |
| 53 | +
|
| 54 | + [requires] |
| 55 | + Poco/1.9.0@pocoproject/stable |
| 56 | +
|
| 57 | + [generators] |
| 58 | + make |
| 59 | +
|
| 60 | +In order to use this generator within your project, use the following Makefile as a reference: |
| 61 | + |
| 62 | +.. code-block:: makefile |
| 63 | + :caption: Makefile |
| 64 | +
|
| 65 | + include conanbuildinfo.mak |
| 66 | +
|
| 67 | + #---------------------------------------- |
| 68 | + # Make variables for a sample App |
| 69 | + #---------------------------------------- |
| 70 | +
|
| 71 | + CXX_SRCS = \ |
| 72 | + main.cpp |
| 73 | +
|
| 74 | + CXX_OBJ_FILES = \ |
| 75 | + main.o |
| 76 | +
|
| 77 | + EXE_FILENAME = \ |
| 78 | + main |
| 79 | +
|
| 80 | +
|
| 81 | + #---------------------------------------- |
| 82 | + # Prepare flags from variables |
| 83 | + #---------------------------------------- |
| 84 | +
|
| 85 | + CFLAGS += $(CONAN_CFLAGS) |
| 86 | + CXXFLAGS += $(CONAN_CPPFLAGS) |
| 87 | + CPPFLAGS += $(addprefix -I, $(CONAN_INCLUDE_PATHS)) |
| 88 | + CPPFLAGS += $(addprefix -D, $(CONAN_DEFINES)) |
| 89 | + LDFLAGS += $(addprefix -L, $(CONAN_LIB_PATHS)) |
| 90 | + LDLIBS += $(addprefix -l, $(CONAN_LIBS)) |
| 91 | +
|
| 92 | +
|
| 93 | + #---------------------------------------- |
| 94 | + # Make Commands |
| 95 | + #---------------------------------------- |
| 96 | +
|
| 97 | + COMPILE_CXX_COMMAND ?= \ |
| 98 | + g++ -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ |
| 99 | +
|
| 100 | + CREATE_EXE_COMMAND ?= \ |
| 101 | + g++ $(CXX_OBJ_FILES) \ |
| 102 | + $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) \ |
| 103 | + -o $(EXE_FILENAME) |
| 104 | +
|
| 105 | +
|
| 106 | + #---------------------------------------- |
| 107 | + # Make Rules |
| 108 | + #---------------------------------------- |
| 109 | +
|
| 110 | + .PHONY : exe |
| 111 | + exe : $(EXE_FILENAME) |
| 112 | +
|
| 113 | + $(EXE_FILENAME) : $(CXX_OBJ_FILES) |
| 114 | + $(CREATE_EXE_COMMAND) |
| 115 | +
|
| 116 | + %.o : $(CXX_SRCS) |
| 117 | + $(COMPILE_CXX_COMMAND) |
| 118 | +
|
| 119 | +Now we are going to let Conan retrieve the dependencies and generate the dependency information in a *conanbuildinfo.mak*: |
| 120 | + |
| 121 | +.. code-block:: bash |
| 122 | +
|
| 123 | + $ conan install . |
| 124 | +
|
| 125 | +Then let's call :command:`make` to generate our project: |
| 126 | + |
| 127 | +- Use this command for Windows Visual Studio: |
| 128 | + |
| 129 | + .. code-block:: bash |
| 130 | +
|
| 131 | + $ make exe |
| 132 | +
|
| 133 | +Now you can run your application with ``./main``. |
| 134 | + |
| 135 | +.. seealso:: |
| 136 | + |
| 137 | + Check the complete reference of the :ref:`Make generator<make_generator>`. |
0 commit comments