CMake使用的一些基本操作
cmake cookbook
https://chenxiaowei.gitbook.io/cmake-cookbook/5.0-chinese/5.6-chinese
cuda 模板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| project(test_cuda_project)
cmake_minimum_required(VERSION 2.8)
find_package(CUDA)
if(${CUDA_FOUND}) include_directories(${CUDA_INCLUDE_DIRS}) link_directories($ENV{CUDA_PATH}/lib/x64) else(${CUDA_FOUND}) MESSAGE(STATUS "cuda not found!") endif(${CUDA_FOUND}) FIND_PACKAGE( OpenMP REQUIRED) if(OPENMP_FOUND) message("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()
INCLUDE_DIRECTORIES(/usr/local/cuda/samples/common/inc) INCLUDE_DIRECTORIES(/usr/local/cuda/include) INCLUDE_DIRECTORIES(/usr/local/cuda/include)
set_source_files_properties(test.cpp PROPERTIES CUDA_SOURCE_PROPERTY_FORMAT OBJ) file(GLOB_RECURSE CURRENT_HEADERS *.h *.hpp *.cuh) file(GLOB CURRENT_SOURCES *.cpp *.cu .cc) source_group("Include" FILES ${CURRENT_HEADERS}) source_group("Source" FILES ${CURRENT_SOURCES}) link_directories( /usr/local/cuda/lib64 ) CUDA_ADD_EXECUTABLE(test ${CURRENT_HEADERS} ${CURRENT_SOURCES})
target_link_libraries(test cudart)
|
Normal project
1 2 3 4 5 6 7 8 9 10
| cmake_minimum_required(VERSION 2.8) PROJECT (HELLO)
AUX_SOURCE_DIRECTORY(. SRC_LIST) add_definitions("-Wall -std=c++11") MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR}) MESSAGE(STATUS "This is SOURCE dir " ${HELLO_SOURCE_DIR})
set(SOURCES math/circle.cpp ./container.cpp) ADD_EXECUTABLE(container ${SRC_LIST} ./math/circle.cpp)
|
选择windows studio指定版本编译
1
| cmake -G "Visual Studio 14 2015 Win64" ..
|