Skip to content
Open
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ target_link_libraries(cli INTERFACE Threads::Threads)
# ---------------------------------------------------------------
# Boost.Asio support
# ---------------------------------------------------------------
set(CLI_BOOST_COMPILED OFF)
if(CLI_UseBoostAsio)
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW) # <PackageName>_ROOT
Expand All @@ -83,6 +84,7 @@ if(CLI_UseBoostAsio)
add_definitions(-DBOOST_ALL_NO_LIB) # for windows

if(Boost_FOUND)
set(CLI_BOOST_COMPILED ON)
message(STATUS "Using compiled Boost libraries on ${CMAKE_SYSTEM_NAME}")
target_link_libraries(cli INTERFACE Boost::system Boost::date_time)
else()
Expand Down Expand Up @@ -150,6 +152,10 @@ endif()
if(CLI_BuildTests)
enable_testing()
add_subdirectory(test)
add_test(NAME cli_install_consumer
COMMAND ${CMAKE_COMMAND}
-DTEST_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/install-consumer
-P ${CMAKE_CURRENT_SOURCE_DIR}/test/cmake/install-consumer.cmake)
endif()

# ---------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions cliConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

include(CMakeFindDependencyMacro)

if (CLI_UseBoostAsio)
find_dependency(Boost REQUIRED COMPONENTS system)
if (@CLI_BOOST_COMPILED@)
find_dependency(Boost REQUIRED COMPONENTS system date_time)
endif()

find_dependency(Threads REQUIRED)
Expand Down
6 changes: 6 additions & 0 deletions test/cmake/consumer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.8...3.27)
project(cli_install_consumer LANGUAGES CXX)

find_package(cli CONFIG REQUIRED)
add_executable(consumer main.cpp)
target_link_libraries(consumer PRIVATE cli::cli)
13 changes: 13 additions & 0 deletions test/cmake/consumer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <cli/cli.h>
#include <sstream>

int main()
{
auto menu = std::make_unique<cli::Menu>("cli");
menu->Insert("add", [](std::ostream& out, int a, int b){ out << a + b; });
cli::Cli app(std::move(menu));
std::ostringstream out;
cli::CliSession session(app, out);
session.Feed("add 2 3");
return out.str() == "5" ? 0 : 1;
}
26 changes: 26 additions & 0 deletions test/cmake/install-consumer.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Run with: cmake -DTEST_BINARY_DIR=<scratch directory> -P test/cmake/install-consumer.cmake
cmake_minimum_required(VERSION 3.8...3.27)
get_filename_component(CLI_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)

function(run)
execute_process(COMMAND ${ARGV} RESULT_VARIABLE result)
if(NOT result EQUAL 0)
message(FATAL_ERROR "Command failed: ${ARGV}")
endif()
endfunction()

foreach(mode IN ITEMS compiled header_only none)
set(root "${TEST_BINARY_DIR}/${mode}")
set(options -DCLI_UseBoostAsio=ON)
if(mode STREQUAL "header_only")
list(APPEND options -DCMAKE_DISABLE_FIND_PACKAGE_Boost=ON)
elseif(mode STREQUAL "none")
set(options -DCLI_UseBoostAsio=OFF)
endif()
run("${CMAKE_COMMAND}" "-H${CLI_SOURCE_DIR}" "-B${root}/library"
"-DCMAKE_INSTALL_PREFIX=${root}/prefix" ${options})
run("${CMAKE_COMMAND}" --build "${root}/library" --target install --config Release)
run("${CMAKE_COMMAND}" "-H${CMAKE_CURRENT_LIST_DIR}/consumer" "-B${root}/consumer"
"-DCMAKE_PREFIX_PATH=${root}/prefix")
run("${CMAKE_COMMAND}" --build "${root}/consumer" --config Release)
endforeach()