Skip to main content

Makes include paths for a C/C++ lib relative

Project description

Relative Include

Python utility that replaces C/C++ #include directives with relative paths. It searches for a set of include paths (typically provided by a build system) and searches for the best match and uses a relative path instead. Typically this wouldnt be required if you are using CMake, Meson, Make, etc, but if the build system does not allow to include directories paths, then you can only resort to relative includes.

Motivation

The motivation of this script is that the Arduino build system for libraries does not have an easy way to add include directories. Instead libraries developed for the Arduino platform require to use relative paths. This should not be a problem if you are developing the library only for Arduino. However, if you want to port a 3rd party library into Arduino in can be a PITA.

If the 3rd party library has a few files it is not a problem but when the number increases, adding the relative paths can take too long or requires to change the original structure of the 3rd party library. If you need to update the library, then you need to repeat this process either because you changed the library structure or the authors of the library changed the place of the headers.

Installation

Pip install

    python -m pip install relative_include

Local install

    python -m setup.py install

Usage

Run the script

    python -m relative_include YourCfg.json
usage: [-h] [-s] [-d] [-V] config_file

positional arguments:
  config_file    JSON Config file to run this script

optional arguments:
  -h, --help     show this help message and exit
  -s             Silent output
  -d             Print debug messages
  -V, --version  show program's version number and exit

To use the script, a JSON configuration file must be provided with the following information

  • lib_path: String Path where the C++/C project is located

  • include_paths: string array that represents the relative path with respect to lib_path of where the include directories are located. Typically these values are passed to the compiler via the -I flag.

  • include_same_dir: Boolean value that indicates wether include directives are included directly by the name of the file or must refer to the root of their directory. By default set to true. For example, if file foo.c includes bar.h, and are located in the directory Foo, the include directive can either be

    • #include "bar.h" when include_same_dir equals true
    • #include "../Foo/bar.h" when include_same_dir equals false

    The second option might seem unnecessary, but if you have another file named bar.h that is included via the compiler flag -I, the incorrect header with the same name might be included. I have seen this behaviour when porting the lwIP project to the Arduino platform and is left as an option for this specific type of edge cases.

  • out: Dictionary Settings for the output of the script

    • dir: String path that indicates wheree to write the output of the script with the relative include changes.
    • overwrite Bolean value that allows to overwrrite the output directory if it already exists.
  • silent: Boolean value. Silences the output of the script. By default set to false.

  • debug: Boolean value. Prints debug information from the script. By default set to false.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

relative_include-1.0.1.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

relative_include-1.0.1-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file relative_include-1.0.1.tar.gz.

File metadata

  • Download URL: relative_include-1.0.1.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for relative_include-1.0.1.tar.gz
Algorithm Hash digest
SHA256 de80ce8e9d167f3ecb48fe26bce74b2c9b7278bd597501c9303c85531a7a85d2
MD5 31fd25a8fb4b3d1cac3b29a3f82ecaf7
BLAKE2b-256 2d9fbde549cf4df8f01f0d4ec83db3ad8ab9fd84c9b4c1a39a0c0773c92765cd

See more details on using hashes here.

File details

Details for the file relative_include-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for relative_include-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a5c54dc20e782520afbfe770d2a8f0e623724eafe82d432401e26a1e07a5c1a
MD5 1ff9ccb3532415532a988641f499ae03
BLAKE2b-256 d812a57d829085a153187df4b1d41c2b05a52504235754e80e776e5e3beb521f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page