- Boost Program Options Library
- CMake
- C++14
mkdir build
cd build
cmake .. && make
./evil --help
#!/bin/bash | |
# vim: set ts=4 sw=4 noet fileencoding=utf-8: | |
targetBuildDIR=$(dirname $0)/build | |
if [[ ! -d $targetBuildDIR ]]; then | |
echo "Creating build output directory at $targetBuildDIR" | |
mkdir $targetBuildDIR | |
else | |
echo "Build output directory $targetBuildDIR already exists" | |
fi | |
cd $targetBuildDIR | |
if [[ ! $(type -P cmake) ]]; then | |
echo "CMake was not found in your path. It must be installed." | |
exit -1 | |
fi | |
################################################################################ | |
if cmake .. && make; then | |
cd - # leave the build directory if we are successful | |
else | |
echo "Failed" | |
exit -1 # ensure we propagate the exit code for callers | |
fi |
# vim: set ts=4 sw=4 noet fileencoding=utf-8: | |
# | |
# cmake -DCMAKE_BUILD_TYPE=Debug .. | |
# cmake -DCMAKE_BUILD_TYPE=Release .. | |
cmake_minimum_required(VERSION 2.8) | |
set(PACKAGE_NAME "evil") | |
set(PACKAGE_VERSION "0.0.1-dev") | |
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") | |
set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}") | |
project(${PACKAGE_NAME} CXX) | |
# essential language (C++) specific features & debug / production build | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") | |
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -Wall") | |
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") | |
set(Boost_USE_STATIC_LIBS ON) | |
set(Boost_USE_MULTITHREADED OFF) | |
find_package(Boost 1.42 REQUIRED COMPONENTS program_options) | |
add_executable(evil evil.c++) | |
target_link_libraries(evil ${Boost_LIBRARIES}) |
// vim: set ts=4 sw=4 noet fileencoding=utf-8: | |
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <thread> | |
#include <boost/program_options.hpp> | |
namespace po = boost::program_options; | |
int main(int argc, char const *argv[]) { | |
unsigned threads; | |
try { | |
po::options_description desc("Allowed options"); | |
desc.add_options() | |
("help", "print this help message and exit") | |
("threads,t", po::value<unsigned>(&threads)->default_value(0), | |
"Threads") | |
; | |
po::positional_options_description p; | |
p.add("threads", -1); | |
po::variables_map vm; | |
po::store( | |
po::command_line_parser(argc, argv) | |
.options(desc) | |
.positional(p) | |
.run(), | |
vm); | |
po::notify(vm); | |
if (vm.count("help") || !threads) { | |
std::cout | |
<< "Usage: evil [options]" << std::endl | |
<< desc << std::endl; | |
return 1; | |
} | |
} catch (std::exception& e) { | |
std::cerr << e.what() << std::endl; | |
return 1; | |
} | |
//////////////////////////////////////////////////////////////////////////// | |
auto evil = [](void) -> void { int i; while (1) ++i; }; | |
std::vector<std::thread*> threadList; | |
for (int i = 0; i < threads; ++i) | |
threadList.push_back(new std::thread(*evil)); | |
for (auto t : threadList) t->join(); | |
} |