Skip to content

Commit

Permalink
Added cxxopts external dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jam4375 committed Dec 28, 2020
1 parent 96080ab commit d1a8b40
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
9 changes: 6 additions & 3 deletions apps/ExampleApp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
add_executable(ExampleApp main.cpp)
configure_file(main.cpp main.cpp)

target_include_directories(ExampleApp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(ExampleApp ExampleLib)
add_executable(ExampleApp "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")

target_include_directories(ExampleApp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(ExampleApp ExampleLib cxxopts)
32 changes: 31 additions & 1 deletion apps/ExampleApp/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
#include "ExampleLib/ExampleLib.h"

int main() {
#include "cxxopts.hpp"

int main(int argc, char **argv) {
cxxopts::Options options(
"ExampleApp", "ExampleApp: example application for the templo template repository (Version: ${GIT_VERSION})");

// clang-format off
options.add_options()
("h,help", "Print usage message")
;
// clang-format on

try {
auto result = options.parse(argc, argv);

if (result.count("help")) {
std::cout << options.help() << std::endl;
std::exit(0);
}
} catch (const cxxopts::option_not_exists_exception &e) {
std::cerr << "ERROR: " << e.what() << std::endl;
std::cout << std::endl;
std::cout << options.help() << std::endl;
std::exit(1);
} catch (const std::exception &e) {
std::cerr << "ERROR: " << e.what() << std::endl;
std::cout << std::endl;
std::cout << options.help() << std::endl;
std::exit(1);
}

PrintMessage("Hello world");

return 0;
Expand Down
19 changes: 19 additions & 0 deletions config/cmake/external/cxxopts.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include(FetchContent)
FetchContent_Declare(
cxxopts-external
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG v2.2.1)

set(FETCHCONTENT_QUIET OFF)

option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)
option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ON)

set(CXXOPTS_BUILD_EXAMPLES OFF)
set(CXXOPTS_BUILD_TESTS OFF)

FetchContent_MakeAvailable(cxxopts-external)

get_target_property(cxxopts_include_dirs cxxopts INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties(cxxopts PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
"${cxxopts_include_dirs}")
1 change: 1 addition & 0 deletions config/cmake/external/external.cmake
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include("${CMAKE_SOURCE_DIR}/config/cmake/external/gtest.cmake")
include("${CMAKE_SOURCE_DIR}/config/cmake/external/cxxopts.cmake")

0 comments on commit d1a8b40

Please sign in to comment.