Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/help_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
#include <CLI/CLI.hpp>
#include <string>

int main(int argc, char **argv) {
int main(int argc, char *argv[]) {
std::string input_file_name, output_file_name;
int level{5}, subopt{0};

// app caption
CLI::App app{"CLI11 help"};

// this tests out some of the wide character support, mainly for compilation checking
argv = app.ensure_utf8(argv);
app.require_subcommand(1);
// subcommands options and flags
CLI::App *const encode = app.add_subcommand("e", "encode")->ignore_case(); // ignore case
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ if(CMAKE_CXX_STANDARD LESS 14)
target_compile_features(CLI11 INTERFACE cxx_std_11)
endif()

if(WIN32)
target_link_libraries(CLI11 ${PUBLIC_OR_INTERFACE} Shell32)
endif()

if(CLI11_INSTALL OR CLI11_FULL_INSTALL)

# Make an export target
Expand Down
75 changes: 49 additions & 26 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ endif()
# Add boost to test boost::optional (currently explicitly requested)"
option(CLI11_BOOST "Turn on boost test (currently may fail with Boost 1.70)" OFF)
if(CLI11_BOOST)
find_package(Boost 1.61 REQUIRED)
find_package(Boost 1.61 QUIET CONFIG)
if(NOT Boost_FOUND)
find_package(Boost 1.61 QUIET)
endif()
if(NOT Boost_FOUND)
message(FATAL_ERROR "Boost 1.61+ requested via CLI11_BOOST, but not found.")
endif()
endif()
set(boost-optional-def $<$<BOOL:${Boost_FOUND}>:CLI11_BOOST_OPTIONAL>)

Expand Down Expand Up @@ -71,7 +77,7 @@ endif()

set(CLI11_MULTIONLY_TESTS TimerTest)

find_package(Catch2 CONFIG)
find_package(Catch2 CONFIG QUIET)

if(Catch2_FOUND)
if(NOT TARGET Catch2::Catch2)
Expand All @@ -88,18 +94,29 @@ if(Catch2_FOUND)
target_compile_definitions(Catch2::Catch2WithMain INTERFACE -DCLI11_CATCH3)
endif()
else()
message(STATUS "Downloading Catch2")

# FetchContent would be better, but requires newer CMake.
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/catch2")
set(url https://github.com/philsquared/Catch/releases/download/v2.13.10/catch.hpp)
file(
DOWNLOAD ${url} "${CMAKE_CURRENT_BINARY_DIR}/catch2/catch.hpp"
STATUS status
EXPECTED_HASH SHA256=3725c0f0a75f376a5005dde31ead0feb8f7da7507644c201b814443de8355170)
list(GET status 0 error)
if(error)
message(FATAL_ERROR "Could not download ${url}, and Catch2 not found on your system.")
set(catch2_url https://github.com/philsquared/Catch/releases/download/v2.13.10/catch.hpp)
set(catch2_header "${CMAKE_CURRENT_BINARY_DIR}/catch2/catch.hpp")
set(catch2_hash "3725c0f0a75f376a5005dde31ead0feb8f7da7507644c201b814443de8355170")

if(EXISTS "${catch2_header}")
file(SHA256 "${catch2_header}" catch2_cached_hash)
endif()

if(EXISTS "${catch2_header}" AND catch2_cached_hash STREQUAL catch2_hash)
message(STATUS "Using cached Catch2 header")
else()
message(STATUS "Catch2 not found; downloading Catch2")

# FetchContent would be better, but requires newer CMake.
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/catch2")
file(
DOWNLOAD ${catch2_url} "${catch2_header}"
STATUS status
EXPECTED_HASH SHA256=${catch2_hash})
list(GET status 0 error)
if(error)
message(FATAL_ERROR "Could not download ${catch2_url}, and Catch2 not found on your system.")
endif()
endif()
add_library(catch_main main.cpp catch.hpp)
target_include_directories(catch_main PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}"
Expand Down Expand Up @@ -275,27 +292,33 @@ file(WRITE "${PROJECT_BINARY_DIR}/CTestCustom.cmake"
target_compile_definitions(informational PRIVATE ${boost-optional-def})
target_compile_definitions(OptionalTest PRIVATE ${boost-optional-def})

if(TARGET Boost::boost)
message(STATUS "including boost target")
target_link_libraries(informational PRIVATE Boost::boost)
target_link_libraries(OptionalTest PRIVATE Boost::boost)
target_link_libraries(BoostOptionTypeTest PRIVATE Boost::boost)
if(TARGET Boost::headers)
set(cli11_boost_target Boost::headers)
elseif(TARGET Boost::boost)
set(cli11_boost_target Boost::boost)
endif()

if(DEFINED cli11_boost_target)
message(STATUS "Using Boost target ${cli11_boost_target}")
target_link_libraries(informational PRIVATE ${cli11_boost_target})
target_link_libraries(OptionalTest PRIVATE ${cli11_boost_target})
target_link_libraries(BoostOptionTypeTest PRIVATE ${cli11_boost_target})
if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS)
target_link_libraries(OptionalTest_Single PRIVATE Boost::boost)
target_link_libraries(BoostOptionTypeTest_Single PRIVATE Boost::boost)
target_link_libraries(OptionalTest_Single PRIVATE ${cli11_boost_target})
target_link_libraries(BoostOptionTypeTest_Single PRIVATE ${cli11_boost_target})
endif()
message(STATUS "Boost libs=${Boost_INCLUDE_DIRS}")
elseif(BOOST_FOUND)
message(STATUS "no boost target")
message(STATUS "Boost includes=${Boost_INCLUDE_DIRS}")
elseif(Boost_FOUND)
message(STATUS "Using Boost include directories")
target_include_directories(informational PRIVATE ${Boost_INCLUDE_DIRS})
target_include_directories(OptionalTest PRIVATE ${Boost_INCLUDE_DIRS})
target_include_directories(BoostOptionTypeTest PRIVATE ${Boost_INCLUDE_DIRS})
if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS)
target_include_directories(OptionalTest_Single PRIVATE ${Boost_INCLUDE_DIRS})
target_include_directories(BoostOptionTypeTest_Single PRIVATE ${Boost_INCLUDE_DIRS})
endif()
message(STATUS "Boost libs=${Boost_INCLUDE_DIRS}")
else()
message(STATUS "Boost includes=${Boost_INCLUDE_DIRS}")
elseif(CLI11_BOOST)
message(STATUS "Boost not found, not adding boost tests")
endif()

Expand Down
Loading