All Projects â†’ cginternals â†’ cpplocate

cginternals / cpplocate

Licence: MIT license
Cross-platform C++ library providing tools for applications to locate themselves, their data assets as well as dependent modules.

Programming Languages

CMake
9771 projects
c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language
Makefile
30231 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to cpplocate

dpytools
Collection of easy to use, beginner friendly but powerful, orthogonal tools to speed up discord bots development (discord.py)
Stars: ✭ 23 (-62.3%)
Mutual labels:  utility-library
s3tree
🌲 Access S3 like a tree.
Stars: ✭ 26 (-57.38%)
Mutual labels:  utility-library
mpu
Martins Python Utilities - Stuff that comes in Handy
Stars: ✭ 47 (-22.95%)
Mutual labels:  utility-library
react-pendulum
A React Context utility library.
Stars: ✭ 15 (-75.41%)
Mutual labels:  utility-library
isepic-chess
♞ JavaScript chess utility library.
Stars: ✭ 16 (-73.77%)
Mutual labels:  utility-library
Biblioteca-DDR-Java
Funciones java con utilidades para distintos proyectos
Stars: ✭ 19 (-68.85%)
Mutual labels:  utility-library
HypeStyle
Small, useful CSS library build on utility classes & components.
Stars: ✭ 28 (-54.1%)
Mutual labels:  utility-library
fastnumbers
Super-fast and clean conversions to numbers.
Stars: ✭ 85 (+39.34%)
Mutual labels:  utility-library
Differentia.js
No longer being supported or maintained. A Graph Theory & Data Structure Library for JavaScript.
Stars: ✭ 13 (-78.69%)
Mutual labels:  utility-library
redux-fp
Functional programming helpers for Redux.
Stars: ✭ 28 (-54.1%)
Mutual labels:  utility-library
DPTLib
My C libraries
Stars: ✭ 20 (-67.21%)
Mutual labels:  utility-library
rgutil
rgutil是基于ES6创建的函数库工具
Stars: ✭ 22 (-63.93%)
Mutual labels:  utility-library
CLU
The OpenCL Utility library
Stars: ✭ 18 (-70.49%)
Mutual labels:  utility-library
js-markerclusterer
Create and manage clusters for large amounts of markers
Stars: ✭ 92 (+50.82%)
Mutual labels:  utility-library
CommonUtils
No description or website provided.
Stars: ✭ 39 (-36.07%)
Mutual labels:  utility-library
Benzina
Benzina is an image-loader package that greatly accelerates image loading onto GPUs using their built-in hardware codecs.
Stars: ✭ 36 (-40.98%)
Mutual labels:  utility-library
mango
Core utility library & data connectors designed for simpler usage in Scala
Stars: ✭ 41 (-32.79%)
Mutual labels:  utility-library
CoreLibraries
A set of .NET libraries for building enterprise level solutions quickly
Stars: ✭ 22 (-63.93%)
Mutual labels:  utility-library
bytes-java
Bytes is a utility library that makes it easy to create, parse, transform, validate and convert byte arrays in Java. It supports endianness as well as immutability and mutability, so the caller may decide to favor performance.
Stars: ✭ 120 (+96.72%)
Mutual labels:  utility-library
not-enough-standards
A modern header-only C++ library that provides platform-independent utilities.
Stars: ✭ 197 (+222.95%)
Mutual labels:  utility-library


cpplocate is a cross-platform C++ library that provides tools for applications to locate their binary files and data assets, as well as those of dependent modules.

GitHub release C++ CI Tokei Tokei

In the context of cross-platform applications, locating data assets belonging to an application or library is not an easy task. Depending on the situation, data assets can occupy different locations on a system: in a development tree, data might be located relative to the executable in a build directory, when installed into the system, they might be located in a global directory such as /usr/share or C:\Users\...\AppData, while for self-contained installs they might be located relative to the executable again. When projects are deployed using installers or archives, the final location can be controlled by the user installing the software, therefore it cannot be known at build-time. The situation gets even more complicated when an application does not only need access to its own data assets, but depends on other modules, such as dynamic libraries or even plugins, which bring their own data. However, software should be able to locate its data assets as easy as possible and still be relocatable for typical deployment and installation routines to work as expected.

cpplocate provides interfaces to locate such data assets. Following, a short example on how glbinding examples locate their run-time assets:

#include <cpplocate/cpplocate.h>

#include <glbinding/gl/gl.h>

const std::string assetPath = cpplocate::locatePath("data/cubescape", "share/glbinding", 
    reinterpret_cast<void *>(&gl::glCreateShader));
// assetPath now contains the path to the directory containing "data/cubescape"

Resources

Installation and Development
Feature Documentation and Code Snippets

Install Instructions

cpplocate is available for different platforms using different distribution channels. You can either download the source and manually compile it or use one of the pre-compiled releases of this repository. For systems providing package managers, we generally strive to provide packages.

Windows

There is currently no precompiled package maintained. Please download the source code and commence building from source.

Ubuntu

cpplocate is provided on Ubuntu using PPAs. For Ubuntu 15.04 (vivid) and more recent versions use the current PPA, for Ubuntu 14.04 (trusty) use the backports PPA. Using the current PPA as example, the following lines install cpplocate:

> sudo apt-add-repository ppa:cginternals/ppa
> sudo apt-get update
> sudo apt-get install libcpplocate

To use cpplocate as dependency, install the development package:

> sudo apt-get install libcpplocate-dev libcpplocate-dbg

Alternatively, download the source code and commence building from source.

OS X

There is currently no precompiled package maintained. Please download the source code and commence building from source.

Debian-based Systems

There is currently no precompiled package maintained. Please download the source code and commence building from source.

Build Instructions

Prerequisites and Dependencies

The only mandatory run-time dependencies of cpplocate are the STL of the used compiler. Building cpplocate utilizes:

  • CMake 3.0 or higher for building cpplocate from source (mandatory for any build from source)
  • git for version control (optional)
  • Doxygen 1.8 or higher for generating the documentation on your system (optional)
    • graphviz for generating diagrams (optional)
Compile Instructions

For compilation, a C++11 compliant compiler, e.g., GCC 4.8, Clang 3.3, MSVC 2013 Update 3, is required.

First, download the source code as archive or via git:

> git clone https://github.com/cginternals/cpplocate.git
> cd cpplocate

Then, depending on the version of cpplocate you want to build, choose the appropriate tag or branch, e.g., for the 2.0.0 release:

> git fetch --tags
> git checkout v2.0.0

The actual compilation can be done using CMake and your favorite compiler and IDE.

For building cpplocate CMake via command line can be used (should work on all systems):

First create a build directory (we do not recommend in-source builds):

> mkdir build
> cd build

Configure cpplocate with your prefered or default generator, e.g., for Visual Studio 2017 in x64 use (note: some IDEs have integrated support for CMake projects, e.g., Qt Creator, and allow you to skip the manual project configuration):

> cmake .. -G "Visual Studio 15 2017 Win64"

In order to compile the project, either use you favorite Editor/IDE with the created project or use CMake as follows:

> cmake --build .

Tips for Linking

For a smooth integration we suggest using CMake, the build system employed by cpplocate. In this case, cpplocate provides a find configuration script that should be either installed into your system or at least accessible by CMake. In your project's CMakeLists.txt, add one of the following lines:

find_package(cpplocate QUIET) # if you want to check for existence
find_package(cpplocate REQUIRED) # if it is really required in your project

Finally, just link cpplocate to your own library or executable:

target_link_libraries(${target} ... PUBLIC cpplocate::cpplocate)

Examples and Documentation

cpplocate supports queries of different paths, depending on the type of the component in question (application, library, or application bundle). For the most basic use case, cpplocate is used to detect run-time data that is associated with a module, and we provide a convenience location function.

Query Executable Path

#include <cpplocate/cpplocate.h>

const std::string executablePath = cpplocate::getExecutablePath();
// executablePath now contains the path to the executable (including its filename)

Query Module Path

#include <cpplocate/cpplocate.h>

const std::string modulePath = cpplocate::getModulePath();
// modulePath now contains the path to the directory containing the executable

Query Bundle Path

Querying application bundles is only defined for macOS application bundles. For other platforms or non-bundle applications, empty strings are returned.

#include <cpplocate/cpplocate.h>

const std::string bundlePath = cpplocate::getBundlePath();
// bundlePath now contains the path to the root of the application bundle
// (instead of the path to the executable within the bundle)

Query Library Path

To query a library location, you have to specify a pointer to a symbol (e.g., a function pointer or a public static member) that is exposed by the library.

#include <cpplocate/cpplocate.h>

#include <QtGlobal>

const std::string libraryPath = cpplocate::getLibraryPath(reinterpret_cast<void *>(&qVersion));
// libraryPath now contains the path to the QtCore library (including its filename)

Query Runtime Asset Path

This function searches for a subdirectory pattern across available system paths, local run paths of the executable or alongside a library that is identified via an exported symbol. This function searches for a relative directory as passed as the first parameter along the executable or a library (local install) and in a number of system install locations (system install). In case of a system install, the relative path of the second parameter is assumed to prepend the first parameter. A library for which a run-time directory should get located can be identified through an exposed symbol.

Note that for Windows most projects deploy using local installs. Currently, we assume local installs for Windows.

#include <cpplocate/cpplocate.h>

#include <glbinding/gl/gl.h>

const std::string assetPath = cpplocate::locatePath("data/cubescape", "share/glbinding", 
    reinterpret_cast<void *>(&gl::glCreateShader));
// assetPath now contains the path to the directory containing "data/cubescape"

C Port of cpplocate: liblocate

Internally, cpplocate is implemented using plain C, providing a C++ interface for ease of use. For communities and software that don't want to use C++, the liblocate within this project can be used instead.

The adapted CMake integration is:

find_package(liblocate QUIET) # if you want to check for existence
find_package(liblocate REQUIRED) # if it is really required in your project

# declare target

target_link_libraries(${target} ... PUBLIC cpplocate::liblocate)

The interfaces are as follows:

#include <liblocate/liblocate.h>

// Get path to the current executable
void getExecutablePath(char ** path, unsigned int * pathLength);

// Get path to the current application bundle
void getBundlePath(char ** path, unsigned int * pathLength);

// Get path to the current module
void getModulePath(char ** path, unsigned int * pathLength);

// Get path to dynamic library
void getLibraryPath(void * symbol, char ** path, unsigned int * pathLength);

// Locate path to a file or directory
void locatePath(char ** path, unsigned int * pathLength, const char * relPath, unsigned int relPathLength, 
    const char * systemDir, unsigned int systemDirLength, void * symbol);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].