Skip to content

Commit

Permalink
Change download flag to CLAP_HELPERS_DOWNLOAD_IF_NEEDED.
Browse files Browse the repository at this point in the history
Issue a fatal error if clap or catch2 (if needed) targets
are missing and download is off.
  • Loading branch information
baconpaul committed Jan 16, 2024
1 parent bfa8911 commit 79ec562
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pullreq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:

- name: Build project
run: |
cmake -S . -B ./build ${{ matrix.cmakeargs }} -DCMAKE_BUILD_TYPE=Debug -DCLAP_HELPERS_BUILD_TESTS=TRUE
cmake -S . -B ./build ${{ matrix.cmakeargs }} -DCMAKE_BUILD_TYPE=Debug -DCLAP_HELPERS_DOWNLOAD_IF_NEEDED=TRUE -DCLAP_HELPERS_BUILD_TESTS=TRUE
cmake --build ./build --config Debug --target clap-helpers-tests --parallel
- name: Run Tests
Expand Down
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ cmake_policy(SET CMP0100 NEW) # handle .hh files
project(clap-helpers C CXX)

option(CLAP_HELPERS_BUILD_TESTS "Build tests for the CLAP Helper" FALSE)
option(CLAP_HELPERS_ALWAYS_DOWNLOAD "Always download CPM versions even if target defined" FALSE)
option(CLAP_HELPERS_DOWNLOAD_IF_NEEDED "Resolve CLAP Targets with CPM if not defined" FALSE)

add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE include)

if ((NOT TARGET clap) OR ${CLAP_HELPERS_ALWAYS_DOWNLOAD})
if ((NOT TARGET clap) AND ${CLAP_HELPERS_DOWNLOAD_IF_NEEDED})
message(STATUS "${PROJECT_NAME}: Downloading CLAP using CPM")

message(STATUS "${PROJECT_NAME}: including CPM")
Expand All @@ -23,6 +23,8 @@ if ((NOT TARGET clap) OR ${CLAP_HELPERS_ALWAYS_DOWNLOAD})
)

add_subdirectory(${CMAKE_BINARY_DIR}/cpm/clap)
else()
message(FATAL_ERROR "${PROJECT_NAME}: 'clap' is not a target. Set CLAP_HELPERS_DOWNLOAD_IF_NEEDED or include clap before clap-helpers")
endif()
target_link_libraries(${PROJECT_NAME} INTERFACE clap)

Expand All @@ -32,7 +34,7 @@ if (${CLAP_HELPERS_BUILD_TESTS})
set(CLAP_HELPERS_TESTS_CXX_STANDARD 11)
endif()

if ((NOT TARGET Catch2::Catch2WithMain) OR ${CLAP_HELPERS_ALWAYS_DOWNLOAD})
if ((NOT TARGET Catch2::Catch2WithMain) AND ${CLAP_HELPERS_DOWNLOAD_IF_NEEDED})
message(STATUS "${PROJECT_NAME}: Downloading Catch2")
include(cmake/external/CPM.cmake)
CPMAddPackage(
Expand All @@ -44,6 +46,8 @@ if (${CLAP_HELPERS_BUILD_TESTS})
SOURCE_DIR cpm/catch2
)
add_subdirectory(${CMAKE_BINARY_DIR}/cpm/catch2)
else()
message(FATAL_ERROR "${PROJECT_NAME}: 'Catch2::Catch2WithMain' is not a target. Set CLAP_HELPERS_DOWNLOAD_IF_NEEDED or include catch2 before clap-helpers")
endif()

add_executable(${PROJECT_NAME}-tests EXCLUDE_FROM_ALL
Expand Down

0 comments on commit 79ec562

Please sign in to comment.