Skip to content

Commit

Permalink
🔧 added simple boost example
Browse files Browse the repository at this point in the history
  • Loading branch information
pysco68 committed Mar 6, 2025
1 parent 780f147 commit 0173859
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/boost/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
45 changes: 45 additions & 0 deletions example/boost/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.27.6)
project(boost-example VERSION "0.0.1")

set(FETCHCONTENT_QUIET OFF)
include(FetchContent)


set(hfc_REPOSITORY https://github.com/tipi-build/hfc)
set(hfc_REVISION main)

include(HermeticFetchContent OPTIONAL RESULT_VARIABLE hfc_included)
if(NOT hfc_included)
FetchContent_Populate(
hfc
GIT_REPOSITORY https://github.com/tipi-build/hfc.git
GIT_TAG ${hfc_REVISION}
SOURCE_DIR "${PROJECT_SOURCE_DIR}/thirdparty/cache/hfc/src"
SUBBUILD_DIR "${PROJECT_SOURCE_DIR}/thirdparty/cache/hfc/subbuild"
BINARY_DIR "${PROJECT_SOURCE_DIR}/thirdparty/cache/hfc/bin"
)
FetchContent_GetProperties(hfc)
message(STATUS "Hermetic FetchContent ${hfc_REVISION} available at '${hfc_SOURCE_DIR}'")
list(APPEND CMAKE_MODULE_PATH "${hfc_SOURCE_DIR}/cmake")
include(HermeticFetchContent)
endif()

FetchContent_Declare(
Boost
GIT_REPOSITORY https://github.com/boostorg/boost
GIT_TAG "ab7968a0bbcf574a7859240d1d8443f58ed6f6cf" # 1.85
)

FetchContent_MakeHermetic(
Boost
HERMETIC_TOOLCHAIN_EXTENSION
[=[
set(BOOST_BUILD_TEST OFF CACHE BOOL "" FORCE)
set(BOOST_ENABLE_PYTHON OFF CACHE BOOL "" FORCE)
]=]
)

HermeticFetchContent_MakeAvailableAtBuildTime(Boost)

add_executable(boost_example "boost_example.cpp")
target_link_libraries(boost_example Boost::system)
174 changes: 174 additions & 0 deletions example/boost/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Adding Boost to your project using HFC

This example showcases how to add [boost](https://github.com/boostorg/boost) to your HFC project.

```
cmake -GNinja -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
./build/boost_example
```

The example application just uses bits from the Boost Algorithm Library, but all the targets exported by Boost's CMake build system are available for consumption once the dependency has been configured.

Here's the list of targets that boost v1.85 is exporting:

```
Boost::accumulators
Boost::algorithm
Boost::align
Boost::any
Boost::array
Boost::asio
Boost::assert
Boost::assign
Boost::atomic
Boost::beast
Boost::bimap
Boost::bind
Boost::callable_traits
Boost::charconv
Boost::chrono
Boost::circular_buffer
Boost::compat
Boost::compatibility
Boost::compute
Boost::concept_check
Boost::config
Boost::container
Boost::container_hash
Boost::context
Boost::contract
Boost::conversion
Boost::convert
Boost::core
Boost::coroutine
Boost::coroutine2
Boost::crc
Boost::date_time
Boost::describe
Boost::detail
Boost::dll
Boost::dynamic_bitset
Boost::endian
Boost::exception
Boost::fiber
Boost::fiber_numa
Boost::filesystem
Boost::flyweight
Boost::foreach
Boost::format
Boost::function
Boost::function_types
Boost::functional
Boost::fusion
Boost::geometry
Boost::gil
Boost::graph
Boost::hana
Boost::headers
Boost::heap
Boost::histogram
Boost::hof
Boost::icl
Boost::included_prg_exec_monitor
Boost::included_test_exec_monitor
Boost::included_unit_test_framework
Boost::integer
Boost::interprocess
Boost::intrusive
Boost::io
Boost::iostreams
Boost::iterator
Boost::json
Boost::lambda
Boost::lambda2
Boost::leaf
Boost::lexical_cast
Boost::local_function
Boost::locale
Boost::lockfree
Boost::log
Boost::log_setup
Boost::logic
Boost::math
Boost::metaparse
Boost::move
Boost::mp11
Boost::mpl
Boost::msm
Boost::multi_array
Boost::multi_index
Boost::multiprecision
Boost::mysql
Boost::nowide
Boost::numeric_conversion
Boost::numeric_interval
Boost::numeric_odeint
Boost::numeric_ublas
Boost::optional
Boost::outcome
Boost::parameter
Boost::pfr
Boost::phoenix
Boost::poly_collection
Boost::polygon
Boost::pool
Boost::predef
Boost::preprocessor
Boost::prg_exec_monitor
Boost::process
Boost::program_options
Boost::property_map
Boost::property_tree
Boost::proto
Boost::ptr_container
Boost::qvm
Boost::random
Boost::range
Boost::ratio
Boost::rational
Boost::redis
Boost::regex
Boost::safe_numerics
Boost::scope
Boost::scope_exit
Boost::serialization
Boost::signals2
Boost::smart_ptr
Boost::sort
Boost::spirit
Boost::stacktrace_addr2line
Boost::stacktrace_backtrace
Boost::stacktrace_basic
Boost::stacktrace_noop
Boost::statechart
Boost::static_assert
Boost::static_string
Boost::stl_interfaces
Boost::system
Boost::test_exec_monitor
Boost::thread
Boost::throw_exception
Boost::timer
Boost::tokenizer
Boost::tti
Boost::tuple
Boost::type_erasure
Boost::type_index
Boost::type_traits
Boost::typeof
Boost::unit_test_framework
Boost::units
Boost::unordered
Boost::url
Boost::utility
Boost::uuid
Boost::variant
Boost::variant2
Boost::vmd
Boost::wave
Boost::winapi
Boost::wserialization
Boost::xpressive
Boost::yap
```
46 changes: 46 additions & 0 deletions example/boost/boost_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <boost/algorithm/string.hpp>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char **argv)
{
std::string text = " Hello, Boost Algorithm Library! ";

// Trim whitespace from the string
boost::algorithm::trim(text);
std::cout << "Trimmed text: '" << text << "'" << std::endl;

// Convert to uppercase
std::string upper_text = boost::algorithm::to_upper_copy(text);
std::cout << "Uppercase: " << upper_text << std::endl;

// Convert to lowercase
std::string lower_text = boost::algorithm::to_lower_copy(text);
std::cout << "Lowercase: " << lower_text << std::endl;

// Split the string into words
std::vector<std::string> words;
boost::algorithm::split(words, text, boost::is_any_of(" ,!"));
std::cout << "Split words:\n";
for (const auto &word : words) {
if (!word.empty()) {
std::cout << "- " << word << std::endl;
}
}

// Join words with a hyphen
std::string joined_text = boost::algorithm::join(words, "-");
std::cout << "Joined with hyphen: " << joined_text << std::endl;

// Check if string starts or ends with a certain substring
if (boost::algorithm::starts_with(text, "Hello")) {
std::cout << "The text starts with 'Hello'." << std::endl;
}

if (boost::algorithm::ends_with(text, "Library!")) {
std::cout << "The text ends with 'Library!'." << std::endl;
}

return 0;
}

0 comments on commit 0173859

Please sign in to comment.