结合qt与cuda工程的cmakelist

第一种方式,cuda使用find_package:

cmake_minimum_required(VERSION 3.9)
project(untitled1)

find_package(CUDA REQUIRED)

message("CUDA_TOOLKIT_ROOT_DIR: ${CUDA_TOOLKIT_ROOT_DIR}")
message("cuda version: ${CUDA_VERSION_STRING}")

include_directories(
    ${CUDA_INCLUDE_DIRS}
    ${CUDA_TOOLKIT_ROOT_DIR}/samples/common/inc
)

set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -std=c++11 -gencode arch=compute_61,code=sm_61 -DNDEBUG")
message("CMAKE_CUDA_FLAGS: ${CMAKE_CUDA_FLAGS}")


set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(QT_DIR "/opt/Qt5.12.0")
set(QT_SUB_DIR "5.12.0")
find_package(Qt5 COMPONENTS Widgets Gui OpenGL HINTS ${QT_DIR}/${QT_SUB_DIR}/gcc_64/lib/cmake/Qt5)


set(CMAKE_CXX_STANDARD 11)

set(INCLUDE_FILES

    )
set(SOURCE_FILES
    main.cpp
    main_test.cu
    )
CUDA_ADD_EXECUTABLE(untitled1 ${SOURCE_FILES} ${INCLUDE_FILES})
target_link_libraries(untitled1
    Qt5::Widgets
    ${CUDA_LIBRARIES}
    ${CUDA_cudadevrt_LIBRARY}
    )

第二种方式,使用cmake的CUDA language:

cmake_minimum_required(VERSION 3.9)
project(untitled CUDA CXX)

include_directories(
    /usr/local/cuda/samples/common/inc
    /usr/local/cuda/include
)

set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_61,code=sm_61")
message("CMAKE_CUDA_FLAGS: ${CMAKE_CUDA_FLAGS}")

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(QT_DIR "/opt/Qt5.12.0")
set(QT_SUB_DIR "5.12.0")
find_package(Qt5 COMPONENTS Core HINTS ${QT_DIR}/${QT_SUB_DIR}/gcc_64/lib/cmake/Qt5)

set(INCLUDE_FILES
    )
set(SOURCE_FILES
    main.cpp
    main_test.cu
    )

if ( TARGET Qt5::Core )
  get_property( core_options TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_OPTIONS )
  string( REPLACE "-fPIC" "" new_core_options "${core_options}" )
  set_property( TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_OPTIONS ${new_core_options} )
  set_property( TARGET Qt5::Core PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE "ON" )
  set( CMAKE_CXX_COMPILE_OPTIONS_PIE "-fPIC" )
endif()

add_executable(untitled ${SOURCE_FILES} ${INCLUDE_FILES})

target_link_libraries(untitled
Qt5::Core
)

第二种方式要处理编译选项传入问题(nvcc fatal   : Unknown option 'fPIC')。

你可能感兴趣的:(结合qt与cuda工程的cmakelist)