Skip to content

[fix] CMake 3.31+ breaks OpenMP detection in CUDA projects (issue #333)#415

Open
edenfunf wants to merge 1 commit intoNVIDIA:masterfrom
edenfunf:fix/openmp-cmake-cuda-language-detection
Open

[fix] CMake 3.31+ breaks OpenMP detection in CUDA projects (issue #333)#415
edenfunf wants to merge 1 commit intoNVIDIA:masterfrom
edenfunf:fix/openmp-cmake-cuda-language-detection

Conversation

@edenfunf
Copy link
Copy Markdown

@edenfunf edenfunf commented Apr 3, 2026

What's the problem

CMake 3.31 added support for finding OpenMP in the CUDA language. When find_package(OpenMP) (or find_package(OpenMP REQUIRED)) is called inside a project that declares LANGUAGES C CXX CUDA, CMake now also tries to find OpenMP for CUDA. That lookup fails on most setups because nvcc doesn't expose OpenMP the same way GCC/Clang does:

CMake Error at .../FindPackageHandleStandardArgs.cmake:233 (message):
  Could NOT find OpenMP_CUDA (missing: OpenMP_CUDA_FLAGS OpenMP_CUDA_LIB_NAMES)
Call Stack:
  Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txt:21 (find_package)

This hits anyone on CMake >= 3.31 building UnifiedMemoryStreams (and potentially cudaOpenMP) on Linux.

Steps to reproduce

cmake -S . -B build   # CMake >= 3.31 required

Error appears when CMake processes Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txt.

What I changed

Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txt

The Visual Studio branch already had find_package(OpenMP REQUIRED C CXX) — the non-VS branch was missing the language restriction. Since both cases want the same thing, I collapsed the if/else into a single call with C CXX specified:

# before
if(CMAKE_GENERATOR MATCHES "Visual Studio")
    find_package(OpenMP REQUIRED C CXX)
else()
    find_package(OpenMP REQUIRED)
endif()

# after
find_package(OpenMP REQUIRED C CXX)

Samples/0_Introduction/cudaOpenMP/CMakeLists.txt

Same root cause. find_package(OpenMP) without components in a CUDA project will attempt CUDA OpenMP detection on CMake 3.31+. Added C CXX here too:

# before
find_package(OpenMP)

# after
find_package(OpenMP C CXX)

Why this is safe

Specifying C CXX explicitly tells CMake "only look for OpenMP for these two languages." This is exactly what these samples need — they link against OpenMP::OpenMP_CXX and never use CUDA OpenMP. The behavior is identical on CMake < 3.31 since CUDA was not a recognized OpenMP language before that version.

Impact

Only affects the two sample CMakeLists files. No source code changes, no behavior change at runtime. Doesn't touch any other samples.

Fixes #333

CMake 3.31 added support for finding OpenMP in CUDA projects. When
find_package(OpenMP) or find_package(OpenMP REQUIRED) is called inside
a project declared with LANGUAGES C CXX CUDA, CMake now also attempts
to find OpenMP for the CUDA language. This fails on most toolchains
since nvcc does not support OpenMP in the same way, causing:

  Could NOT find OpenMP_CUDA (missing: OpenMP_CUDA_FLAGS OpenMP_CUDA_LIB_NAMES)

Fix by explicitly restricting the OpenMP search to C and CXX languages
in both affected samples (UnifiedMemoryStreams and cudaOpenMP). This
matches the existing behavior on pre-3.31 CMake and avoids the spurious
CUDA component detection.

Fixes NVIDIA#333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CMake Configuration Fails with OpenMP_CUDA Not Found

1 participant