Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding CUDA NVCC build #365

Merged
merged 3 commits into from
Dec 10, 2019
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
17 changes: 17 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,20 @@ jobs:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/[email protected]

cuda-build:
name: CUDA build only
runs-on: ubuntu-latest
container: nvidia/cuda:10.2-devel-ubuntu18.04
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: Add wget
run: apt-get update && apt-get install -y wget
- name: Install Modern CMake
run: wget -qO- "https://cmake.org/files/v3.16/cmake-3.16.0-Linux-x86_64.tar.gz" | tar --strip-components=1 -xz -C /usr/local
- name: Configure
run: cmake -S . -B build -DCLI11_CUDA_TESTS=ON
- name: Build
run: cmake --build build
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(CLI11_CUDA_TESTS "Build the tests with NVCC to check for warnings there - requires CMake 3.9+")
if(CLI11_CUDA_TESTS)
enable_language(CUDA)

# Print out warning and error numbers
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --display_error_number")
endif()

option(CLI11_WARNINGS_AS_ERRORS "Turn all warnings into errors (for CI)")

# Be moderately paranoid with flags
Expand Down
12 changes: 11 additions & 1 deletion include/CLI/TypeTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,17 @@ struct pair_adaptor<
// check for constructibility from a specific type and copy assignable used in the parse detection
template <typename T, typename C> class is_direct_constructible {
template <typename TT, typename CC>
static auto test(int, std::true_type) -> decltype(TT{std::declval<CC>()}, std::is_move_assignable<TT>());
static auto test(int, std::true_type) -> decltype(
// NVCC warns about narrowing conversions here
#ifdef __CUDACC__
#pragma diag_suppress 2361
#endif
TT { std::declval<CC>() }
#ifdef __CUDACC__
#pragma diag_default 2361
#endif
,
std::is_move_assignable<TT>());

template <typename TT, typename CC> static auto test(int, std::false_type) -> std::false_type;

Expand Down
12 changes: 11 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ set(CLI11_MULTIONLY_TESTS
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

foreach(T ${CLI11_TESTS})
if(CLI11_CUDA_TESTS)
set_property(
SOURCE ${T}.cpp
PROPERTY
LANGUAGE CUDA
)
endif()

add_executable(${T} ${T}.cpp ${CLI11_headers})
add_sanitizers(${T})
target_link_libraries(${T} PUBLIC CLI11 CLI11_warnings)
target_link_libraries(${T} PUBLIC CLI11)
if(NOT CLI11_CUDA_TESTS)
target_link_libraries(${T} PUBLIC CLI11_warnings)
endif()
add_gtest(${T})

if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion tests/SetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ TEST_F(TApp, SimiShortcutSets) {
}

TEST_F(TApp, SetFromCharStarArrayVector) {
constexpr const char *names[] = {"one", "two", "three"};
constexpr const char *names[3]{"one", "two", "three"};
std::string value;
auto opt = app.add_option("-s,--set", value)
->check(CLI::IsMember{std::vector<std::string>(std::begin(names), std::end(names))});
Expand Down