forked from taketwo/radical
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
199 lines (162 loc) · 6.02 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
cmake_minimum_required(VERSION 2.8.12.2)
if(POLICY CMP0054)
# Only interpret if() arguments as variables or keywords when unquoted.
cmake_policy(SET CMP0054 NEW)
endif()
set(LIB_NAME radical)
project("${LIB_NAME}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
include("${CMAKE_SOURCE_DIR}/cmake/Utils.cmake")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# On Windows we build a static library with statically linked dependencies and
# on Linux we build a shared library.
if(WIN32)
set(LIB_TYPE STATIC)
else()
set(LIB_TYPE SHARED)
endif()
# Library version
set(RADICAL_VERSION_MAJOR 1)
set(RADICAL_VERSION_MINOR 0)
set(RADICAL_VERSION_PATCH 0)
set(RADICAL_VERSION "${RADICAL_VERSION_MAJOR}.${RADICAL_VERSION_MINOR}.${RADICAL_VERSION_PATCH}")
set(RADICAL_VERSION_SO "${RADICAL_VERSION_MAJOR}.${RADICAL_VERSION_MINOR}")
set(RADICAL_VERSION_LIB "${RADICAL_VERSION_MAJOR}.${RADICAL_VERSION_MINOR}.${RADICAL_VERSION_PATCH}")
# Set build type to Release if not specified by user
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "-- No build type specified; defaulting to CMAKE_BUILD_TYPE=Release")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# Force to always compile with W4
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++11 -fcolor-diagnostics")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -std=c++11 -fdiagnostics-color")
endif()
RADICAL_OPTION(BUILD_APPS "Build apps" ON)
RADICAL_OPTION(BUILD_TESTS "Build tests" OFF)
RADICAL_OPTION(WITH_OPENNI2 "Enable support for OpenNI2 cameras" ON)
RADICAL_OPTION(WITH_REALSENSE "Enable support for RealSense cameras" ON)
RADICAL_OPTION(WITH_PYLON "Enable support for Pylon cameras" OFF)
RADICAL_OPTION(WITH_CERES "Enable features requiring Google Ceres solver" ON)
find_package(OpenCV COMPONENTS core imgproc REQUIRED)
if(BUILD_APPS OR BUILD_TESTS)
set(Boost_COMPONENTS system filesystem)
if(BUILD_APPS)
list(APPEND Boost_COMPONENTS program_options)
endif()
if(BUILD_TESTS)
list(APPEND Boost_COMPONENTS unit_test_framework)
endif()
if(LIB_TYPE STREQUAL STATIC)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BOOST_ALL_DYN_LINK OFF)
endif()
find_package(Boost COMPONENTS ${Boost_COMPONENTS} REQUIRED)
endif()
include_directories("${PROJECT_SOURCE_DIR}/include")
set(RADICAL_SRC
src/radical/radiometric_response.cpp
src/radical/vignetting_response.cpp
src/radical/vignetting_model.cpp
src/radical/nonparametric_vignetting_model.cpp
src/radical/polynomial_vignetting_model.cpp
src/radical/mat_io.cpp
src/radical/check.cpp
)
add_library(${LIB_NAME} ${LIB_TYPE} ${RADICAL_SRC})
set_target_properties(
${LIB_NAME} PROPERTIES
VERSION "${RADICAL_VERSION_LIB}"
SOVERSION "${RADICAL_VERSION_SO}"
)
target_compile_definitions(${LIB_NAME} PUBLIC "RADICAL_DEBUG=$<CONFIG:Debug>")
target_include_directories(${LIB_NAME}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
${OpenCV_INCLUDE_DIRS} # Should be picked up automatically from linking, but
# does not work reliably on Windows
)
target_link_libraries(${LIB_NAME} PUBLIC opencv_core opencv_imgproc)
if(BUILD_APPS)
add_subdirectory(src/utils)
add_subdirectory(src/grabbers)
add_subdirectory(src/apps)
endif()
if(BUILD_TESTS)
enable_testing(true)
add_subdirectory(tests)
endif()
#---------------------------------------------------------------------#
# Installation #
#---------------------------------------------------------------------#
## Layout:
#
# <prefix>
# ├── include
# │ └── radical
# └── lib
# └── cmake
# └── radical
set(_config_install_dir "lib/cmake/${PROJECT_NAME}")
set(_include_install_dir "include")
set(_generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(_version_config_file "${_generated_dir}/${PROJECT_NAME}-config-version.cmake")
set(_project_config_file "${_generated_dir}/${PROJECT_NAME}-config.cmake")
set(_targets_export_name "${PROJECT_NAME}-targets")
## Create radical-config-version.cmake
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${_version_config_file}"
VERSION ${RADICAL_VERSION}
COMPATIBILITY AnyNewerVersion
)
## Create radical-config.cmake
configure_package_config_file(
"cmake/Config.cmake.in"
"${_project_config_file}"
INSTALL_DESTINATION "${_config_install_dir}"
)
## Install targets
install(TARGETS ${LIB_NAME}
EXPORT "${_targets_export_name}"
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION ${_include_install_dir}
)
## Install headers
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/include/${PROJECT_NAME}
DESTINATION ${_include_install_dir}
FILES_MATCHING PATTERN "*.h"
)
## Instal config files
install(
FILES ${_project_config_file} ${_version_config_file}
DESTINATION "${_config_install_dir}"
)
install(
EXPORT "${_targets_export_name}"
DESTINATION "${_config_install_dir}"
)
#---------------------------------------------------------------------#
# Uninstallation #
#---------------------------------------------------------------------#
## Uninstall target
configure_file(
"cmake/Uninstall.cmake.in"
"${_generated_dir}/uninstall.cmake"
IMMEDIATE @ONLY
)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${_generated_dir}/uninstall.cmake
)