🎉 init(cmake): init modern cmake template
This commit is contained in:
24
src/CMakeLists.txt
Normal file
24
src/CMakeLists.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
# Note that headers are optional, and do not affect add_library, but they will not
|
||||
# show up in IDEs unless they are listed in add_library.
|
||||
|
||||
# Optionally glob, but only for CMake 3.12 or later:
|
||||
# file(GLOB HEADER_LIST CONFIGURE_DEPENDS "${ModernCMakeExample_SOURCE_DIR}/include/modern/*.hpp")
|
||||
set(HEADER_LIST "${ModernCMakeExample_SOURCE_DIR}/include/modern/lib.hpp")
|
||||
|
||||
# Make an automatic library - will be static or dynamic based on user setting
|
||||
add_library(modern_library lib.cpp ${HEADER_LIST})
|
||||
|
||||
# We need this directory, and users of our library will need it too
|
||||
target_include_directories(modern_library PUBLIC ../include)
|
||||
|
||||
# This depends on (header only) boost
|
||||
target_link_libraries(modern_library PRIVATE Boost::boost)
|
||||
|
||||
# All users of this library will need at least C++11
|
||||
target_compile_features(modern_library PUBLIC cxx_std_11)
|
||||
|
||||
# IDEs should put the headers in a nice place
|
||||
source_group(
|
||||
TREE "${PROJECT_SOURCE_DIR}/include"
|
||||
PREFIX "Header Files"
|
||||
FILES ${HEADER_LIST})
|
21
src/lib.cpp
Normal file
21
src/lib.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <modern/lib.hpp>
|
||||
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/accumulators/accumulators.hpp>
|
||||
#include <boost/accumulators/statistics/stats.hpp>
|
||||
#include <boost/accumulators/statistics/mean.hpp>
|
||||
#include <boost/accumulators/statistics/moment.hpp>
|
||||
|
||||
namespace ba = boost::accumulators;
|
||||
|
||||
std::tuple<double, double> accumulate_vector(const std::vector<double>& values) {
|
||||
|
||||
ba::accumulator_set<double, ba::stats<ba::tag::mean, ba::tag::moment<2>>> acc;
|
||||
|
||||
std::for_each(std::begin(values), std::end(values), std::ref(acc));
|
||||
|
||||
return {ba::mean(acc), ba::moment<2>(acc)};
|
||||
}
|
Reference in New Issue
Block a user