From 83df18f3b49783ca8364d8d42cc6f34508511eed Mon Sep 17 00:00:00 2001 From: edenfunf Date: Fri, 3 Apr 2026 21:52:38 +0800 Subject: [PATCH] fix(cmake): restrict OpenMP language search to C/CXX in CUDA projects 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 #333 --- Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txt | 6 +----- Samples/0_Introduction/cudaOpenMP/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txt b/Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txt index b86e9cb12..aad59df8c 100644 --- a/Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txt +++ b/Samples/0_Introduction/UnifiedMemoryStreams/CMakeLists.txt @@ -26,11 +26,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "QNX") endif() # Source file -if(CMAKE_GENERATOR MATCHES "Visual Studio") - find_package(OpenMP REQUIRED C CXX) -else() - find_package(OpenMP REQUIRED) -endif() +find_package(OpenMP REQUIRED C CXX) if(${OpenMP_FOUND}) # Add target for UnifiedMemoryStreams diff --git a/Samples/0_Introduction/cudaOpenMP/CMakeLists.txt b/Samples/0_Introduction/cudaOpenMP/CMakeLists.txt index 991936c12..24eaf6308 100644 --- a/Samples/0_Introduction/cudaOpenMP/CMakeLists.txt +++ b/Samples/0_Introduction/cudaOpenMP/CMakeLists.txt @@ -19,7 +19,7 @@ endif() # Include directories and libraries include_directories(../../../Common) -find_package(OpenMP) +find_package(OpenMP C CXX) # Source file if(OpenMP_CXX_FOUND)