project(vir_data_process)
cmake_minimum_required(VERSION 2.8)
add_compile_options(-std=c++11)
#include_directories(/usr/local/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/opencv-3.2.0/include)
include_directories(${CMAKE_SOURCE_DIR}/include)
#include_directories(/usr/local/cuda/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/cuda/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/darknet/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/protobuf/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/caffe/include)
link_directories("/usr/local/cuda/lib64")
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/cuda/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/caffe/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/opencv-3.2.0/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/darknet/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/protobuf/lib)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/opencv-3.2.0/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/caffe/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/boost_1_59_0)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/protobuf/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/darknet/include)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/zlog/include)
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/source)
include_directories(${CMAKE_SOURCE_DIR}/samples/result_decoding)
include_directories(${CMAKE_SOURCE_DIR}/3rdParty/cuda/include)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/protobuf/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/cairo/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/freetype /lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/opencv-3.2.0/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/darknet/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/zlog/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/cuda/lib)
link_directories(${CMAKE_SOURCE_DIR}/3rdParty/caffe/lib)
aux_source_directory(${CMAKE_SOURCE_DIR}/utility src_utility)
aux_source_directory(${CMAKE_SOURCE_DIR}/yolo src_yolo)
#aux_source_directory(${CMAKE_SOURCE_DIR}/include src_include)
aux_source_directory(${CMAKE_SOURCE_DIR}/ssd src_ssd)
aux_source_directory(${CMAKE_SOURCE_DIR}/lstm src_lstm)
aux_source_directory(${CMAKE_SOURCE_DIR}/cls src_cls)
add_library(alg_vir_sdk SHARED ${yolo} ${src_utility} ${src_yolo} ${src_ssd} ${src_cls} ${src_lstm})
FILE(GLOB_RECURSE Includefiles ${CMAKE_SOURCE_DIR}/include/*.h)
FILE(GLOB_RECURSE Includeutility ${CMAKE_SOURCE_DIR}/utility/*.h)
FILE(GLOB_RECURSE Includeyolo ${CMAKE_SOURCE_DIR}/yolo/*.h)
FILE(GLOB_RECURSE Includessd ${CMAKE_SOURCE_DIR}/ssd/*.h)
FILE(GLOB_RECURSE Includelstm ${CMAKE_SOURCE_DIR}/lstm/*.h)
FILE(GLOB_RECURSE Includecls ${CMAKE_SOURCE_DIR}/cls/*.h)
add_custom_target(whatever SOURCES
${Includefiles}
${Includeutility}
${Includeyolo}
${Includessd}
${Includelstm}
${Includecls})
target_link_libraries(alg_vir_sdk darknet cudnn cuda opencv_core
opencv_highgui opencv_imgproc opencv_imgcodecs
opencv_video opencv_videoio boost_system boost_thread boost_filesystem
opencv_core opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_features2d opencv_calib3d opencv_objdetect opencv_imgcodecs opencv_videoio
opencv_flann boost_serialization boost_system boost_filesystem glog caffe hdf5 hdf5_hl boost_thread protobuf atlas cublas cudart culibos curand cudnn
ssl3 pthread dl rt boost_system boost_filesystem)
#set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_BUILD_TYPE Debug)
#set(CMAKE_BUILD_TYPE Release)
add_executable(vir_data_process main.cpp ${yolo} ${src_utility} ${yolo} ${ssd} ${cls} ${lstm})
#add_library(libdarknet STATIC IMPORTED)
target_link_libraries(vir_data_process alg_vir_sdk darknet cudnn cuda opencv_core
opencv_highgui opencv_imgproc opencv_imgcodecs
opencv_video opencv_videoio boost_system boost_thread boost_filesystem
opencv_core opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_features2d opencv_calib3d opencv_objdetect opencv_imgcodecs opencv_videoio
opencv_flann boost_serialization boost_system boost_filesystem glog caffe hdf5 hdf5_hl boost_thread protobuf atlas cublas cudart culibos curand cudnn
ssl3 pthread dl rt boost_system boost_filesystem)
install(TARGETS vir_data_process
RUNTIME DESTINATION bin)
对于多级目录,
推荐下载一个看目录的工具
sudo apt-get install tree
tree -a ./fold
比如
.
├── 3rdParty
│ └── caffe
│ └── include
│ └── caffe
│ └── common.hpp
├── cmake
│ └── Dependencies.cmake
├── CMakeLists.txt
├── include
│ └── Alg_VIR_Handheld_Video_Interface.h
├── source
│ ├── CMakeLists.txt
│ ├── common
│ │ ├── common.cpp
│ │ └── include
│ │ └── common.hpp
│ └── debug
│ ├── demonstrate
│ │ ├── demonstrate.cpp
│ │ └── include
│ │ └── demonstrate.hpp
│ └── redis_utils
│ ├── include
│ │ └── redis_utils.hpp
│ └── redis_utils.cpp
└── test
├── CMakeLists.txt
└── redis.cpp
.
├── 3rdParty
│ └── caffe
│ └── include
│ └── caffe
│ └── common.hpp
├── cmake
│ └── Dependencies.cmake
├── CMakeLists.txt
├── include
│ └── Alg_VIR_Handheld_Video_Interface.h
├── source
│ ├── CMakeLists.txt
│ ├── common
│ │ ├── common.cpp
│ │ └── include
│ │ └── common.hpp
│ └── debug
│ ├── demonstrate
│ │ ├── demonstrate.cpp
│ │ └── include
│ │ └── demonstrate.hpp
│ └── redis_utils
│ ├── include
│ │ └── redis_utils.hpp
│ └── redis_utils.cpp
└── test
├── CMakeLists.txt
└── redis.cpp
一个工程里面有这些东西
尤其注意主:
CMakeLists.txt
cmake/Dependencies.cmake
source/Dependencies.cmake
test/CMakeLists.txt
主CMakeLists.txt可以促使头文件全局有效,但source/Dependencies.cmake里面的头文件比如test/redis.cpp是不能直接引用,需要绝对路径,但是强制引用会把source/里面的引用搞得一塌糊涂,所以需要引用source 里面的头文件的内容,就直接include注册在主CMakeLists.txt里面,比如3rdParty里面的全部在。
主CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
SET(CMAKE_EXE_LINKER_FLAGS " -no-pie")
set(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/source/common/include)
include_directories(${CMAKE_SOURCE_DIR}/source/debug/redis_utils/include)
# ---[ Dependencies
include(cmake/Dependencies.cmake)
add_subdirectory(source)
add_subdirectory(test)
cmake/Dependencies.cmake里面主要负责3rdParty的引用,然后再连到主CMakeLists.txt,利用这句
# ---[ Dependencies
include(cmake/Dependencies.cmake)
cmake/Dependencies.cmake内容,非常简单
# protobuf
set(PROTOBUF_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/protobuf)
include_directories(${PROTOBUF_ROOT}/include)
link_directories(${PROTOBUF_ROOT}/lib)
# cuda
set(CUDA_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/cuda_100)
include_directories(${CUDA_ROOT}/include)
link_directories(${CUDA_ROOT}/lib)
link_directories(${CUDA_ROOT}/lib/stubs)
# opencv
set(OPENCV_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/opencv-3.4.10)
include_directories(${OPENCV_ROOT}/include)
link_directories(${OPENCV_ROOT}/lib)
# caffe
set(CAFFE_ROOT ${CMAKE_SOURCE_DIR}/3rdParty/caffe_cuda100)
include_directories(${CAFFE_ROOT}/include)
link_directories(${CAFFE_ROOT}/lib)
source/Dependencies.cmake
test/CMakeLists.txt
利用这句代码连到工程
add_subdirectory(source)
add_subdirectory(test)
test/CMakeLists.txt内容:包含一个可执行文件目标
# set the test link libs
SET(CMAKE_EXE_LINKER_FLAGS " -no-pie")
add_compile_options(-std=c++11)
#link_directories(${CMAKE_SOURCE_DIR}/3rdParty/redisLib)
add_executable(redis redis.cpp)
target_link_libraries(redis handheld_video libavv_alg_redis.a libhiredis.a)
add_executable(testModel testModel.cpp)
target_link_libraries(testModel handheld_video)
source/Dependencies.cmake:包含一个编译的算法库,和另一个可执行文件目标(注因为主函数被写在source里面,本例忘记把文件在上文中加入了,还望海涵)
cmake_minimum_required(VERSION 3.5.0)
project(handheld_video)
SET(CMAKE_EXE_LINKER_FLAGS " -no-pie")
# set the common link libs
list(APPEND HANDHELD_VIDEO_LINK_LIBS cuda)
list(APPEND HANDHELD_VIDEO_LINK_LIBS nvrtc)
list(APPEND HANDHELD_VIDEO_LINK_LIBS boost_date_time)
aux_source_directory(${CMAKE_SOURCE_DIR}/source/common common_src)
aux_source_directory(${CMAKE_SOURCE_DIR}/source/debug/redis_utils redis_utils_src)
aux_source_directory(${CMAKE_SOURCE_DIR}/source/debug/demonstrate demonstrate_src)
add_library(handheld_video SHARED
${common_src}
${redis_utils_src}
${demonstrate_src}
../include/Alg_VIR_Handheld_Video_Interface.h ../source/api/Alg_VIR_Handheld_Video_Interface.cpp)
target_link_libraries(handheld_video ${TORCH_LIBRARIES} ${HANDHELD_VIDEO_LINK_LIBS})
add_executable(redisBaoDing app/redis/redis.cpp)
target_link_libraries(redisBaoDing handheld_video )