Created
October 5, 2021 10:20
-
-
Save TinoDidriksen/944e6d94060efaff8b156a6bee24158d to your computer and use it in GitHub Desktop.
MSYS2 CMake + Boost Program Options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ pacman -S cmake make mingw-w64-x86_64-gcc mingw-w64-x86_64-boost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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