forked from plstcharles/litiv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
241 lines (228 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
# This file is part of the LITIV framework; visit the original repository at
# https://github.com/plstcharles/litiv for more information.
#
# Copyright 2015 Pierre-Luc St-Charles; pierre-luc.st-charles<at>polymtl.ca
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/cmake/"
"${CMAKE_SOURCE_DIR}/cmake/Modules/"
)
if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "In-source builds are not supported; generation should be done in a local subfolder, e.g. '${CMAKE_SOURCE_DIR}/build'.")
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
include(FrameworkUtils)
include(CMakePackageConfigHelpers)
include(GetGitRevisionDescription)
include(CheckFunctionExists) # should be pre-packaged with CMake...
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(EXTERNAL_DATA_ROOT "${CMAKE_SOURCE_DIR}/data/" CACHE PATH "External data root folder (this is where all datasets should be located for applications to find them automatically)")
set(SAMPLES_DATA_ROOT "${CMAKE_SOURCE_DIR}/samples/data/" CACHE PATH "Sample data root folder (should contain necessary files so that samples can be used out-of-the-box)")
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install path prefix, prepended onto install directories (optional)")
# add hardcoded guesses for find_package here (caution: top level project is not defined yet!)
list(APPEND CMAKE_PREFIX_PATH
"$ENV{USER_DEVELOP}/opencv/build-litiv/install/" "$ENV{USER_DEVELOP}/opencv/build/" "$ENV{USER_DEVELOP}/opencv/"
"$ENV{USER_DEVELOP}/freeglut/build-litiv/install/" "$ENV{USER_DEVELOP}/freeglut/build/" "$ENV{USER_DEVELOP}/freeglut/"
"$ENV{USER_DEVELOP}/glfw/build-litiv/install/" "$ENV{USER_DEVELOP}/glfw/build/" "$ENV{USER_DEVELOP}/glfw/"
"$ENV{USER_DEVELOP}/glew/build-litiv/install/" "$ENV{USER_DEVELOP}/glew/build/" "$ENV{USER_DEVELOP}/glew/"
"$ENV{USER_DEVELOP}/glm/build-litiv/install/" "$ENV{USER_DEVELOP}/glm/build/" "$ENV{USER_DEVELOP}/glm/"
"$ENV{USER_DEVELOP}/opengm/build-litiv/install/" "$ENV{USER_DEVELOP}/opengm/build/" "$ENV{USER_DEVELOP}/opengm/"
)
################################################################
project(litiv)
set(LITIV_VERSION_MAJOR 1) # last change: 2015/10
set(LITIV_VERSION_MINOR 3) # last change: 2016/10
set(LITIV_VERSION_PATCH 3) # last change: 2016/11
set(LITIV_VERSION "${LITIV_VERSION_MAJOR}.${LITIV_VERSION_MINOR}.${LITIV_VERSION_PATCH}")
set(LITIV_VERSION_PLAIN "${LITIV_VERSION_MAJOR}${LITIV_VERSION_MINOR}${LITIV_VERSION_PATCH}")
set(LITIV_VERSION_ABI 0) # still unstable
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Forced project build type" FORCE)
endif(NOT CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "$<$<CONFIG:Debug>:DEBUG>")
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "$<$<CONFIG:Debug>:_DEBUG>")
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64-bit toolchain/platform
set(DATASETS_CACHE_SIZE 6 CACHE STRING "Cache size to be used for dataset preloading, if needed (in GB)")
set(TARGET_PLATFORM_x64 TRUE CACHE INTERNAL "" FORCE)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) # 32-bit toolchain/platform
set(DATASETS_CACHE_SIZE 1 CACHE STRING "Cache size to be used for dataset preloading, if needed (in GB)")
set(TARGET_PLATFORM_x64 FALSE CACHE INTERNAL "" FORCE)
else()
message(FATAL_ERROR "Could not detect x64/x86 platform identity using void pointer size (s=${CMAKE_SIZEOF_VOID_P}).")
endif()
option(USE_WORLD_SOURCE_GLOB "Compile all LITIV modules as part of the world module instead of soft-linking them" OFF)
option(USE_BSDS500_BENCHMARK "Link & use BSDS500 dataset benchmark implementation in litiv_datasets (cleaned 3rd party code; will use an approximative solution otherwise)" ON)
option(USE_CVCORE_WITH_UTILS "Include OpenCV core components in utils module" ON)
option(USE_FAST_MATH "Enable fast math optimizations" OFF)
mark_as_advanced(
USE_WORLD_SOURCE_GLOB
USE_BSDS500_BENCHMARK
USE_CVCORE_WITH_UTILS
USE_FAST_MATH
DATASETS_CACHE_SIZE
)
### OPENCV CHECK
find_package(OpenCV 3.0 REQUIRED)
### GLSL CHECK
find_package(OpenGL)
find_package(FREEGLUT)
find_package(GLFW)
find_package(GLEW)
find_package(GLM)
set_eval(USE_GLSL_INIT ((${GLFW_FOUND} OR ${FREEGLUT_FOUND}) AND ${OPENGL_FOUND} AND ${GLEW_FOUND} AND ${GLM_FOUND}))
option(USE_GLSL "Specifies whether GLSL support should be enabled or not; if false, projects that depend on it will be disabled" ${USE_GLSL_INIT})
if(USE_GLSL)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(GLM REQUIRED)
option(USE_GLFW "Use GLFW as the OpenGL window manager for GLSL implementations" ${GLFW_FOUND})
option(USE_FREEGLUT "Use FREEGLUT as the OpenGL window manager for GLSL implementations" ${FREEGLUT_FOUND})
if((${GLFW_FOUND} AND ${FREEGLUT_FOUND}) OR ((NOT ${GLFW_FOUND}) AND (NOT ${FREEGLUT_FOUND})))
set(USE_GLFW ON)
set(USE_FREEGLUT OFF)
endif()
if(${USE_GLFW})
find_package(GLFW REQUIRED)
elseif(${FREEGLUT_FOUND})
find_package(FREEGLUT REQUIRED)
endif()
set(TARGET_GL_VER_MAJOR 4 CACHE STRING "Target OpenGL profile major version for LITIV modules")
set(TARGET_GL_VER_MINOR 4 CACHE STRING "Target OpenGL profile minor version for LITIV modules")
option(GLEW_EXPERIMENTAL "Use experimental GLEW features" ON)
option(USE_VPTZ_STANDALONE "Build VPTZ library as standalone lib from LITIV framework" ON)
else()
message("Without GLSL support enabled, vptz module & shader-based implementations will be disabled")
endif()
### OPENGM CHECK
find_package(OpenGM COMPONENTS ext)
option(USE_OPENGM "Specifies whether OpenGM should be included/linked or not; if false, projects that depend on it will be disabled" ${OpenGM_FOUND})
if(USE_OPENGM)
find_package(OpenGM REQUIRED COMPONENTS ext)
else()
message("Without OpenGM support w/ external dependencies enabled, cosegm project & utilities will be disabled")
endif()
### CUDA CHECK @@@@ add later for parallel utils & impls
set_eval(USE_CUDA 0)
### OPENCL CHECK @@@@ add later for parallel utils & impls
set_eval(USE_OPENCL 0)
### Kinect SDK CHECK
if(WIN32)
find_package(KinectSDK2)
mark_as_advanced(
KinectSDK2_FACE
KinectSDK2_FUSION
KinectSDK2_VGB
)
option(USE_KINECTSDK "Specifies whether the Kinectv2 SDK should be included/linked or not; if false, projects that depend on it will be disabled" ${KinectSDK2_FOUND})
if(USE_KINECTSDK)
find_package(KinectSDK2 REQUIRED)
else()
message("Without full Kinectv2 SDK support, capture app will be disabled")
endif()
endif()
if(KinectSDK2_FOUND)
message(STATUS "Kinectv2 SDK found, will disable internal SDK standalone utilities.")
set(USE_KINECTSDK_STANDALONE FALSE CACHE INTERNAL "" FORCE)
else()
set(USE_KINECTSDK_STANDALONE TRUE CACHE INTERNAL "" FORCE)
endif()
initialize_internal_list(litiv_projects)
initialize_internal_list(litiv_3rdparty_modules)
initialize_internal_list(litiv_3rdparty_modules_sourcelist)
initialize_internal_list(litiv_modules)
initialize_internal_list(litiv_modules_sourcelist)
initialize_internal_list(litiv_apps)
initialize_internal_list(litiv_samples)
add_subdirectory(cmake/checks/simd)
add_definitions(-DLITIV_BUILD)
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"))
option(BUILD_SHARED_LIBS "Build shared libraries (.so) instead of static ones (.a)" ON)
if(NOT CMAKE_CROSSCOMPILING)
add_definitions(-march=native)
endif()
if(USE_FAST_MATH)
add_definitions(-ffast-math)
endif()
add_definitions(-Wall)
add_definitions(-Wfatal-errors)
add_definitions(-fPIC) # @@@@ for shared libs only?
add_definitions(-ftemplate-depth=900) # already default for gcc, but not for clang
check_function_exists(aligned_alloc USE_STL_ALIGNED_ALLOC)
if(NOT USE_STL_ALIGNED_ALLOC)
set(USE_STL_ALIGNED_ALLOC 0 CACHE INTERNAL "Have function aligned_alloc")
endif()
check_function_exists(posix_memalign USE_POSIX_ALIGNED_ALLOC)
if(NOT USE_POSIX_ALIGNED_ALLOC)
set(USE_POSIX_ALIGNED_ALLOC 0 CACHE INTERNAL "Have function posix_memalign")
endif()
elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC")
if(MSVC_VERSION LESS 1900)
message(FATAL_ERROR "MSVC toolchains older than 2015 (v140) are not supported!")
endif()
#set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE)
set(CMAKE_DEBUG_POSTFIX "d" CACHE INTERNAL "" FORCE)
option(USE_VERSION_TAGS "Apply version tags suffixes on built libraries" ON)
option(BUILD_SHARED_LIBS "Build shared libraries (.dll) instead of static ones (.lib)" OFF)
if(BUILD_SHARED_LIBS)
message("LITIV DLLs are still missing symbol exports, and might be incomplete for some targets")
endif()
add_definitions(-DUNICODE -D_UNICODE)
if(USE_FAST_MATH)
add_definitions(/fp:fast)
else(NOT USE_FAST_MATH)
add_definitions(/fp:precise)
endif()
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(/W1)
add_definitions(/openmp)
add_definitions(/arch:AVX) # check performance difference? vs 387? @@@
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
message(FATAL_ERROR "Intel compiler still unsupported; please edit the main CMakeList.txt file to add proper configuration")
# ... @@@
else()
message(FATAL_ERROR "Unknown compiler; please edit the main CMakeList.txt file to add proper configuration")
endif()
add_subdirectory(3rdparty)
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"))
add_definitions(-Wextra)
add_definitions(-Wshadow)
add_definitions(-Werror)
add_definitions(-pedantic-errors)
add_definitions(-Wno-missing-braces)
elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC")
add_definitions(/W4)
add_definitions(/wd4201) # disables C4201, "nonstandard extension used : nameless struct/union"
add_definitions(/wd4505) # disables C4505, "unreferenced local function has been removed"
add_definitions(/wd4514) # disables C4514, "unreferenced inline function has been removed"
add_definitions(/wd4250) # disables C4250, "'class1' : inherits 'class2::member' via dominance" (such behavior is expected in datasets module due to diamond struct patterns)
add_definitions(/wd4268) # disables C4268, "'variable': 'const' static/global data initialized with compiler generated default constructor fills the object with zeros
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
# ... @@@
endif()
add_subdirectory(modules)
add_subdirectory(samples)
add_subdirectory(apps)
add_subdirectory(doc)
include(FrameworkPackGen)