Using in your project
There are many ways for adding libbase
to your project. It is up to you to
decide which one you prefer. Below you will find a recommended (and probably the
easiest) way to do so.
Recommended way (CMake)
This will be a step-by-step guide to create a new project that uses libbase
library using a Git and CMake. If you wish to add libbase
to your existing
project, please skip here.
Create a new Git repository and add initial files.
$ git init $ git add [...] $ git commit -m "Initial commit"
Create a new CMake script and a simple C++ source file.
cmake_minimum_required(VERSION 3.13) project(project-name VERSION 1.0 LANGUAGES CXX) add_executable(project-name "") target_sources(project-name PRIVATE src/main.cc )
#include <iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; }
Add
libbase
library as a Git submodule and initialize it$ git submodule add https://github.com/RippeR37/libbase third_party/libbase $ git submodule update --init --recursive
Note
It is not required to fetch/store
libbase
as a submodule. It is, however, a recommended way.Add
libbase
subdirectory to your CMake script.cmake_minimum_required(VERSION 3.13) project(project-name VERSION 1.0 LANGUAGES CXX) add_subdirectory(third_party/libbase) add_executable(project-name "") target_compile_options(project-name PRIVATE ${LIBBASE_COMPILE_FLAGS}) target_link_libraries(project-name PRIVATE libbase) target_sources(project-name PRIVATE src/main.cc )
Use
libbase
library in your project.#include <iostream> #include "base/callback.h" int main() { base::BindOnce([]() { std::cout << "Hello World!" << std::endl; }).Run(); return 0; }
Compile, build and run!
$ cmake -S . -b build $ cmake --build build $ ./build/project-name Hello World!
Tip
Repository with the above project can also be viewed here: RippeR37/libbase-example-cmake.
Other build systems
Todo
Unfortunately, libbase
library at this time comes only with a
preconfigured way of integrating it within another CMake project. Other build
systems are not yet supported out-of-the-box.
Note
If you manage to integrate libbase
with a different build system, feel
free to make a pull request with any necessary changes.