https://github.com/a-cordier/bpk
:construction_worker: bpk packages files as binary resources availables in your C++ project
https://github.com/a-cordier/bpk
build-tool cpp
Last synced: 8 months ago
JSON representation
:construction_worker: bpk packages files as binary resources availables in your C++ project
- Host: GitHub
- URL: https://github.com/a-cordier/bpk
- Owner: a-cordier
- Created: 2019-05-28T21:35:17.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-09T09:11:09.000Z (about 7 years ago)
- Last Synced: 2025-02-12T16:18:55.614Z (over 1 year ago)
- Topics: build-tool, cpp
- Language: C++
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## bpk
bpk packages files as binary resources availables in your project
### Requirements
- [cmake](https://cmake.org/install/)
- [conan](https://docs.conan.io/en/latest/installation.html)
### Download & Build
```sh
git clone --recursive https://github.com/a-cordier/bpk.git
cd bpk
mkdir build
cd build
cmake ..
make
```
### Package your files
```sh
bpk -d -o .h -n
```
### Use in your project
- Add the output file to your project
- Use `::getResource(const char* key)` to get access to your file
Files are named after their relative path inside their resource directory
### Example
- Assuming the following resource directory
```
resources
└── svg
├── next.svg
├── pause.svg
├── play.svg
├── previous.svg
└── stop.svg
```
Running:
```sh
bpk -d ./resources -o resources.h -n resources
```
- Will generate the following `resources.h` file
```cpp
#include
#include
#include
#include
namespace resources {
namespace {
std::map > data = {
{ "svg/previous.svg", { /* Data chunks */ } },
{ "svg/pause.svg", { /* Data chunks */ } },
{ "svg/play.svg", { /* Data chunks */ } },
{ "svg/next.svg", { /* Data chunks */ } },
};
}
inline char* get(const char* name) {
auto it = data.find(name);
return it == data.end() ? nullptr : it->second.data();
}
inline std::vector::size_type size(const char* name) {
auto it = data.find(name);
return it == data.end() ? 0 : it->second.size();
}
}
```
- Resources being accessed the following way
```cpp
#include "resources.h"
auto data = resources::get("svg/play.svg")
```
### Integrating with CMAKE
Integration with CMAKE for automating generation at build time may be achieved using the
[ExternalProject](https://cmake.org/cmake/help/latest/module/ExternalProject.html) module
#### CMAKE integration sample
```cmake
include(ExternalProject)
ExternalProject_Add(
bpk
GIT_REPOSITORY "https://github.com/a-cordier/bpk.git"
GIT_TAG "v1.0.0"
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/bpk-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/bpk-build"
INSTALL_COMMAND ""
)
set(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources")
set(RESOURCES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/src/resources.h")
add_custom_command(
TARGET bpk
POST_BUILD
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND "${CMAKE_CURRENT_BINARY_DIR}/bpk-build/bin/bpk"
"-o" "${RESOURCES_FILE}"
"-d" "${RESOURCES_DIR}"
"-n" "resources"
COMMENT "Running bpk to generate resources file"
)
```