|
| 1 | +# 指定 cmake版本 |
| 2 | +# 指定 project name |
| 3 | +# 指定生成文件的输出目录 |
| 4 | +cmake_minimum_required(VERSION 2.8) |
| 5 | +project(project_name) |
| 6 | + |
| 7 | +message("-- system arch: ${CMAKE_SYSTEM_PROCESSOR}") |
| 8 | +message("-- output path: ${PROJECT_OUTPUT_DIR} ") |
| 9 | + |
| 10 | +# set output path |
| 11 | +set(PROJECT_OUTPUT_DIR ${PROJECT_BINARY_DIR}/${CMAKE_SYSTEM_PROCESSOR}) |
| 12 | +SET(PROJECT_INCLUDE_DIR ${PROJECT_OUTPUT_DIR}/include) |
| 13 | + |
| 14 | +# mkdir directory |
| 15 | +file(MAKE_DIRECTORY ${PROJECT_INCLUDE_DIR}) |
| 16 | +FILE(MAKE_DIRECTORY ${PROJECT_OUTPUT_DIR}/bin) |
| 17 | +FILE(MAKE_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib) |
| 18 | + |
| 19 | +## set the target path |
| 20 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/bin) |
| 21 | +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib) |
| 22 | +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_OUTPUT_DIR}/lib) |
| 23 | + |
| 24 | +# 中间部分-指定工程依赖 |
| 25 | +# 指定工程需要用到的一些系统包和库 |
| 26 | +# 指定依赖的库文件 |
| 27 | + |
| 28 | +find_package(PkgConfig) |
| 29 | + pkg_check_modules(GSTREAMER QUIET gstreamer-1.0) |
| 30 | + pkg_check_modules(GST_APP REQUIRED gstreamer-app-1.0) |
| 31 | + |
| 32 | +find_package(Qt4 REQUIRED) |
| 33 | +find_package(CUDA) |
| 34 | +find_package(OpenGL) |
| 35 | +find_package(OpenCV) |
| 36 | + |
| 37 | +## set c++11 编译选项 |
| 38 | +# -std=c++11 包含C++11特性 |
| 39 | +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
| 40 | + |
| 41 | +## set CUDA NVCC编译选项 |
| 42 | +set( |
| 43 | + CUDA_NVCC_FLAGS |
| 44 | + ${CUDA_NVCC_FLAGS}; |
| 45 | + -O3 |
| 46 | + -gencode arch=compute_53,code=sm_53 |
| 47 | + -gencode arch=compute_62,code=sm_62 ##TX2 |
| 48 | + -gencode arch=compute_30,code=sm_30 |
| 49 | +) |
| 50 | + |
| 51 | +# INCLUDE for c/C++ include |
| 52 | +include_directories(${PROJECT_INCLUDE_DIR}) |
| 53 | +include_directories( |
| 54 | + /usr/include/gstreamer-1.0 |
| 55 | + /usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/gstreamer-1.0/include |
| 56 | + /usr/include/glib-2.0 |
| 57 | + /usr/include/libxml2 /usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/glib-2.0/include |
| 58 | + /usr/include/opencv2 |
| 59 | +) |
| 60 | + |
| 61 | +# 结尾部分-指定输出文件 |
| 62 | + |
| 63 | +#create executable-file |
| 64 | +add_executable(exe-filename needed-C_or_C++file) |
| 65 | + |
| 66 | +#create shared-library |
| 67 | +add_library(lib-filename SHARED needed-files-list) |
| 68 | + |
| 69 | +## CUDA 版本 |
| 70 | +cuda_add_executable(exe-filename needed-cu_file) |
| 71 | +cuda_add_library(lib-filename SHARED needed-cu_files-list) |
| 72 | + |
| 73 | +## 对于有多个文件可以先创建一个变量 file-list |
| 74 | +file(GLOB gstcam_source lib/gstreamer/*cpp lib/image/*cpp lib/cuda/*cpp lib/cuda/*cu lib/opengl/*cpp ) |
| 75 | +file(GLOB gstcam_include lib/gstreamer/*h lib/image/*h lib/cuda/*h lib/opengl/*h) |
| 76 | + |
| 77 | +## 循环打印一下看看 |
| 78 | +foreach(sources ${gstcam_source}) |
| 79 | +MESSAGE("-- the ${PROJECT_NAME} contion ${sources}") |
| 80 | +endforeach(sources ${}) |
| 81 | + |
| 82 | + |
| 83 | +## creat gstcam shared library |
| 84 | +cuda_add_library(${PROJECT_NAME} SHARED ${gstcam_source}) |
| 85 | +target_link_libraries(${PROJECT_NAME} Qt4::QtGui GL GLEW gstreamer-1.0 gstapp-1.0 ${OpenCV_LIBS}) |
| 86 | + |
| 87 | +# transfer all headers to the include directory |
| 88 | +foreach(include ${gstcam_include}) |
| 89 | + message("-- Copying ${include}") |
| 90 | + configure_file(${include} ${PROJECT_INCLUDE_DIR} COPYONLY) |
| 91 | +endforeach() |
| 92 | + |
| 93 | +## create exe-file |
| 94 | +add_executable(gst_app_test src/gst-camera.cpp) |
| 95 | +target_link_libraries(gst_app_test ${PROJECT_NAME}) |
| 96 | + |
0 commit comments