forked from HesselM/flashcam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·166 lines (129 loc) · 6.19 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
cmake_minimum_required (VERSION 2.8.11)
project(flashcam)
option(TEST_CAP "compile for capture-mode testing" OFF)
option(TEST_VID "compile for video-mode streaming testing" OFF)
option(TEST_VID_OPENGL "compile for video-mode streaming testing with OpenGL rendering" OFF)
option(TEST_VID_FRAMECAPTURE "compile for video-mode testing. Frames are recorded with a keypress." OFF)
option(TEST_VID_OPENGL_FRAMECAPTURE "compile for video-mode streaming testing with OpenGL rendering. Frames are recorded with a keypress." OFF)
option(TEST_PLL_TUNE "compile for PLL tuning" OFF)
option(TEST_PLL_STEPRESPONSE "compile for PLL stepresponse recording" OFF)
set(CMAKE_CXX_FLAGS "-fpermissive -std=c++11 ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-fpermissive -std=c++11 ${CMAKE_C_FLAGS}")
# Main sources for FlashCam-lib
set(FLASHCAM_SOURCES FlashCam.cpp FlashCam_types.cpp util/FlashCam_util_mmal.cpp)
#include required packages
find_package( Threads REQUIRED )
find_package( PkgConfig REQUIRED )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
# MMAL
pkg_search_module( MMAL REQUIRED mmal )
include_directories( ${MMAL_INCLUDE_DIRS} )
link_directories( ${MMAL_LIBRARY_DIRS} )
# BCM_HOST
pkg_search_module( BCMHOST REQUIRED bcm_host )
include_directories( ${BCMHOST_INCLUDE_DIRS} )
link_directories( ${BCMHOST_LIBRARY_DIRS} )
# EGL -> optional (required for OpenGL rendering)
pkg_search_module(EGL egl)
if (EGL_FOUND)
include_directories(${EGL_INCLUDE_DIRS})
link_directories(${EGL_LIBRARY_DIRS} )
#add OpenGL sources
add_definitions( -DBUILD_FLASHCAM_WITH_OPENGL )
set(FLASHCAM_SOURCES opengl/FlashCam_opengl.cpp;
util/FlashCam_util_opengl.cpp;
${FLASHCAM_SOURCES})
message(">> Found EGL: including OpenGL functions in build")
else()
message(">> Did not found EGL: OpenGL functions and tests are disabled")
endif()
# WiringPi -> optional (required for PLL)
pkg_search_module( WIRINGPI wiringpi )
if (WIRINGPI_FOUND)
include_directories( ${WIRINGPI_INCLUDE_DIRS} )
link_directories( ${WIRINGPI_LIBRARY_DIRS} )
#add PLL sources
add_definitions( -DBUILD_FLASHCAM_WITH_PLL )
set(FLASHCAM_SOURCES pll/FlashCam_pll.cpp;
${FLASHCAM_SOURCES})
message(">> Found WiringPi: including PLL functions in build")
else()
message(">> Did not found WiringPi: PLL functions and tests are disabled")
endif()
# Userland -> if not set via commandline or toolchain, set default value.
if (NOT USERLAND_DIR)
message(">> Setting default USERLAND_DIR: /usr/src/userland")
set(USERLAND_DIR "/usr/src/userland")
endif()
include_directories(${USERLAND_DIR})
include_directories(${USERLAND_DIR}/host_applications/linux/libs/sm)
# Projectdirs
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/pll)
include_directories(${CMAKE_SOURCE_DIR}/opengl)
include_directories(${CMAKE_SOURCE_DIR}/tests)
include_directories(${CMAKE_SOURCE_DIR}/util)
# Which test?
if (TEST_CAP)
set(FLASHCAM_SOURCES tests/FlashCam_test_cap.cpp; ${FLASHCAM_SOURCES})
message(">> Building for capture-mode testing. (TEST_CAP=ON)")
elseif (TEST_VID)
set(FLASHCAM_SOURCES tests/FlashCam_test_vid.cpp; ${FLASHCAM_SOURCES})
message(">> Building for video-mode stream testing. (TEST_VID=ON)")
elseif (TEST_VID_FRAMECAPTURE)
set(FLASHCAM_SOURCES tests/FlashCam_test_vid_framecapture.cpp; ${FLASHCAM_SOURCES})
message(">> Building for video-mode stream testing. Frames are recorded with a keypress. (TEST_VID_FRAMECAPTURE=ON)")
elseif (TEST_VID_OPENGL AND EGL_FOUND)
set(FLASHCAM_SOURCES tests/FlashCam_test_vid_opengl.cpp; ${FLASHCAM_SOURCES})
message(">> Building for video-mode stream testing with OpenGL rendering. (TEST_VID_OPENGL=ON)")
elseif (TEST_VID_OPENGL_FRAMECAPTURE AND EGL_FOUND)
set(FLASHCAM_SOURCES tests/FlashCam_test_vid_framecapture.cpp; ${FLASHCAM_SOURCES})
message(">> Building for video-mode stream testing with OpenGL rendering. Frames are recorded with a keypress. (TEST_VID_OPENGL_FRAMECAPTURE=ON)")
elseif (TEST_PLL_TUNE AND WIRINGPI_FOUND)
add_definitions( -DPLLTUNE )
set(FLASHCAM_SOURCES tests/FlashCam_test_pll_tune.cpp; util/FlashCam_util_terminal.cpp; ${FLASHCAM_SOURCES})
message(">> Building for PLL tuning. (TEST_PLL_TUNE=ON)")
elseif (TEST_PLL_STEPRESPONSE AND WIRINGPI_FOUND)
add_definitions( -DPLLTUNE )
add_definitions( -DSTEPRESPONSE )
set(FLASHCAM_SOURCES tests/FlashCam_test_pll_tune.cpp; util/FlashCam_util_terminal.cpp; ${FLASHCAM_SOURCES})
message(">> Building for PLL stepresponse recording. (TEST_PLL_STEPRESPONSE=ON)")
endif()
# Executables
add_executable(flashcam ${FLASHCAM_SOURCES})
# Libraries
target_link_libraries(flashcam ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(flashcam ${OpenCV_LIBS} )
target_link_libraries(flashcam ${MMAL_LIBRARIES})
target_link_libraries(flashcam ${BCMHOST_LIBRARIES})
target_link_libraries(flashcam m)
if (EGL_FOUND)
target_link_libraries(flashcam ${EGL_LIBRARIES})
endif()
if (WIRINGPI_FOUND)
target_link_libraries(flashcam ${WIRINGPI_LIBRARIES})
endif()
# Print output.
function(removeDuplicateSubstring stringIn stringOut)
separate_arguments(stringIn)
list(REMOVE_DUPLICATES stringIn)
string(REPLACE ";" " " stringIn "${stringIn}")
set(${stringOut} "${stringIn}" PARENT_SCOPE)
endfunction()
#remove duplicates
string(REPLACE "-isystem /" "-isystem-/" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "-isystem /" "-isystem-/" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
removeDuplicateSubstring(${CMAKE_CXX_FLAGS} CMAKE_CXX_FLAGS)
removeDuplicateSubstring(${CMAKE_C_FLAGS} CMAKE_C_FLAGS)
string(REPLACE "-isystem-/" "-isystem /" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "-isystem-/" "-isystem /" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
#make it pretty
string(REPLACE " -" "\n\t-" PRETTY_CMAKE_CXX_FLAGS "\t${CMAKE_CXX_FLAGS}")
string(REPLACE " -" "\n\t-" PRETTY_CMAKE_C_FLAGS "\t${CMAKE_C_FLAGS}")
list( SORT FLASHCAM_SOURCES)
string(REPLACE ";" "\n\t- " PRETTY_FLASHCAM_SOURCES "\t- ${FLASHCAM_SOURCES}")
#show result
message(">> Used CXX flags: \n ${PRETTY_CMAKE_CXX_FLAGS}")
message(">> Used C flags: \n ${PRETTY_CMAKE_C_FLAGS}")
message(">> Source List: \n ${PRETTY_FLASHCAM_SOURCES}")