Skip to content

Instantly share code, notes, and snippets.

@TinoDidriksen
Created October 5, 2021 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TinoDidriksen/944e6d94060efaff8b156a6bee24158d to your computer and use it in GitHub Desktop.
Save TinoDidriksen/944e6d94060efaff8b156a6bee24158d to your computer and use it in GitHub Desktop.
MSYS2 CMake + Boost Program Options
$ pacman -S cmake make mingw-w64-x86_64-gcc mingw-w64-x86_64-boost
cmake_minimum_required(VERSION 3.0)
project(test CXX)
find_package(Boost COMPONENTS program_options REQUIRED)
add_executable(test test.cpp)
target_include_directories(test PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(test ${Boost_LIBRARIES})
#include <boost/program_options.hpp>
#include <iostream>
namespace po = boost::program_options;
int main(int argc, char *argv[]) {
try {
po::options_description desc("Allowed Options");
desc.add_options()
("help", "shows the help page")
("compression", po::value<int>(), "set compression level")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << desc << std::endl;
return 0;
}
if (vm.count("compression")) {
std::cout << "Compression level was set to "
<< vm["compression"].as<int>() << "." << std::endl;
} else {
std::cout << "Compression level was not set." << std::endl;
}
} catch(...) {
std::cerr << "caugth a error.\n";
return -1;
}
}
$ export "PATH=/mingw64/bin:$PATH"
$ cmake .
$ make
$ ./test --help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment