forked from shinsumicco/FBoW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
303 lines (257 loc) · 11.7 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#
# The MIT License
#
# Copyright (c) 2017 Rafael Muñoz-Salinas
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ------------------------------------------------------
# BASIC CONFIGURATION
# ------------------------------------------------------
cmake_minimum_required(VERSION 2.9)
project(fbow CXX C)
if(NOT POLICY CMP0054)
cmake_policy(SET CMO0054 NEW)
endif()
# Disable in-source build
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(PROJECT_VERSION "0.0.1")
string(REGEX MATCHALL "[0-9]" PROJECT_VERSION_PARTS "${PROJECT_VERSION}")
list(GET PROJECT_VERSION_PARTS 0 PROJECT_VERSION_MAJOR)
list(GET PROJECT_VERSION_PARTS 1 PROJECT_VERSION_MINOR)
list(GET PROJECT_VERSION_PARTS 2 PROJECT_VERSION_PATCH)
set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
set(CMAKE_MACOSX_RPATH 1)
# ------------------------------------------------------
# build type
# ------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
# ------------------------------------------------------
# library names and directries
# ------------------------------------------------------
set(PROJECT_DLL_VERSION "${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}${PROJECT_VERSION_PATCH}")
if(WIN32)
set(RUNTIME_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin" CACHE PATH "Directory for dlls and binaries")
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin" CACHE PATH "Directory for binaries")
set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin" CACHE PATH "Directory for DLLs")
else()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_INSTALL_PREFIX}/lib/cmake/" "/usr/lib/cmake" "/usr/local/lib/cmake")
endif()
option(USE_OWN_EIGEN3 "Set to OFF to use a standard eigen3 version" ON)
option(BUILD_UTILS "Set to ON to build utils" OFF)
option(BUILD_TESTS "Set to ON to build tests" OFF)
option(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON)
option(USE_CONTRIB "Set ON to use OpenCV contrib modules" OFF)
option(USE_AVX "Set on/off" ON)
option(USE_SSE3 "Set on/off" ON)
option(USE_SSE4 "Set on/off" ON)
option(INSTALL_FBOW_DEV "Set to OFF to disable source installation" ON)
# ------------------------------------------------------
# find dependencies
# ------------------------------------------------------
find_package(OpenCV 3.0 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
if(USE_CONTRIB)
add_definitions(-DUSE_CONTRIB)
endif()
set(REQUIRED_LIBRARIES "${OpenCV_LIBS}")
# ------------------------------------------------------
# PROJECT CONFIGURATION
# ------------------------------------------------------
# ------------------------------------------------------
# uninstall target for "make uninstall"
# ------------------------------------------------------
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
# ------------------------------------------------------
# create configuration file from .in file
# (if you use windows take care with paths)
# ------------------------------------------------------
configure_file("${PROJECT_SOURCE_DIR}/config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION "share/${PROJECT_NAME}/")
# ------------------------------------------------------
# program optimization and debug options
# ------------------------------------------------------
set(WARNINGS_ARE_ERRORS OFF CACHE BOOL "Treat warnings as errors")
set(EXTRA_C_FLAGS "")
set(EXTRA_C_FLAGS_RELEASE "")
set(EXTRA_C_FLAGS_DEBUG "")
set(EXTRA_EXE_LINKER_FLAGS "")
set(EXTRA_EXE_LINKER_FLAGS_RELEASE "")
set(EXTRA_EXE_LINKER_FLAGS_DEBUG "")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR MINGW)
# profiling option
set(ENABLE_PROFILING OFF CACHE BOOL "Enable profiling in the GCC/Clang compiler (Add flags: -g -pg)")
# option for omitting frame pointer
set(USE_OMIT_FRAME_POINTER ON BOOL "Enable -fomit-frame-pointer for GCC/Clang")
# select optimization level
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES arm*)
# ARM system
set(USE_O2 ON CACHE BOOL "Enable -O2 for GCC/Clang")
set(USE_FAST_MATH OFF CACHE BOOL "Enable -ffast-math for GCC/Clang")
endif()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES powerpc*)
# PowerPC system
set(USE_O3 ON CACHE BOOL "Enable -O3 for GCC/Clang")
set(USE_POWERPC ON CACHE BOOL "Enable PowerPC for GCC/Clang")
endif ()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64* OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64*)
# 64bit system
set(USE_O3 ON CACHE BOOL "Enable -O3 for GCC/Clang")
set(USE_FAST_MATH OFF CACHE BOOL "Enable -ffast-math for GCC/Clang")
set(USE_MMX ON CACHE BOOL "Enable MMX for GCC/Clang")
set(USE_SSE ON CACHE BOOL "Enable SSE for GCC/Clang")
set(USE_SSE2 ON CACHE BOOL "Enable SSE2 for GCC/Clang")
set(USE_SSE3 ON CACHE BOOL "Enable SSE3 for GCC/Clang")
set(USE_SSE4 ON CACHE BOOL "Enable SSE4 for GCC/Clang")
endif()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES i686* OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86)
# 32bit system
set(USE_O3 ON CACHE BOOL "Enable -O3 for GCC/Clang")
set(USE_FAST_MATH OFF CACHE BOOL "Enable -ffast-math for GCC/Clang")
set(USE_MMX ON CACHE BOOL "Enable MMX for GCC/Clang")
set(USE_SSE OFF CACHE BOOL "Enable SSE for GCC/Clang")
set(USE_SSE2 OFF CACHE BOOL "Enable SSE2 for GCC/Clang")
set(USE_SSE3 OFF CACHE BOOL "Enable SSE3 for GCC/Clang")
set(USE_SSE4 OFF CACHE BOOL "Enable SSE4 for GCC/Clang")
endif()
set(USE_AVX ON CACHE BOOL "Enable AVX for GCC/Clang")
# warning options
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall")
if(WARNINGS_ARE_ERRORS)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Werror")
endif()
# -Wno-long-long is required in 64bit systems when including sytem headers
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64* OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES amd64*)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-long-long")
endif()
# apply options
if(NOT ENABLE_PROFILING AND USE_OMIT_FRAME_POINTER)
set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -fomit-frame-pointer")
endif()
if(USE_O2)
set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O2")
endif()
if(USE_O3)
set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -O3")
endif()
if(USE_FAST_MATH)
set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -ffast-math")
endif()
if(USE_POWERPC)
set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -mcpu=G3 -mtune=G5")
endif()
# apply vectorization
if(USE_MMX)
set(VECTORIAL_INSTRUCTIONS "${VECTORIAL_INSTRUCTIONS} -mmmx")
add_definitions(-DUSE_MMX)
endif()
if(USE_SSE)
set(VECTORIAL_INSTRUCTIONS "${VECTORIAL_INSTRUCTIONS} -msse")
add_definitions(-DUSE_SSE)
endif()
if(USE_SSE2)
set(VECTORIAL_INSTRUCTIONS "${VECTORIAL_INSTRUCTIONS} -msse2")
add_definitions(-DUSE_SSE2)
endif()
if(USE_SSE3 AND NOT MINGW)
set(VECTORIAL_INSTRUCTIONS "${VECTORIAL_INSTRUCTIONS} -msse3")
add_definitions(-DUSE_SSE3)
endif()
if(USE_SSE4 AND NOT MINGW)
set(VECTORIAL_INSTRUCTIONS "${VECTORIAL_INSTRUCTIONS} -msse4.1")
add_definitions(-DUSE_SSE4)
endif()
IF(USE_AVX)
set(VECTORIAL_INSTRUCTIONS "${VECTORIAL_INSTRUCTIONS} -mavx")
add_definitions(-DUSE_AVX)
endif()
if(ENABLE_PROFILING)
set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE} -pg -g")
else()
if(NOT APPLE)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -ffunction-sections")
endif()
endif()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7l)
set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE}")
endif()
set(CMAKE_CXX_FLAGS "${EXTRA_C_FLAGS} -std=c++11 ")
set(CMAKE_CXX_FLAGS_RELEASE "${VECTORIAL_INSTRUCTIONS}${EXTRA_C_FLAGS_RELEASE} -DNDEBUG -D_NDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "${VECTORIAL_INSTRUCTIONS} -g3 -DDEBUG -D_DEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${VECTORIAL_INSTRUCTIONS} -O2 -g3 -DDEBUG -D_DEBUG")
else()
add_definitions(-DNOMINMAX)
endif()
find_package(OpenMP)
if(OPENMP_FOUND)
add_compile_options(-DUSE_OPENMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${OpenMP_CXX_FLAGS}")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}${CMAKE_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_EXE_LINKER_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${EXTRA_EXE_LINKER_FLAGS_RELEASE})
set(CMAKE_EXE_LINKER_FLAGS_DEBUG ${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${EXTRA_EXE_LINKER_FLAGS_DEBUG})
# ------------------------------------------------------
# utility directories
# ------------------------------------------------------
add_subdirectory(src)
if(BUILD_UTILS)
add_subdirectory(utils)
endif()
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
# ------------------------------------------------------
# display status message for important variables
# ------------------------------------------------------
message(STATUS)
message(STATUS "----------------------------------------" )
message(STATUS " General configuration for ${PROJECT_NAME} ${PROJECT_VERSION}")
message(STATUS "----------------------------------------" )
message(STATUS)
message(STATUS "CMAKE_MODULE_PATH = ${CMAKE_MODULE_PATH}")
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
message(STATUS "CMAKE_BINARY_DIR = ${CMAKE_BINARY_DIR}")
message(STATUS)
message(STATUS "OpenCV_DIR = ${OpenCV_DIR}" )
message(STATUS "OpenCV_INCLUDE_DIRS = ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV_LIBS = ${OpenCV_LIBS}")
message(STATUS)
message(STATUS "Processor: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Build dynamic libs: ${BUILD_SHARED_LIBS}")
message(STATUS "Build utils: ${BUILD_UTILS}")
message(STATUS "Build tests: ${BUILD_TESTS}")
message(STATUS "Use OpenMP: ${OPENMP_FOUND}")
message(STATUS)
message(STATUS "C compiler: ${CMAKE_C_COMPILER}")
message(STATUS "C++ compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS)
message(STATUS "C++ flags (Common):${CMAKE_CXX_FLAGS}")
message(STATUS "C++ flags (Release):${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "C++ flags (Debug):${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "C++ flags (Relaese+Debug):${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
message(STATUS)