Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
141 lines (82 sloc) 4.19 KB

Advanced build configuration

Apart from all the building with CMake tips available in :ref:`custom build configuration guide<building>`, there's also a few things that may come in handy while using biicode with CMake.

Publish, share and reuse CMake scripts

Now, biicode lets you publish, share and reuse CMake scripts. You can reuse other user's CMake macros/functions and apply any content in your CMakeLists.txt.

Reusing CMake code is as simple as #including libraries in C++ with biicode.

Edit your CMakeLists.txt file and include the CMake file from the block that you want:

INCLUDE(user/block/path_to_macros_file) # Without .cmake extension
MACRO_NAME_TO_USE() # Macro defined in My_macros.cmake

# Actually create targets: EXEcutables and libraries.
ADD_BII_TARGETS()

And run bii find command:

$ bii find

All CMake dependencies will be downloaded into your project/deps/user/block folder

EXAMPLE: How to activate C++11 with a macro already programmed?

biicode featured user has a block named cmake where you can find useful macros from the tools.cmake file, like one to activate C++11 flags for any OS, or to link a OSX framework to a target, etc.

Just edit your CMakeLists.txt file, include INCLUDE(biicode/cmake/tools) and use the Macros.

CMakeLists.txt

# Including tools.cmake from biicode/cmake user block
# see https://www.biicode.com/biicode/cmake
INCLUDE(biicode/cmake/tools)

ADD_BII_TARGETS()

# Calling specific macro to activate c++11 flags
ACTIVATE_CPP11(INTERFACE ${BII_BLOCK_TARGET})

Remember to run bii find to download the dependency.

$ bii find

Overriding dependencies build options and configuration

Sometimes you need to override some configuration of how your dependency libraries are built.

This is the project layout when you have dependencies:

|-- my_project
|    +-- blocks
|    |    +-- my_user
|    |    |    +-- my_block
|    |    |    |    +-- biicode.conf
|    |    |    |    +-- CMakeLists.txt
|    |    |    |    +-- main.cpp
|    +-- deps
|    |    +-- lasote
|    |    |    +-- superlibrary
|    |    |    |    +-- biicode.conf
|    |    |    |    +-- CMakeLists.txt
|    |    |    |    +-- library.h
|    |    |    |    +-- library.cpp
|    |    +-- sara
|    |    |    +-- coollibrary
|    |    |    |    +-- biicode.conf
|    |    |    |    +-- CMakeLists.txt
|    |    |    |    +-- tool.h
|    |    |    |    +-- tool.cpp

You should not edit the source code in deps directory because it will be overwritten by biicode. As can't change the CMakeLists.txt files of our dependencies directly, here's a way to override their build configuration.

How does it work?

Create a file named bii_deps_config.cmake in your block (my_user/my_block/) and write into it the CMake code you need.

You can act upon dependency target following this naming rule:

[USER]_[BLOCK]_interface

For example, if we have lasote/superlibrary block as a dependency, we can refer to it using this interface name:

lasote_superlibrary_interface
  • EXAMPLE: Activate C++ 11 in the dependency lasote/superlibrary block:
target_compile_options(lasote_superlibrary_interface INTERFACE -std=c++11)
  • EXAMPLE: Change a compilation option:
SET(MY_OPTION OFF CACHE BOOL "MyCoolOption" FORCE)

We are available at biicode's forum for any issues. You can also write us for suggestions and feedback.