在Cmake项目中指定openmp CUDA标志

时间:2012-02-16 15:03:35

标签: cuda cmake openmp

如何在cmake项目中将openmp标志传递给NVCC? 我的这个项目的CMakeLists.txt看起来像这样,但编译失败,“未定义引用`omp_get_wtime'”消息。

cmake_minimum_required (VERSION 2.8.2)

set (CMAKE_MODULE_PATH 
  "${CMAKE_SOURCE_DIR}/cmake" 
  ${CMAKE_MODULE_PATH}
)

find_package (CUDA 4.0 REQUIRED)

if(OPENMP_FOUND)
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}
${OpenMP_EXE_LINKER_FLAGS}") endif()

set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)

if(UNIX)
  add_definitions(-DUNIX)
endif(UNIX)

add_subdirectory(xor)

CUDA_BUILD_CLEAN_TARGET()

1 个答案:

答案 0 :(得分:2)

我刚刚发现将find_package(OpenMP)添加到上一个脚本就可以了。