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
  • Adapt your library
  • Edit on GitHub
Where is biicode´s “magic”?
Advanced Usage

Adapt your library¶

Transforming your library in a full functional biicode block can be straightforward or require some work. The bigger or “heavier” a library is, the higher time it takes to adapt it.

We assume you’ve read Custom build configuration section and have understood how biicode builds your code.

Concepts to understand¶

  • Place your library’s source code in a biicode block.
  • Biicode analyzes your code and builds a dependency graph with how each file connects to the others. These files are appended to BII_LIB_SRC variable in your CMakeLists.txt file.
  • When you #include a header (ex: file.h) from a remote block, biicode only downloads the files that depend on “file.h” (recursively) and builds a library with the files needed. The dependency library built is linked to your targets automatically.
  • When you’re the one uploading a “reusable” library, it’s really important that the dependency graph for that lib is built correctly.
  • A quick way to be sure that your library is fully reusable, is publishing with DEV tag and then depend on it from another project making an example. The example can be a main including a header from your own library. You can check a lot of examples reusing libsS in examples user.

Key facts¶

As biicode may build the libraries with just a few files from the whole library (biicode only downloads and builds the needed files), you shouldn’t assume in your CMakeLists.txt that all your library files will be present.

> Example: Make sure an exe target exists before executing TARGET_LINK_LIBRARIES upon it.

> Example: Adding my_file.cpp to your library explicitly isn’t recommended as you don’t know if biicode has downloaded this file.

Biicode needs a library in BII_LIB_TARGET variable to make it reusable, as a “plug”.

It builds ${BII_LIB_TARGET} for each block with the source code files in BII_LIB_SRC variable (list).

Without a previous CMakeLists.txt¶

If your current library doesn’t have a CMakeLists.txt biicode creates it when you execute bii configure or bii build.

1. Look for unresolved dependencies with bii deps¶

  • If some of your header files (*.h) are unresolved, biicode has not been able to detect them. You can solve this by filling [paths] section in biicode.conf with the folders containing the headers to let biicode find them.

    You only need to specify your paths when your project has non-file-relative #include (s).

    For example:

    [paths]
        # Local directories to look for headers in your block
        include
        /
    
  • If there are references to external headers, look for the library you need in biicode. You can use the search engine in https://www.biicode.com and search for the file typing file:my_include.h

    • Found the library in biicode? Just fill your [requirements] of biicode.conf as shown in dependencies section. Re-run bii deps command to ensure the #includes are resolved.
    • Didn’t find the library in biicode? You could be the first one adding it ;)
  • If there are no unresolved dependencies or it seems your unresolved dependencies are system dependencies, try to compile it (point 2).

2. Execute bii build¶

  • There are compilation errors:

    • Check if some compile definition is needed. You can use TARGET_COMPILE_DEFINITIONS(${BII_BLOCK_TARGET} PUBLIC “MY_DEFINITION=1”) in your CMakeLists after ADD_BII_TARGETS().
    • Review the BII_LIB_SRC variable in CMakeLists.txt (and BII_exe_name_SRC) and look for missing files.

    If you detect a file is missing, add it to [dependencies] section in biicode.conf.

  • If you receive linker errors, search in the code the missing symbols.

    • If they are in you source code, maybe biicode is not finding some implementation and the dependency graph wasn’t built correctly. You can use bii deps –files to inspect how the code is connected. Use [dependencies] section in biicode.conf to specify the missing source file.
    • Can’t find them in your sources? Try to google them. You may need to link a system library. You can use TARGET_LINK_LIBRARIES(${BII_LIB_TARGET} PUBLIC pthread) in your CMakeLists.txt after ADD_BII_TARGETS().

3. Test the libary’s reusability¶

At this point biicode knows how to build your code. But you are not done yet. You should check that your library can be included and works fine.

  • bii publish to publish a DEV version of your code.

  • Open a new terminal and create a new biicode project with an example including your library. You can check a lot of reuse examples in examples user. Create a new folder and execute bii init -l and bii new –hello cpp. Replace main.cpp code with your example code.

  • Run bii configure to create biicode.conf and CMakeLists.txt files.

  • Require your original block library in [requirements] section of biicode.conf

  • Execute bii deps to ensure your requirement is wired right.

  • Execute bii build to build the example

    • If compilation fails because any files are missing, check bii/deps/ folder to review the files biicode downloaded. If you notice some file are missing you probably need to add them in [dependencies] section in biicode.conf. Fix the library and bii publish again. Then execute bii build in your example folder again, this downloads the updated library automatically. Check again the files downloaded.
    • If compilation fails in cause of an error in your library’s CMakeLists.txt check that you are not presuming that (key fact 1) all files are present. Fix CMakeLists.txt or wire a dependency (if needed) in [dependencies] section in biicode.conf.
  • You can build more examples including more headers from your library to ensure it works well.

  • Congrats! You have a full functional library in biicode! Execute bii publish –tag STABLE to freeze an stable version.

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

With a previous CMakeLists.txt¶

Option 1: Let biicode do its job in an isolated file¶

If you already have a CMakeLists.txt file there’s no need to replace it, just adapt it like this:

IF(BIICODE)
   INCLUDE("biicode.cmake")
   RETURN()
ENDIF()
# Your regular project configuration here

Now create a file named biicode.cmake an add the line ADD_BII_TARGETS(). Then read without a previous CMakeLists.txt section knowing that biicode.cmake is now the file where you will write the code needed.

Option 2: Build your own target library and link them to BII_LIB_TARGET¶

Sometimes, when adapting big and complex libraries that already have a CMakeLists.txt building its own library, the best approach is to link the resulting library to ${BII_LIB_TARGET}

  • As you want to use your own library targets and these take for granted that all files are always present, it’s violating key fact nº1. The way to proceed is wiring all your library files together in [dependencies] section in biicode.conf.

    EXAMPLE: [dependencies] section from curl block.

    [dependencies]
            # Nothing depend on tests, so do not include tests if not needed
            src/* - tests/*
            lib/* - tests/*
            include/* - tests/*
    
            # Lib doesn't depend on src
            lib/* - src/*
    
            # Everything depends on libcurl
            src/* + lib/* docs/MANUAL docs/curl.1 src/mkhelp.pl
            include/* + lib/*
            tests/*.h + src/* lib/* include/* tests/*
    
            # Src module goes together
            src/*.h + src/*.c
    
  • Enable a plug for biicode (key fact nº2) at the end of your CMakeLists.txt (or before installation steps), assuming ${LIB_NAME} is the name of the library you’ve built:

    IF(BIICODE)
      # Clear biicode auto detected files.
      # BII_LIB_TARGET will be an interface target.
      SET(BII_LIB_SRC)
    
      ADD_BII_TARGETS()
    
      # If you have configured some file, include the output directory
      # TARGET_INCLUDE_DIRECTORIES(${BII_LIB_TARGET} INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
    
      # Apply biicode dependencies to my library
      TARGET_LINK_LIBRARIES(${LIB_NAME} PUBLIC ${BII_LIB_DEPS})
      # Also the interface properties
      TARGET_LINK_LIBRARIES(${LIB_NAME} PUBLIC ${BII_BLOCK_TARGET})
      # Wire your lib to ${BII_LIB_TARGET} so biicode can use it
      TARGET_LINK_LIBRARIES(${BII_LIB_TARGET} INTERFACE ${LIB_NAME})
    
    ENDIF()
    
  • Don’t presume that targets are always present (key fact nº1):

    EXAMPLE: tests folder is not present (because tests not depend on any header of your library), so its not downloaded.

    IF(BIICODE AND (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests"))
       # Your code for generate examples targets
    ENDIF()
    
  • If your CMakeLists.txt uses find_package directive and you want to replace these dependencies and depend on biicode blocks:

    • Let biicode handle requirements:

      EXAMPLE: This library links OpenSSL library of the system. But we want to link openssl from biicode:

      if(NOT BIICODE) # Biicode uses OpenSSL as a dep, do not find it in system
        find_package(OpenSSL)
        if(OPENSSL_FOUND)
              set(USE_OPENSSL ON)
              # ...
              # ...
        endif()
      else()
        set(USE_OPENSSL ON)
      endif()
      
      • Require your original block library in [requirements] section in biicode.conf
      • Execute bii deps to ensure your requirement is wired right.

There’s a complete example of Option 2 you can check here at curl block and libcurl CMakeLists.txt.

Option 2 is not “ideal” because is downloading, compiling and linking the whole library and some files may be unnecessary. But if your library files are heavily connected and/or there are so many files this is your best option.

Option 3: Adapt your CMakeLists.txt filtering files¶

There is a third option, a mix of the two previous options:

  • Filter the files with the set of files detected by biicode ${BII_LIB_SRC}, not forcing all source code to interconnect.

    key fact 1 said not to presume all files exist in our CMakeLists.txt, but we know which files has downloaded looking the BII_LIB_SRC variable, so you can always compose your library with the intersection of your list of sources and BII_LIB_SRC

    EXAMPLE:

    MACRO(INTERSECTION var_name list1 list2)
      # Store the intersection between the two given lists in var_name.
      SET(intersect_tmp "")
      FOREACH(l ${list1})
        IF("${list2}" MATCHES "(^|;)${l}(;|$)")
          SET(intersect_tmp ${intersect_tmp} ${l})
        ENDIF("${list2}" MATCHES "(^|;)${l}(;|$)")
      ENDFOREACH(l)
      SET(${var_name} ${intersect_tmp})
    ENDMACRO(INTERSECTION)
    
    # Biicode detects that file2.cpp is not a dependency of the block that includes this one.
    # So in BII_LIB_SRC there are only file1.cpp and file3.cpp
    # If we try to add_library using file2.cpp will fail, so lets filter it.
    
    set(my_library_files file1.cpp file2.cpp file3.cpp)
    IF(BIICODE)
      INTERSECTION(filtered_files "${my_library_files}" "${BII_LIB_SRC}")
    ELSE()
      set(filtered_files ${my_library_files})
    END()
    add_library(my_library ${filtered_files})
    

    You can include tools.cmake from biicode/cmake block and reuse the macro INTERSECTION. Check Publish, share and reuse CMake scripts section for more information.

  • Keep the way you build the library:

    Following key fact 2, you can build your library and link to ${BII_LIB_TARGET}, or even change the value of BII_LIB_TARGET variable to match your library name. The only thing important is that the variable BII_LIB_TARGET contains a cmake library.

    SET(BII_LIB_TARGET my_library)
    

As you know we’re available at our forum for questions and answers. You can also write us.

Where is biicode´s “magic”?
Advanced Usage

© Copyright 2014, biicode.