Biicode-logo
  • Explore
  • Plans
  • Learn
    • Get Started
    • Downloads
    • Docs
    • Blog
    • Forum
  • Log in
C/C++ Arduino Raspberry Pi (cross compiling) Node.js
  • Biicode
    • Installation
      • Install Biicode
      • Install C/C++ tools
      • Debian based distributions
      • Arch based distributions
      • Run biicode from source
      • Install C/C++ tools manually
        • Verify your installation
      • Connect through a proxy server
    • Getting started
      • Basics
      • Create your first project
        • [optional] Keeping #includes short
      • Using an IDE
      • Build and run
      • Publishing
    • Dependencies
      • Dependencies
      • Modifying the version you depend on
        • Depending on a block track
    • Publishing
      • Tag a version
      • Private blocks
    • Custom build configuration
      • CMake basics
      • Where is biicode´s “magic”?
      • Define and prepare targets
        • Which source code files are part of the block’s library
        • Choose STATIC or SHARED library
        • Modify which executable targets are made
        • Which source code files are part of each executable
        • Modify which test targets are made
      • Configure targets
        • Configure library target
        • Configure executable target
      • Select build type: Debug or Release
      • Complete variable reference
    • Adapt your library
      • Concepts to understand
        • Key facts
      • Without a previous CMakeLists.txt
        • 1. Look for unresolved dependencies with bii deps
        • 2. Execute bii build
        • 3. Test the libary’s reusability
      • With a previous CMakeLists.txt
        • Option 1: Let biicode do its job in an isolated file
        • Option 2: Build your own target library and link them to BII_LIB_TARGET
        • Option 3: Adapt your CMakeLists.txt filtering files
    • Advanced Usage
      • Custom Layouts
        • Simple Layout
        • TMP Layout
        • Classic Layout
        • CLion Layout
      • Tests
      • Open multiple blocks
        • Working with your own blocks
        • Opening your block
        • Publishing updated code
        • Closing edited block
        • Working with any published block
        • Open a block
        • Publish the changes
        • Close the block
        • Depend on the block you’ve just published
      • Toolchains
      • Override a dependency
        • Override a dependency with block tracks
      • Advanced build configuration
        • Publish, share and reuse CMake scripts
        • Overriding dependencies build options and configuration
      • Publish a block track
        • Publish a new block Track
      • Private blocks
    • Examples
      • Basic Compression Library
        • Simple Huffman Compression - Uncompression
        • Open and build
      • Boost Libraries
        • Boost.Lambda
        • Boost.Coroutine
        • Alternative setup call
        • Extra configuration variables
        • Contribute to the setup scripts
      • Box2D
        • Bounces of a circle falling
        • Open and build
      • C++ challenge
        • Create a new project
        • Copy the code
        • Find and retrieve dependencies
        • Build and run
      • CImg
        • Tron game
        • Open and build
      • Crypto++
        • Encrypt a message
        • Open and build
      • CSparse
        • Read a matrix and solve a linear system
        • Create a new project
        • Open and build
      • cURL
        • HTML page gatherer
        • Open and build
      • Eigen
        • Middle rows from a matrix
        • Open and build
      • Expression Parser
        • Simple form of mathematical expression parsing
        • Open and build
      • fit
        • Tests
      • Flatbuffers
        • Charge a *.fbs file and generate a C++ header
      • Freeglut
        • 1. Create a new project
        • 2. Creating reusable code
        • 3. Find dependencies
        • 4. Build and run
      • GLFW
        • Running the examples
      • GLUI User Interface Library
        • GLUI Window Template
      • Google Mock (GMock)
        • GMock Examples
        • Mocking a simple function
      • Google Test (GTest)
        • Testing a factorial function: Simple test
        • Testing a factorial function: Test suites
        • Open and build
      • HTTP Server
        • How does it work?
        • How can I use it?
        • The code
        • Supported Operating Systems
        • More information
        • List of dependencies
      • json11
        • Simple convert data to json and vice versa
      • json++
        • Simple parser and converter from JSON to XML
      • Miniutf
      • Multivariate Splines
      • libuv
        • Http client/server application
        • Change libuv’s version
      • Little CMS
        • ICC Profile Examples
        • Open and build
      • Log4z
        • Fast stream log strings test
      • lwan Web Server
        • Hello World Example
      • MiLi
      • MuParser
      • OpenCV
        • Showing an image and detecting faces
        • Open and build
      • OpenSSL
        • Encrypting with MD5 and SHA1
        • Develop your project
        • Open and build
      • POCO
        • PDF example
        • Using NetSSL_OpenSSL or NetSSL_Win library
      • PTypes
      • SDL
        • Graphical window interface
        • Open and build
      • SQLite
        • Shopping list database
        • SQLite++ Wrapper
        • Open and build
      • TinyThread++
        • Open and build the examples
        • Simple Hello World with a thread
        • Draw a fractal
      • Zlib
        • Usage example (difficulty: medium)
      • ZMQ
        • Simple client-server with C++ binding
      • ZMQ with Google Protocol Buffers Serialization
    • Integrations
      • Generators and IDEs
        • Eclipse CDT
        • Visual Studio
        • CLion
      • IDEs and VCS
      • Git (GitHub, Bitbucket, etc.)
        • With a new repository
        • Create a block from a git repository
        • Publish from git commit
      • Continuous Integration
        • AppVeyor
        • Travis CI
      • Koding
      • Doxygen
        • Create a Doxyfile template
        • Edit your Doxyfile
        • Generate the Documentation
    • Reference
      • biicode.conf: configure your biicode projects
        • [requirements]
        • [parent]
        • [paths]
        • [dependencies]
        • [mains]
        • [tests]
        • [hooks]
        • [includes]
        • [data]
      • Commands
        • bii build: build your project
        • bii buzz: init, find and build
        • bii clean: delete meta-information
        • bii close: finish editing published blocks
        • bii configure: configure your project
        • bii deps: show block dependencies
        • bii diff: compare block versions
        • bii find: find your external dependencies
        • bii init: creates a new project
        • bii new: creates new blocks
        • bii open: edit published blocks
        • bii publish: publish your blocks
        • bii setup: install necessary tools
        • bii test: test your code
        • bii update: update a block
        • bii user: specify your username
      • Configuration Files
        • layout.bii: define your project layout
        • policies.bii: defining the policies for the code you want to reuse
        • ignore.bii: filtering your files
        • settings.bii: defining your tools and preferences
        • types.bii: configuring non-standard file extensions
    • Release notes
    • FAQs
      • Is biicode free?
      • Is biicode an editor in the cloud?
      • Is biicode a VCS?
      • Can I use biicode with my favourite VCS?
      • Which languages are supported?
      • How does biicode relate to Maven, NPM, PyPI...?
    • Troubleshooting
      • Eclipse projects: “Launch failed. Binary not found” (OS X)
      • g++ doesn’t compile simple code, using thread header
      • Default Build Configuration with bii build not working
  • Arduino
    • Installation
      • Install Biicode
      • Install Arduino tools
      • Install Arduino tools manually
        • Install Arduino SDK manually
    • Getting started
      • Installing biicode and Arduino tools
      • Create your project
      • Define your board
      • Build and upload your program
      • Depending on Fenix Blink
      • Build and upload
    • Arduino commands
      • bii configure -t arduino: configure your project
      • bii build: build your project
      • bii arduino:upload: send your code into the Arduino
      • bii arduino:settings: configure your Arduino settings
      • bii arduino:monitor: start a serial monitor
      • bii configure –toolchain=arduino: enable, disable or change the Arduino cross compilation
    • How to
      • Eclipse IDE configuration
        • How to import your project
        • How to fix “Unresolved inclusion: Arduino.h”
      • Configure your SDK, port and board
        • I changed my Arduino’s port, what happens now?
        • How can I change my Arduino project properties?
        • bii arduino:settings options
      • How to adapt your code
        • 1. Projects with one single .ino file
        • 2. Projects with multiple .ino files
      • How to use the Arduino Yun
        • Download Arduino 1.5
        • Configure your settings
    • Examples
      • Arduino Serial Monitor
        • C++ code
        • Turn ON/OFF one LED
      • Servo and LCD 2x16
        • What do we need?
        • Scheme
        • The code: Display the servo angle into a LCD
        • Build and upload the code
      • Arduino Serial Interface
        • How does it work?
        • How do I use it?
        • C++ code
        • Arduino code
        • Build and run!
    • Troubleshooting
      • Launching Arduino IDE, I get an error ./arduino: 22: ./arduino: java: not found in Ubuntu
  • Raspberry Pi Cross Compilation
    • Installation
      • Install Biicode
      • Install RPI tools
      • Install RPI cross-compiling tools manually
        • C++ tools installation
        • Raspberry Pi tools installation
    • Getting started
      • 1. Installing biicode and C/C++ cross-building tools
      • 2. Create your project
      • 3. Build and run your program (cross-compiling)
      • 4. Send your executable to your Raspberry Pi
      • 5. Depending on WiringPi
    • RPi commands
      • bii rpi:send: send a bin folder
      • bii rpi:settings: configure your Raspberry Pi settings
      • bii rpi:ssh: connect by ssh with the Raspberry Pi
      • bii configure –toolchain=rpi: enable, disable or change the Raspberry Pi cross compilation.
    • How to
      • Installing the biicode package from downloads page is too slow
      • Output selection and volume control
      • Raspberry Pi GPIO Pin Layout
    • Examples
      • WiringPi: C GPIO library
        • How to make a LED blink with Raspberry Pi
        • How to use the RPi PWM output to control a motor
        • How to use softServo to control a Servo
      • HTTP Server: how to control a led by web
        • How can i use it?
      • A funny moving doll with Raspberry PI and biicode
        • You just need paper, scissors, a servo, a Raspberry Pi and biicode!
        • Choose the paper doll you like most
        • Putting it all together!
        • Stick the head to the servo and put the servo in the body
        • Connect the servo to the 5v, GPIO17 and 0v pins
    • Troubleshooting
      • Is it possible to change the version of gcc used for cross-compiling to the Raspberry Pi?
  • Node.js
    • Getting started
      • 1. Installing biicode and node.js
      • 2. Create your project
      • 3. Run your program
      • 4. Depending on redis
    • How to
      • Run your node programs
  • biicode docs
  • Biicode
  • Custom build configuration
  • Where is biicode´s “magic”?
  • Edit on GitHub
CMake basics
Adapt your library

Where is biicode´s “magic”?¶

bii configure or bii build commands generate a CMakeLists.txt file in each block.

CMakeLists.txt has 1 line by default (stripping out comments):

ADD_BII_TARGETS()

So biicode:

  • Detects how source code files are connected and builds a dependency graph (following #includes and searching for implementations).
  • Generates, for each block, a CMakeLists.txt defining some variables according to the dependency graph detected. These variables allow Biicode to “plug” your library to its cloud so it is easily reused.
  • Builds a library for each block you have in your project (including each dependency).
  • Builds an executable for each file with a main() function.
  • Link the block’s library to all executables within the block.
  • Builds the block’s library only with the source code files needed, according to the dependencies detected (how files are connected).

Define and prepare targets¶

In the CMakeLists.txt file, before ADD_BII_TARGETS() you can adjust:

Which source code files are part of the block’s library¶

BII_LIB_SRC contains all the source code biicode adds to the library (through CMake add_library)

EXAMPLE: Exclude my_file.cpp from being compiled in the block’s library.

# Remove my_file.cpp from being compiled in library
LIST(REMOVE_ITEM BII_LIB_SRC my_file.cpp)

ADD_BII_TARGETS()

EXAMPLE: Include other_file.cpp to be compiled in the block library.

# Include my_file.cpp to be compiled in library
LIST(APPEND BII_LIB_SRC other_file.cpp)

ADD_BII_TARGETS()
ESSENTIAL TIP: If biicode did not add a file needed to your block’s library, you could specify this dependency in the [dependencies] section of the biicode.conf file. Why? This way you wire the dependency (fixing the dependency graph). If someone depends on your library, biicode will also download the missing file and will add it to BII_LIB_SRC automatically. Otherwise file won’t be downloadedm and their build will fail.

Choose STATIC or SHARED library¶

BII_LIB_TYPE value is empty by default (turns out it is STATIC in most cases). It can be either STATIC or SHARED.

EXAMPLE: Making a shared library (.dll, .so):

SET(BII_LIB_TYPE SHARED)

ADD_BII_TARGETS()

Modify which executable targets are made¶

BII_BLOCK_EXES List of executable targets (mains). Each “exe” matches this pattern: path_to_mainfile.

For example, if the block lasote/game has a main.cpp in a folder named “src”, the variable has an element: “src_main”

EXAMPLE: Prevent biicode from creating an EXE target for (examples/src/my_program.cpp):

LIST(REMOVE_ITEM BII_BLOCK_EXES examples_src_my_program)

ADD_BII_TARGETS()
You can also do this by adding !examples_src_my_program line to [mains] section of biicode.conf.

Which source code files are part of each executable¶

BII_exe_name_SRC contains all source code that will be added to the exe. “exe_name” matches this pattern: path_to_mainfile.

For example, if the block lasote/game has a main.cpp in a folder named “src” the variable is: “BII_src_main_SRC“

EXAMPLE: Exclude my_file.cpp from being compiled with examples/main.cpp executable.

LIST(REMOVE_ITEM BII_examples_main_SRC my_file.cpp)

ADD_BII_TARGETS()

Modify which test targets are made¶

BII_BLOCK_TESTS is a subset of BII_BLOCK_EXES and contains the executables specified in [tests] section of biicode.conf file.

EXAMPLE: Exclude tests/one.cpp from tests.

LIST(REMOVE_ITEM BII_BLOCK_TESTS tests_one)

ADD_BII_TARGETS()

Configure targets¶

Once we have selected which files belong to each target and the targets we want, we are ready to call ADD_BII_TARGETS().

ADD_BII_TARGETS() generates the block’s library target and a target for each executable.

Configure library target¶

BII_LIB_TARGET contains the name of the block’s library target. This target may be an INTERFACE target (no source files) if BII_LIB_SRC is empty before ADD_BIICODE_TARGETS call. For this reason we recommend you to always use BII_BLOCK_TARGET.

BII_BLOCK_TARGET: Use this better, instead of BII_LIB_TARGET. Created to ease target configuration. It always exists and it is always a CMake Interface. Represents the whole block, and it is applied to BII_LIB_TARGET and each target executable.

EXAMPLE: Linking with pthread.

# Link against the always existing BII_BLOCK_TARGET
TARGET_LINK_LIBRARIES(${BII_BLOCK_TARGET} INTERFACE pthread)
# or link against the library (if it's not an interface we specify PUBLIC attribute to propagate the configuration)
TARGET_LINK_LIBRARIES(${BII_LIB_TARGET} PUBLIC pthread)
You can also do this by adding pthread to ${BII_LIB_DEPS} before calling ADD_BII_TARGETS()

EXAMPLE: Adding include directories to all targets of this block.

TARGET_INCLUDE_DIRECTORIES(${BII_BLOCK_TARGET} INTERFACE myincludedir)

# You can also add private include directories to the Lib (if existing)
TARGET_INCLUDE_DIRECTORIES(${BII_LIB_TARGET} PRIVATE myincludedir)
You can also do this by adding myincludedir line to [paths] section of biicode.conf.

EXAMPLE: How to activate C++11 for all targets (including lib target).

IF(APPLE)
   TARGET_COMPILE_OPTIONS(${BII_BLOCK_TARGET} INTERFACE "-std=c++11 -stdlib=libc++")
ELSEIF (WIN32 OR UNIX)
   TARGET_COMPILE_OPTIONS(${BII_BLOCK_TARGET} INTERFACE "-std=c++11")
ENDIF(APPLE)

EXAMPLE: Adding compile definitions to all targets (including lib target).

TARGET_COMPILE_DEFINITIONS(${BII_BLOCK_TARGET} PUBLIC "MY_DEFINITION=1")

EXAMPLE: Setting properties to lib target.

SET_TARGET_PROPERTIES(${BII_LIB_TARGET} PROPERTIES COMPILE_DEFINITIONS "IOV_MAX=255")
SET_TARGET_PROPERTIES only allows setting some white-listed properties to BII_BLOCK_TARGET, because it is an interface. Use BII_LIB_TARGET to set target properties.

Configure executable target¶

BII_exe_name_TARGET contains the name of the target for each executable target. Each “exe” matches this pattern: path_to_mainfile.

EXAMPLE: Linking pthread to an executable target (file: examples/one.cpp):

TARGET_LINK_LIBRARIES(${BII_examples_one_TARGET} PUBLIC pthread)

EXAMPLE: Adding compile definitions to an executable target (file: my_main.cpp).

TARGET_COMPILE_DEFINITIONS(${BII_my_main_TARGET} PUBLIC "MY_DEFINITION=1")

When someone depends on your library, biicode only downloads the required files (according to the dependency graph). So you can not assume that ${BII_my_main_TARGET} target will exist. It may seem obvious, but if you reference a target that doesn’t exist build fails. When possible it’s better to not act upon EXE targets. Remember that BII_BLOCK_TARGET will be applied to each target in your block.

It is best to act upon BII_BLOCK_TARGET.

Select build type: Debug or Release¶

You can set the build type with -D option in bii configure command:

$ bii configure -DCMAKE_BUILD_TYPE=DEBUG
$ bii build

Possible values are: DEBUG, RELEASE, RELWITHDEBINFO, MINSIZEREL

Check official docs from CMake Build Type.

If you are using Visual Studio or any other IDE with a select list box for build type use:

$ bii build --config=DEBUG
Use bii clean command to restore most of your project’s meta-information. Here’s more about bii clean command.

Complete variable reference¶

Sorted according to their specific use before or after ADD_BII_TARGETS() variable:

BII_LIB_SRC:List of files belonging to the library.
BII_LIB_TYPE:Empty by default, (STATIC in most cases) STATIC or SHARED.
BII_LIB_DEPS:Dependencies to other libraries (user2_block2, user3_blockX).
BII_LIB_SYSTEM_HEADERS:
 System linking requirements as windows.h, pthread.h, etc.
BII_LIB_INCLUDE_PATHS:
 List of directories that the library target will include through a call to TARGET_INCLUDE_DIRECTORIES
BII_BLOCK_EXES:List of targets that represent the executables (mains) defined in this block. If you want to prevent biicode from creating an EXE target, first remove it from this list.
BII_exe_name_SRC:
 List of files belonging to an “exe”. “exe_name” matches this pattern: path_to_mainfile. For example, if the block lasote/game has a main.cpp in a folder named “src” the variable will be: BII_src_main_SRC
BII_exe_name_DEPS:
 Dependencies of this “exe” target to other libraries, including its own block library if any (user2_block2, user3_blockX).
BII_BLOCK_TESTS:
 List of executables specified in [tests] section of biicode.conf file. Will be excluded from bii build compilation and compiled with bii test command. add_test
ADD_BII_TARGETS()
BII_LIB_TARGET:Target library name, usually in the form “user_block”. It may not exist if BII_LIB_SRC is empty, so better use ${BII_BLOCK_TARGET} as a general rule.
BII_BLOCK_TARGET:
 CMake Interface that represents the whole block. It always exists and it’s applied both library and executables (each target). You can use it to configure a block’s building configuration: Link libraries, compile flags...etc
BII_BLOCK_TARGETS:
 List of all targets defined in the block
BII_exe_name_TARGET:
 Executable target (listed in ${BII_BLOCK_EXES}). e.g. ${BII_main_TARGET}. You can also use directly the name of the executable target (e.g. user_block_main)

Got any doubts? Ask in our forum or write us.

CMake basics
Adapt your library

© Copyright 2014, biicode.