Commit 3bdbbd787515e3a74ab552d5f46607027747495a
Committed by
GitHub
1 parent
d9379ccc
Adding CUDA NVCC build (#365)
* Adding CUDA build * Filter NVCC warning * Constexpr reword
Showing
5 changed files
with
48 additions
and
3 deletions
.github/workflows/tests.yml
| ... | ... | @@ -22,3 +22,20 @@ jobs: |
| 22 | 22 | path: ~/.cache/pre-commit |
| 23 | 23 | key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} |
| 24 | 24 | - uses: pre-commit/action@v1.0.0 |
| 25 | + | |
| 26 | + cuda-build: | |
| 27 | + name: CUDA build only | |
| 28 | + runs-on: ubuntu-latest | |
| 29 | + container: nvidia/cuda:10.2-devel-ubuntu18.04 | |
| 30 | + steps: | |
| 31 | + - uses: actions/checkout@v1 | |
| 32 | + with: | |
| 33 | + submodules: true | |
| 34 | + - name: Add wget | |
| 35 | + run: apt-get update && apt-get install -y wget | |
| 36 | + - name: Install Modern CMake | |
| 37 | + 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 | |
| 38 | + - name: Configure | |
| 39 | + run: cmake -S . -B build -DCLI11_CUDA_TESTS=ON | |
| 40 | + - name: Build | |
| 41 | + run: cmake --build build | ... | ... |
CMakeLists.txt
| ... | ... | @@ -45,6 +45,14 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) |
| 45 | 45 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 46 | 46 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 47 | 47 | |
| 48 | + option(CLI11_CUDA_TESTS "Build the tests with NVCC to check for warnings there - requires CMake 3.9+") | |
| 49 | + if(CLI11_CUDA_TESTS) | |
| 50 | + enable_language(CUDA) | |
| 51 | + | |
| 52 | + # Print out warning and error numbers | |
| 53 | + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --display_error_number") | |
| 54 | + endif() | |
| 55 | + | |
| 48 | 56 | option(CLI11_WARNINGS_AS_ERRORS "Turn all warnings into errors (for CI)") |
| 49 | 57 | |
| 50 | 58 | # Be moderately paranoid with flags | ... | ... |
include/CLI/TypeTools.hpp
| ... | ... | @@ -140,7 +140,17 @@ struct pair_adaptor< |
| 140 | 140 | // check for constructibility from a specific type and copy assignable used in the parse detection |
| 141 | 141 | template <typename T, typename C> class is_direct_constructible { |
| 142 | 142 | template <typename TT, typename CC> |
| 143 | - static auto test(int, std::true_type) -> decltype(TT{std::declval<CC>()}, std::is_move_assignable<TT>()); | |
| 143 | + static auto test(int, std::true_type) -> decltype( | |
| 144 | +// NVCC warns about narrowing conversions here | |
| 145 | +#ifdef __CUDACC__ | |
| 146 | +#pragma diag_suppress 2361 | |
| 147 | +#endif | |
| 148 | + TT { std::declval<CC>() } | |
| 149 | +#ifdef __CUDACC__ | |
| 150 | +#pragma diag_default 2361 | |
| 151 | +#endif | |
| 152 | + , | |
| 153 | + std::is_move_assignable<TT>()); | |
| 144 | 154 | |
| 145 | 155 | template <typename TT, typename CC> static auto test(int, std::false_type) -> std::false_type; |
| 146 | 156 | ... | ... |
tests/CMakeLists.txt
| ... | ... | @@ -52,10 +52,20 @@ set(CLI11_MULTIONLY_TESTS |
| 52 | 52 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) |
| 53 | 53 | |
| 54 | 54 | foreach(T ${CLI11_TESTS}) |
| 55 | + if(CLI11_CUDA_TESTS) | |
| 56 | + set_property( | |
| 57 | + SOURCE ${T}.cpp | |
| 58 | + PROPERTY | |
| 59 | + LANGUAGE CUDA | |
| 60 | + ) | |
| 61 | + endif() | |
| 55 | 62 | |
| 56 | 63 | add_executable(${T} ${T}.cpp ${CLI11_headers}) |
| 57 | 64 | add_sanitizers(${T}) |
| 58 | - target_link_libraries(${T} PUBLIC CLI11 CLI11_warnings) | |
| 65 | + target_link_libraries(${T} PUBLIC CLI11) | |
| 66 | + if(NOT CLI11_CUDA_TESTS) | |
| 67 | + target_link_libraries(${T} PUBLIC CLI11_warnings) | |
| 68 | + endif() | |
| 59 | 69 | add_gtest(${T}) |
| 60 | 70 | |
| 61 | 71 | if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS) | ... | ... |
tests/SetTest.cpp
| ... | ... | @@ -306,7 +306,7 @@ TEST_F(TApp, SimiShortcutSets) { |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | TEST_F(TApp, SetFromCharStarArrayVector) { |
| 309 | - constexpr const char *names[] = {"one", "two", "three"}; | |
| 309 | + constexpr const char *names[3]{"one", "two", "three"}; | |
| 310 | 310 | std::string value; |
| 311 | 311 | auto opt = app.add_option("-s,--set", value) |
| 312 | 312 | ->check(CLI::IsMember{std::vector<std::string>(std::begin(names), std::end(names))}); | ... | ... |