Skip to content

Commit

Permalink
Use only some examples to use config from boost
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjoe committed Feb 24, 2020
1 parent 1f1e729 commit b2bd8ae
Show file tree
Hide file tree
Showing 47 changed files with 335 additions and 85 deletions.
23 changes: 23 additions & 0 deletions examples/Boost-chrono-useBoostConfig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2013, Ruslan Baratov
# All rights reserved.

cmake_minimum_required(VERSION 3.0)

set(Boost_DEBUG ON CACHE BOOLEAN "")
set(TESTING_CONFIG_OPT FILEPATH ${CMAKE_CURRENT_LIST_DIR}/config.cmake)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(download-boost)

hunter_add_package(Boost COMPONENTS chrono)
find_package(Boost CONFIG REQUIRED chrono)

add_executable(foo foo.cpp)
target_link_libraries(
foo
PUBLIC
Boost::chrono
)
File renamed without changes.
6 changes: 6 additions & 0 deletions examples/Boost-chrono-useBoostConfig/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <boost/chrono/system_clocks.hpp>

int main() {
boost::chrono::system_clock::now();
return 0;
}
8 changes: 5 additions & 3 deletions examples/Boost-chrono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
cmake_minimum_required(VERSION 3.0)

set(Boost_DEBUG ON CACHE BOOLEAN "")
set(TESTING_CONFIG_OPT FILEPATH ${CMAKE_CURRENT_LIST_DIR}/config.cmake)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(download-boost)

hunter_add_package(Boost COMPONENTS chrono)
find_package(Boost CONFIG REQUIRED chrono)
hunter_add_package(Boost COMPONENTS system chrono)
find_package(Boost CONFIG REQUIRED system chrono)

add_executable(foo foo.cpp)
target_link_libraries(
foo
PUBLIC
Boost::chrono
Boost::system # Should be last
# Boost 1.66.0, Linux, Clang with -stdlib=libstdc++:
# * https://travis-ci.org/ingenue/hunter/jobs/318140468#L2651
)
3 changes: 1 addition & 2 deletions examples/Boost-contract/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
cmake_minimum_required(VERSION 3.0)

set(Boost_DEBUG ON CACHE BOOLEAN "")
set(TESTING_CONFIG_OPT FILEPATH ${CMAKE_CURRENT_LIST_DIR}/config.cmake)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
Expand All @@ -16,4 +15,4 @@ hunter_add_package(Boost COMPONENTS system contract)
find_package(Boost CONFIG REQUIRED system contract)

add_executable(foo foo.cpp)
target_link_libraries(foo PUBLIC Boost::contract)
target_link_libraries(foo PUBLIC Boost::system Boost::contract)
7 changes: 3 additions & 4 deletions examples/Boost-fiber/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
cmake_minimum_required(VERSION 3.0)

set(Boost_DEBUG ON CACHE BOOLEAN "")
set(TESTING_CONFIG_OPT FILEPATH ${CMAKE_CURRENT_LIST_DIR}/config.cmake)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(download-boost)

hunter_add_package(Boost COMPONENTS fiber)
find_package(Boost CONFIG REQUIRED fiber)
hunter_add_package(Boost COMPONENTS context fiber)
find_package(Boost CONFIG REQUIRED context fiber)

add_executable(foo foo.cpp)
target_link_libraries(foo PUBLIC Boost::fiber)
target_link_libraries(foo PUBLIC Boost::context Boost::fiber)
66 changes: 66 additions & 0 deletions examples/Boost-filesystem-useBoostConfig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (c) 2013-2015, Ruslan Baratov
# All rights reserved.

cmake_minimum_required(VERSION 3.0)

set(Boost_DEBUG ON CACHE BOOLEAN "")
set(TESTING_CONFIG_OPT FILEPATH ${CMAKE_CURRENT_LIST_DIR}/config.cmake)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(download-boost)

# download boost
hunter_add_package(Boost COMPONENTS filesystem)

# now boost can be used
find_package(Boost CONFIG REQUIRED filesystem)

if(ANDROID)
string(COMPARE EQUAL "${CMAKE_ANDROID_NDK}" "" is_empty)
if(is_empty)
message(FATAL_ERROR "CMAKE_ANDROID_NDK is empty")
endif()
add_library(
foo
SHARED
foo_android.cpp
"${CMAKE_ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c"
)
else()
add_executable(foo foo.cpp)
endif()

target_link_libraries(
foo
Boost::filesystem
)

if(ANDROID)
target_link_libraries(foo log android)
target_include_directories(
foo PUBLIC "${CMAKE_ANDROID_NDK}/sources/android/native_app_glue"
)

if(NOT "$ENV{TRAVIS}")
# Travis CI failed builds:
# * https://travis-ci.org/ingenue/hunter/jobs/106905844
# * https://travis-ci.org/ingenue/hunter/jobs/106905851
hunter_add_package(Android-Apk)
list(APPEND CMAKE_MODULE_PATH "${ANDROID-APK_ROOT}")
include(AndroidApk)

hunter_add_package(Android-SDK)
message("Path to `android`: ${ANDROID-SDK_ROOT}/android-sdk/tools/android")
message("Path to `emulator`: ${ANDROID-SDK_ROOT}/android-sdk/tools/emulator")
message("Path to `adb`: ${ANDROID-SDK_ROOT}/android-sdk/platform-tools/adb")

android_create_apk(
BASE_TARGET foo
LAUNCH_TARGET foo-launch
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/apk"
)
endif()
endif()
File renamed without changes.
7 changes: 7 additions & 0 deletions examples/Boost-filesystem-useBoostConfig/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <boost/filesystem.hpp>
#include <iostream> // std::cout

int main() {
namespace fs = boost::filesystem;
std::cout << "Current path: " << fs::current_path() << std::endl;
}
21 changes: 21 additions & 0 deletions examples/Boost-filesystem-useBoostConfig/foo_android.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2015, Ruslan Baratov
// All rights reserved.

#include <boost/filesystem.hpp>

#include <android_native_app_glue.h>
#include <android/log.h>

void android_main(struct android_app* state) {
app_dummy(); // Make sure glue isn't stripped

namespace fs = boost::filesystem;

__android_log_print(
ANDROID_LOG_INFO,
"BoostFilesystemExample",
fs::current_path().c_str()
);

ANativeActivity_finish(state->activity);
}
8 changes: 5 additions & 3 deletions examples/Boost-filesystem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
cmake_minimum_required(VERSION 3.0)

set(Boost_DEBUG ON CACHE BOOLEAN "")
set(TESTING_CONFIG_OPT FILEPATH ${CMAKE_CURRENT_LIST_DIR}/config.cmake)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
Expand All @@ -13,10 +12,10 @@ include("../common.cmake")
project(download-boost)

# download boost
hunter_add_package(Boost COMPONENTS filesystem)
hunter_add_package(Boost COMPONENTS system filesystem)

# now boost can be used
find_package(Boost CONFIG REQUIRED filesystem)
find_package(Boost CONFIG REQUIRED system filesystem)

if(ANDROID)
string(COMPARE EQUAL "${CMAKE_ANDROID_NDK}" "" is_empty)
Expand All @@ -36,6 +35,9 @@ endif()
target_link_libraries(
foo
Boost::filesystem
Boost::system # Should be last
# Boost 1.66.0, Linux, Clang with -stdlib=libstdc++:
# * https://travis-ci.org/ingenue/hunter/jobs/318140416#L2674
)

if(ANDROID)
Expand Down
23 changes: 23 additions & 0 deletions examples/Boost-iostreams-useBoostConfig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2015, Aaditya Kalsi
# All rights reserved.

cmake_minimum_required(VERSION 3.0)

set(Boost_DEBUG ON CACHE BOOLEAN "")
set(TESTING_CONFIG_OPT FILEPATH ${CMAKE_CURRENT_LIST_DIR}/config.cmake)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(boost_iostreams)

hunter_add_package(Boost COMPONENTS iostreams serialization)
# If you use boost/iostreams/filter/gzip.hpp then you should add ZLIB
find_package(ZLIB CONFIG REQUIRED)
# If you use boost/iostreams/filter/bzip2.hpp then you should add BZip2
find_package(BZip2 CONFIG REQUIRED)
find_package(Boost CONFIG REQUIRED iostreams serialization)

add_executable(foo foo.cpp)
target_link_libraries(foo PUBLIC Boost::iostreams Boost::serialization ZLIB::zlib BZip2::bz2)
File renamed without changes.
66 changes: 66 additions & 0 deletions examples/Boost-iostreams-useBoostConfig/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2015, David Hirvonen
// All rights reserved.

#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>

#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/copy.hpp>

#include <iostream>
#include <fstream>

struct Record
{
Record() {}
Record(int age, const std::string &name) : age(age), name(name) {}

int age;
std::string name;

// Boost serialization:
//friend class boost::serialization::access;
template<class Archive> void serialize(Archive & ar, const unsigned int version)
{
ar & age;
ar & name;
}
};

int main(int argc, char **argv)
{
std::string filename = "/tmp/record.dat";

typedef boost::iostreams::zlib_compressor Compressor;
typedef boost::iostreams::zlib_decompressor Decompressor;

{ // Dump the record:
Record record(1, "kermit");
std::ofstream ofs(filename, std::ios_base::out | std::ios_base::binary);
if(ofs)
{
boost::iostreams::filtering_stream<boost::iostreams::output> buffer;
buffer.push(Compressor());
buffer.push(ofs);
boost::archive::binary_oarchive oa(buffer);
oa << record;
}
}

{ // Load the record
Record record;
std::ifstream ifs(filename, std::ios_base::in | std::ios_base::binary);
if(ifs)
{
boost::iostreams::filtering_streambuf<boost::iostreams::input> buffer;
buffer.push(Decompressor());
buffer.push(ifs);
boost::archive::binary_iarchive ia(buffer); // (ifs);
ia >> record;
}
}
}

7 changes: 1 addition & 6 deletions examples/Boost-iostreams/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
cmake_minimum_required(VERSION 3.0)

set(Boost_DEBUG ON CACHE BOOLEAN "")
set(TESTING_CONFIG_OPT FILEPATH ${CMAKE_CURRENT_LIST_DIR}/config.cmake)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
Expand All @@ -13,11 +12,7 @@ include("../common.cmake")
project(boost_iostreams)

hunter_add_package(Boost COMPONENTS iostreams serialization)
# If you use boost/iostreams/filter/gzip.hpp then you should add ZLIB
find_package(ZLIB CONFIG REQUIRED)
# If you use boost/iostreams/filter/bzip2.hpp then you should add BZip2
find_package(BZip2 CONFIG REQUIRED)
find_package(Boost CONFIG REQUIRED iostreams serialization)

add_executable(foo foo.cpp)
target_link_libraries(foo PUBLIC Boost::iostreams Boost::serialization ZLIB::zlib BZip2::bz2)
target_link_libraries(foo PUBLIC Boost::iostreams Boost::serialization)
12 changes: 10 additions & 2 deletions examples/Boost-log-shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ include("../common.cmake")

project(download-boost)

hunter_add_package(Boost COMPONENTS log)
find_package(Boost CONFIG REQUIRED log)
hunter_add_package(Boost COMPONENTS log filesystem system chrono thread regex date_time atomic)
find_package(Boost CONFIG REQUIRED log filesystem system chrono thread regex date_time atomic)

add_executable(foo foo.cpp)
target_link_libraries(foo
PUBLIC
Boost::log
Boost::filesystem
Boost::system
Boost::chrono
Boost::thread
Boost::regex
Boost::date_time
Boost::atomic
Boost::boost
)
4 changes: 0 additions & 4 deletions examples/Boost-log-shared/config.cmake

This file was deleted.

19 changes: 19 additions & 0 deletions examples/Boost-log-useBoostConfig/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2013-2017, Ruslan Baratov
# All rights reserved.

cmake_minimum_required(VERSION 3.0)

set(Boost_DEBUG ON CACHE BOOLEAN "")
set(TESTING_CONFIG_OPT FILEPATH ${CMAKE_CURRENT_LIST_DIR}/config.cmake)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(download-boost)

hunter_add_package(Boost COMPONENTS log)
find_package(Boost CONFIG REQUIRED log)

add_executable(foo foo.cpp)
target_link_libraries(foo PUBLIC Boost::log)
File renamed without changes.
12 changes: 12 additions & 0 deletions examples/Boost-log-useBoostConfig/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <boost/log/trivial.hpp>

int main() {
BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
BOOST_LOG_TRIVIAL(debug) << "A debug severity message";
BOOST_LOG_TRIVIAL(info) << "An informational severity message";
BOOST_LOG_TRIVIAL(warning) << "A warning severity message";
BOOST_LOG_TRIVIAL(error) << "An error severity message";
BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";

return 0;
}
Loading

0 comments on commit b2bd8ae

Please sign in to comment.