Skip to content

Commit

Permalink
Switch to CUDAFLAGS for enable_language(CUDA) support on MSVC, and em…
Browse files Browse the repository at this point in the history
…it helpful warnings if possible
  • Loading branch information
ptheywood committed Aug 21, 2024
1 parent 845639f commit 7a683dc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
build_dir: "build"
config: "Release"
CMAKE: ${{ matrix.cmake }}
CUDAFLAGS: "-allow-unsupported-compiler"

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -115,7 +116,7 @@ jobs:
- name: Configure CMake
id: configure
shell: bash
run: cmake . -B ${{ env.build_dir }} -G "${{ matrix.visual_studio }}" -A x64 -DCMAKE_CUDA_FLAGS="--allow-unsupported-compiler"
run: cmake . -B ${{ env.build_dir }} -G "${{ matrix.visual_studio }}" -A x64

- name: Configure Error Processing
if: ${{ (failure() && steps.configure.outcome == 'failure') || success() }}
Expand Down
54 changes: 47 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
# Cmake for simple cuda project which uses NVTX markers as an optional thing.

# Set the minimum cmake version to that which supports cuda natively.
cmake_minimum_required(VERSION VERSION 3.10 FATAL_ERROR)


# Name the project and set languages
project(main CUDA CXX)

# Set the minimum cmake version to that which provides modern CMake CUDA support (CMAKE_CUDA_ARCHITECTURES)
cmake_minimum_required(VERSION VERSION 3.18 FATAL_ERROR)

# Declare a project without languages, so we can use check_langauge to provide a more helpful error message in some cases
project(main LANGUAGES NONE)
# Check for CXX support, which is required
include(CheckLanguage)
check_language(CXX)
if(CMAKE_CXX_COMPILER)
enable_language(CXX)
else()
message(FATAL_ERROR "CXX Language support is required but not found")
endif()
# Check for CUDA support, once the host compiler has already been found.
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else()
# If using MSVC >= 1940 then CUDA <= 12.3 support requires -allow-unsupported-compiler, so warn about this
if(MSVC AND MSVC_VERSION VERSION_GREATER_EQUAL "1940")
# If this is the case, then CMake >= 3.29.4 is also required, otherwise CMake does not pass -allow-unsupported-compiler along, warn as appropriate
if(CMAKE_VERSION VERSION_LESS "3.29.4")
message(FATAL_ERROR
" CUDA Language support detection failed with MSVC ${MSVC_VERSION}\n"
" \n"
" If you have CUDA <= 12.3 installed:\n"
" - You must upgrade CMake to be >= 3.29.4\n"
" The CUDAFLAGS environment variable must include '-allow-unsupported-compiler'\n"
" You must clear the CMake Cache before reconfiguring this project\n"
" \n"
" - Alternatively you may upgrade CUDA to >= 12.4 and clear the CMake Cache before reconfiguring"
)
else()
message(FATAL_ERROR
" CUDA Language support detection failed with MSVC ${MSVC_VERSION}\n"
" \n"
" If you have CUDA <= 12.3 installed:\n"
" - The CUDAFLAGS environment variable must include '-allow-unsupported-compiler'\n"
" You must clear the CMake Cache before reconfiguring this project\n"
" \n"
" - Alternatively you may upgrade CUDA to >= 12.4 and clear the CMake Cache before reconfiguring"
)
endif()
endif()
# CUDA support is required
message(FATAL_ERROR "CUDA Language support is required but not found")
endif()

# Set a default build type if not passed
set(default_build_type "Release")
Expand Down

0 comments on commit 7a683dc

Please sign in to comment.