forked from rjdmoore/fictrac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
136 lines (116 loc) · 4.65 KB
/
CMakeLists.txt
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
cmake_minimum_required (VERSION 3.0)
project (FicTrac)
# The version number.
set (FICTRAC_VERSION_MAJOR 2)
set (FICTRAC_VERSION_MINOR 0)
# output version info to be included by project
configure_file (
"${PROJECT_SOURCE_DIR}/include/fictrac_version.h.in"
"${PROJECT_SOURCE_DIR}/include/fictrac_version.h"
)
# dependency search dirs
set(OPENCV_DIR "." CACHE PATH "Path to OpenCV folder containing OpenCVConfig.cmake")
set(NLOPT_DIR "." CACHE PATH "Path to NLOpt folder containing libnlopt-0.lib")
# output dirs
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
# optional build config
option(PGR_USB3 "Use Spinnaker SDK to capture from PGR USB3 cameras" OFF) # Disabled by default
if(PGR_USB3)
set(PGR_DIR "." CACHE PATH "Path to PGR Spinnaker SDK folder")
endif()
# find dependencies
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${OPENCV_DIR} ${NLOPT_DIR})
if(MSVC)
find_package(opencv)
find_library(NLOPT_LIB libnlopt-0.lib)
if(PGR_USB3)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PGR_DIR}/lib64/vs2015)
find_library(PGR_LIB Spinnaker_v140.lib)
endif()
else() # gcc
find_package(OpenCV)
find_library(NLOPT_LIB libnlopt.a)
if(PGR_USB3)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PGR_DIR}) # fixme!
find_library(PGR_LIB libSpinnaker.so) # fixme!
endif()
endif()
get_filename_component(NLOPT_DIR ${NLOPT_LIB} DIRECTORY)
if(NLOPT_LIB)
message(STATUS "Found NLOpt lib ${NLOPT_LIB}")
if(MSVC)
message(STATUS "You might need to add ${NLOPT_DIR} to your PATH to be able to run the executable.")
endif()
else()
message(FATAL_ERROR "Error! Could not find NLOpt lib at ${NLOPT_DIR}!")
endif()
if(PGR_USB3)
if(PGR_LIB)
message(STATUS "Found PGR Spinnaker lib ${PGR_LIB}")
else()
message(FATAL_ERROR "Error! Could not find PGR Spinnaker lib at ${PGR_DIR}!")
endif()
endif()
# add include dirs
include_directories(${PROJECT_SOURCE_DIR}/include ${OpenCV_INCLUDE_DIRS} ${NLOPT_DIR})
if(PGR_USB3)
include_directories(${PGR_DIR}/include/spinnaker)
endif()
# find sources to build
file(GLOB LIBFICTRAC_SRCS ${PROJECT_SOURCE_DIR}/src/*.cpp)
# add targets
add_library(libfictrac STATIC ${LIBFICTRAC_SRCS})
add_executable(configGui ${PROJECT_SOURCE_DIR}/exec/configGui.cpp)
add_executable(fictrac ${PROJECT_SOURCE_DIR}/exec/fictrac.cpp)
# add preprocessor definitions
# public means defs will be inherited by linked executables
target_compile_definitions(libfictrac PUBLIC _CRT_SECURE_NO_WARNINGS NOMINMAX)
if(PGR_USB3)
target_compile_definitions(libfictrac PUBLIC PGR_USB3)
endif()
# add compile options
if(MSVC)
target_compile_options(libfictrac PUBLIC $<$<CONFIG:Release>:/MP /GS /GL /W3 /WX- /Gy /Zc:wchar_t /O2 /Oi /Zc:inline /fp:precise /MD /EHsc>)
else() # gcc
target_compile_options(libfictrac PUBLIC -Ofast -Wall -c -fmessage-length=0 -std=c++14 -Wno-unused-function -march=native -MMD)
endif()
# linking and post-build
target_link_libraries(libfictrac PUBLIC ${OpenCV_LIBS} ${NLOPT_LIB})
if(PGR_USB3)
target_link_libraries(libfictrac PUBLIC ${PGR_LIB})
endif()
if(MSVC)
# win-specific libraries
target_link_libraries(libfictrac PUBLIC Ws2_32)
# copy all opencv dlls
set(OPENCV_VER_STRING ${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH})
foreach(lib ${OpenCV_LIBS})
if(EXISTS "${_OpenCV_LIB_PATH}/${lib}${OPENCV_VER_STRING}.dll")
list(APPEND TO_COPY "${_OpenCV_LIB_PATH}/${lib}${OPENCV_VER_STRING}.dll" "${_OpenCV_LIB_PATH}/${lib}${OPENCV_VER_STRING}d.dll")
endif()
endforeach()
set(FFMPEG_LIB_BASE opencv_ffmpeg${OPENCV_VER_STRING})
if(${OpenCV_ARCH} STREQUAL x64)
set(FFMPEG_LIB ${FFMPEG_LIB_BASE}_64.dll)
else()
set(FFMPEG_LIB ${FFMPEG_LIB_BASE}.dll)
endif()
list(APPEND TO_COPY "${_OpenCV_LIB_PATH}/${FFMPEG_LIB}")
# copy nlopt dll
list(APPEND TO_COPY "${NLOPT_DIR}/libnlopt-0.dll")
# copy h264 dll
list(APPEND TO_COPY "${PROJECT_SOURCE_DIR}/dll/openh264-1.7.0-win64.dll")
add_custom_command( TARGET fictrac POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TO_COPY}
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug>/")
else() # gcc
# socket libs, pthread
target_link_libraries(libfictrac PUBLIC pthread)
endif()
target_link_libraries(configGui libfictrac)
add_dependencies(configGui libfictrac)
target_link_libraries(fictrac libfictrac)
add_dependencies(fictrac libfictrac)