Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make generator documentation #955

Merged
merged 7 commits into from Dec 3, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -23,6 +23,7 @@ packages can be consumed, created, and continuously deployed/tested with each, a
integrations/b2
integrations/qmake
integrations/premake
integrations/make
integrations/qbs
integrations/meson
integrations/docker
@@ -0,0 +1,137 @@
.. _make:

Make
====

Conan provides integration with plain Makefiles by means of the ``make`` generator. If you are using ``Makefile`` to build your project you
could get the information of the dependencies in a *conanbuildinfo.mak* file. All you have to do is indicate the generator like this:

.. code-block:: text
:caption: *conanfile.txt*

[generators]
make

.. code-block:: text
:caption: *conanfile.py*

class MyConan(ConanFile):
...
generators = "make"

Example
-------

We are going to use the same example from :ref:`getting_started`, a MD5 Encrypter app.

This is the main file for it:

.. code-block:: cpp
:caption: 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;
}

As this project relies on the Poco Libraries we are going to create a *conanfile.txt* with our requirement and declare there the Make
generator too:

.. code-block:: text
:caption: conanfile.txt

[requires]
Poco/1.9.0@pocoproject/stable

[generators]
make

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

.. code-block:: makefile
:caption: Makefile

include conanbuildinfo.mak

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

CXX_SRCS = \
main.cpp

CXX_OBJ_FILES = \
main.o

EXE_FILENAME = \
main


#----------------------------------------
# Prepare flags from variables
#----------------------------------------

CFLAGS += $(CONAN_CFLAGS)
CXXFLAGS += $(CONAN_CPPFLAGS)
CPPFLAGS += $(addprefix -I, $(CONAN_INCLUDE_PATHS))
CPPFLAGS += $(addprefix -D, $(CONAN_DEFINES))
LDFLAGS += $(addprefix -L, $(CONAN_LIB_PATHS))
LDLIBS += $(addprefix -l, $(CONAN_LIBS))


#----------------------------------------
# Make Commands
#----------------------------------------

COMPILE_CXX_COMMAND ?= \
g++ -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

CREATE_EXE_COMMAND ?= \
g++ $(CXX_OBJ_FILES) \
$(CXXFLAGS) $(LDFLAGS) $(LDLIBS) \
-o $(EXE_FILENAME)


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

.PHONY : exe
exe : $(EXE_FILENAME)

$(EXE_FILENAME) : $(CXX_OBJ_FILES)
$(CREATE_EXE_COMMAND)

%.o : $(CXX_SRCS)
$(COMPILE_CXX_COMMAND)

Now we are going to let Conan retrieve the dependencies and generate the dependency information in a *conanbuildinfo.mak*:

.. code-block:: bash
$ conan install .
Then let's call :command:`make` to generate our project:

- Use this command for Windows Visual Studio:

.. code-block:: bash
$ make exe
Now you can run your application with ``./main``.

.. seealso::

Check the complete reference of the :ref:`Make generator<make_generator>`.
@@ -36,3 +36,4 @@ Available generators:
generators/text
generators/json
generators/premake
generators/make
@@ -0,0 +1,101 @@
.. _make_generator:

make
====

.. container:: out_reference_box

This is the reference page for ``make`` generator.
Go to :ref:`Integrations/make<make>` if you want to learn how to integrate your project or recipes with make.

This generators creates a file named *conanbuildinfo.mak* with information of dependencies in different variables that can be used for your
make builds.

Variables
---------

Variables per package. The ``<PKG-NAME>`` placeholder is filled with the name of the Conan package.

+--------------------------------------+-------------------------------------------------------------------------+
| NAME | VALUE |
+======================================+=========================================================================+
| CONAN_ROOT_<PKG-NAME> | Absolute path to root package folder |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_SYSROOT_<PKG-NAME> | System root folder |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_INCLUDE_PATHS_<PKG-NAME> | Headers folders |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_LIB_PATHS_<PKG-NAME> | Library folders |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_BIN_PATHS_<PKG-NAME> | Binary folders |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_BUILD_PATHS_<PKG-NAME> | Build folders |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_RES_PATHS_<PKG-NAME> | Resources folders |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_LIBS_<PKG-NAME> | Library names to link with |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_DEFINES_<PKG-NAME> | Library definitions |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_CFLAGS_<PKG-NAME> | Options for the C compiler (-g, -s, -m64, -m32, -fPIC) |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_CPPFLAGS_<PKG-NAME> | Options for the C++ compiler (-g, -s, -stdlib, -m64, -m32, -fPIC, -std) |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_SHAREDLINKFLAGS_<PKG-NAME> | Library Shared linker flags |
+--------------------------------------+-------------------------------------------------------------------------+
| CONAN_EXELINK_FLAGS_<PKG-NAME> | Executable linker flags |
+--------------------------------------+-------------------------------------------------------------------------+

Conan also declares some **global variables** with the aggregated values of all our requirements. The values are ordered in the right order
according to the dependency tree.

+--------------------------------+----------------------------------------------------------------------+
| NAME | VALUE |
+================================+======================================================================+
| CONAN_ROOTPATH | Aggregated root folders |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_SYSROOT | Aggregated system root folders |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_INCLUDE_PATHS | Aggregated header folders |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_LIB_PATHS | Aggregated library folders |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_BIN_PATHS | Aggregated binary folders |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_BUILD_PATHS | Aggregated build folders |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_RES_PATHS | Aggregated resource folders |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_LIBS | Aggregated library names to link with |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_DEFINES | Aggregated library definitions |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_CFLAGS | Aggregated options for the C compiler |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_CPPFLAGS | Aggregated options for the C++ compiler |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_SHAREDLINKFLAGS | Aggregated Shared linker flags |
+--------------------------------+----------------------------------------------------------------------+
| CONAN_EXELINKFLAGS | Aggregated Executable linker flags |
+--------------------------------+----------------------------------------------------------------------+

.. important::

Note that the mapping of the Conan variables to the Make ones is done taking the following rules into account and we suggest to use the
variables indicated under the *Makefile* column to apply to a common naming:

+--------------+----------------------+------------+
| ``cpp_info`` | *conanbuildinfo.mak* | *Makefile* |
+==============+======================+============+
| defines | CONAN_DEFINES | CPPFLAGS |
+--------------+----------------------+------------+
| includedirs | CONAN_INCLUDE_PATHS | CPPFLAGS |
+--------------+----------------------+------------+
| libdirs | CONAN_LIB_PATHS | LDFLAGS |
+--------------+----------------------+------------+
| libs | CONAN_LIBS | LDLIBS |
+--------------+----------------------+------------+
| cflags | CONAN_CFLAGS | CFLAGS |
+--------------+----------------------+------------+
| cppflags | CONAN_CPPFLAGS | CXXFLAGS |
+--------------+----------------------+------------+
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.