- CMake配置cuda
- 方法1:
- 方法2:
- CMake配置opengl
- vcpkg的使用
- vcpkg的编译问题与解决
- vcpkg工具使用时,下载缓慢
- vcpkg编译卡死的问题
- CMakeLists.txt中的设置示例
- Qt Creator 中配置vcpkg【不建议使用】
CMake配置cuda 方法1:
cmake_minimum_required(VERSION 3.8)
project(TestVectors LANGUAGES CXX CUDA)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-extended-lambda -gencode arch=compute_61,code=sm_61")
#set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-extended-lambda -gencode arch=compute_61,code=sm_61 -G -g")
add_definitions(-D __CUDACC__)
add_executable(${PROJECT_NAME} kernel.cu)
# cuda核函数调用核函数
set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(${PROJECT_NAME} cudadevrt)
方法2:
find_package(CUDA REQUIRED)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_61,code=sm_61;--expt-extended-lambda;)
#set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_61,code=sm_61;--expt-extended-lambda;-G;-g;)
set(CUDA_SEPARABLE_COMPILATION ON)
cuda_add_executable(${PROJECT_NAME} kernel.cu)
target_link_libraries(${PROJECT_NAME} ${CUDA_LIBRARIES} ${CUDA_cudadevrt_LIBRARY})
CMake配置opengl
cmake_minimum_required(VERSION 2.8)
project(LearnGL)
if(CMAKE_HOST_WIN32)
set(WINDOWS 1)
endif()
# Add search path for include and lib files
set(FREEGLUT_DIR "E:/BookExamp/SB5/freeglut-3.0.0")
INCLUDE_DIRECTORIES("${FREEGLUT_DIR}/include")
if(CMAKE_BUILD_TYPE MATCHES "Debug")
LINK_DIRECTORIES("${FREEGLUT_DIR}/lib/Debug")
elseif(CMAKE_BUILD_TYPE MATCHES "Release")
LINK_DIRECTORIES("${FREEGLUT_DIR}/lib/Release")
endif()
add_executable(${PROJECT_NAME} "main.cpp")
if(CMAKE_BUILD_TYPE MATCHES "Debug")
target_link_libraries(${PROJECT_NAME} "freeglutd")
elseif(CMAKE_BUILD_TYPE MATCHES "Release")
target_link_libraries(${PROJECT_NAME} "freeglut")
endif()
# 拷贝dll文件到程序输出目录
if(WINDOWS)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${FREEGLUT_DIR}/lib/Debug/freeglutd.dll"
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
elseif(CMAKE_BUILD_TYPE MATCHES "Release")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${FREEGLUT_DIR}/lib/Release/freeglut.dll"
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
endif()
endif()
vcpkg的使用
vcpkg的编译问题与解决
vcpkg工具使用时,下载缓慢
vcpkg编译卡死的问题可以手动下载,然后放到downloads目录中,注意文件改名
- vcpkg 只下载不编译 --only-downloads
- vcpkg 避免清除 --editable
编译库需要考虑cpu核心个数和内存的关系,例如4核一般配8G,大致按照这个比例。
编译时使用的内存一定不能超出,超出后会放到交换空间,整个系统都会卡死,原则上是不使用交换空间。
CMakeLists.txt中的设置示例
- opencl
find_package(OpenCL REQUIRED)
target_link_libraries(main PRIVATE ${OpenCL_LIBRARIES})
target_include_directories(main PRIVATE ${OpenCL_INCLUDE_DIRS})
# and the CMake v3.7 and beyond imported target syntax
find_package(OpenCL REQUIRED)
target_link_libraries(main PRIVATE OpenCL::OpenCL)
- gsl
find_package(GSL REQUIRED)
target_link_libraries(main PRIVATE GSL::gsl GSL::gslcblas)
Qt Creator 中配置vcpkg【不建议使用】
删除qtcreator配置中的 -DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} 这一行即可
建议使用cmake+vscode配置工程
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)