-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
234 lines (192 loc) · 7.56 KB
/
Copy pathCMakeLists.txt
File metadata and controls
234 lines (192 loc) · 7.56 KB
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
cmake_minimum_required(VERSION 3.12)
project( RAWTOACES )
if( NOT DEFINED CMAKE_CXX_STANDARD )
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set( RAWTOACES_MAJOR_VERSION 2 )
set( RAWTOACES_MINOR_VERSION 2 )
set( RAWTOACES_PATCH_VERSION 0 )
set( RAWTOACES_VERSION ${RAWTOACES_MAJOR_VERSION}.${RAWTOACES_MINOR_VERSION}.${RAWTOACES_PATCH_VERSION} )
set(RAWTOACES_CORE_LIB "rawtoaces_core")
set(RAWTOACES_UTIL_LIB "rawtoaces_util")
set( CMAKE_MACOSX_RPATH 1 )
# Set strict compiler flags by default for all builds
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# MSVC strict flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /EHsc")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX")
add_compile_definitions( NOMINMAX )
elseif (
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang"
)
# GCC/Clang strict flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -pedantic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wextra -pedantic")
endif()
if (NOT CONFIGURED_ONCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${warnings}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${warnings}")
endif()
## Make install directories overridable
set( INSTALL_LIB_DIR lib CACHE PATH "Install directory for libraries" )
set( INSTALL_BIN_DIR bin CACHE PATH "Install directory for executable binaries" )
set( INSTALL_INCLUDE_DIR include CACHE PATH "Install directory for public header files" )
if( WIN32 AND NOT CYGWIN )
set(DEF_INSTALL_CMAKE_DIR CMake)
else()
set(DEF_INSTALL_CMAKE_DIR lib/CMake/RAWTOACES)
endif()
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Install directory for project CMake files" )
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")
## convert install paths to absolute
foreach( p LIB BIN INCLUDE CMAKE )
set( var INSTALL_${p}_DIR )
if( NOT IS_ABSOLUTE "${${var}}" )
set( ${var} "${CMAKE_INSTALL_PREFIX}/${${var}}" )
endif()
endforeach()
option( ENABLE_SHARED "Enable Shared Libraries" ON )
option( RTA_BUILD_PYTHON_BINDINGS "Build python bindings" ON )
option( RTA_BUILD_TESTS "Build unit tests" ON )
option( RTA_INSTALL_DATABASE "Download and install the spectral measurements database" ON )
option( ENABLE_COVERAGE "Enable code coverage reporting" OFF )
option( RTA_ENABLE_LENSFUN "Use lensfun for lens correction" ON )
option( RTA_ENABLE_EIGEN "Use Eigen for linear algebra" ON )
option( RTA_ENABLE_CERES "Use Ceres Solver for matrix calculation" ON )
set ( RTA_SANITISER_MODE "none" CACHE STRING "Dynamic analysis sanitiser mode ('none', 'address', 'memory', or 'thread')" )
set ( RTA_PYTHON_VERSION "" CACHE STRING "Python version to use" )
if ( ENABLE_SHARED )
set ( DO_SHARED SHARED )
else ()
set ( DO_SHARED STATIC )
endif ()
include ( configure.cmake )
# Include coverage support if enabled
if( ENABLE_COVERAGE )
include( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CodeCoverage.cmake )
endif()
#################################################
##
## Build
add_definitions( -DPACKAGE="RAWTOACES" -DVERSION="${RAWTOACES_VERSION}" )
add_subdirectory("src/${RAWTOACES_CORE_LIB}")
add_subdirectory("src/${RAWTOACES_UTIL_LIB}")
add_subdirectory("src/rawtoaces")
if ( RTA_BUILD_PYTHON_BINDINGS )
add_subdirectory(src/bindings)
endif ( RTA_BUILD_PYTHON_BINDINGS )
if ( RTA_BUILD_TESTS )
enable_testing()
add_subdirectory(tests)
endif ( RTA_BUILD_TESTS )
# Documentation (optional)
option( BUILD_DOCS "Build documentation" OFF )
if( BUILD_DOCS )
add_subdirectory(src/docs)
endif()
#################################################
##
## Dynamic analysis
if ( NOT "${RTA_SANITISER_MODE}" STREQUAL "none" )
if ( "${RTA_SANITISER_MODE}" STREQUAL "address" )
set ( RTA_SANITISER_COMPILE_OPTIONS "-fsanitize=address" "-fno-omit-frame-pointer" "-g" "-O1" )
set ( RTA_SANITISER_LINK_OPTIONS "-fsanitize=address" "-g" )
elseif ( "${RTA_SANITISER_MODE}" STREQUAL "memory" )
set ( RTA_SANITISER_COMPILE_OPTIONS "-fsanitize=memory" "-fno-omit-frame-pointer" "-g" "-O2" "-fsanitize-memory-track-origins" )
set ( RTA_SANITISER_LINK_OPTIONS "-fsanitize=memory" "-g" "-fsanitize-memory-track-origins" )
elseif ( "${RTA_SANITISER_MODE}" STREQUAL "thread" )
set ( RTA_SANITISER_COMPILE_OPTIONS "-fsanitize=thread" "-g" "-O1" )
set ( RTA_SANITISER_LINK_OPTIONS "-fsanitize=thread" "-g" )
else ()
message ( FATAL_ERROR "Invalid RTA_SANITISER_MODE: ${RTA_SANITISER_MODE}" )
endif ()
target_compile_options( ${RAWTOACES_CORE_LIB} PUBLIC
$<$<CONFIG:Debug>: ${RTA_SANITISER_COMPILE_OPTIONS}>
)
target_link_options( ${RAWTOACES_CORE_LIB} PUBLIC
$<$<CONFIG:Debug>: ${RTA_SANITISER_LINK_OPTIONS}>
)
endif ()
#################################################
##
## Install RAWTOACES.pc
if ( PKG_CONFIG_FOUND )
if ( RTA_ENABLE_CERES )
set ( RTA_PC_CERES_LIB "-lCeres" )
else ()
set ( RTA_PC_CERES_LIB "" )
endif ()
configure_file(config/RAWTOACES.pc.in "${PROJECT_BINARY_DIR}/RAWTOACES.pc" @ONLY)
install( FILES "${PROJECT_BINARY_DIR}/RAWTOACES.pc" DESTINATION lib/pkgconfig COMPONENT dev )
endif()
#################################################
##
## Install data
###############################################################################
##
## Fetch data files from rawtoaces-data
##
if ( RTA_INSTALL_DATABASE )
include(FetchContent)
FetchContent_Declare(
rawtoaces_data
GIT_REPOSITORY https://github.com/AcademySoftwareFoundation/rawtoaces-data
GIT_TAG 5cfa53707b053594b2d0d48e8019fb56e6582d6c # v1.1.0-RC
)
FetchContent_MakeAvailable(rawtoaces_data)
if ( APPLE OR UNIX )
install (
DIRECTORY
${PROJECT_BINARY_DIR}/_deps/rawtoaces_data-src/data
DESTINATION share/rawtoaces
)
install (
FILES
${PROJECT_BINARY_DIR}/_deps/rawtoaces_data-src/LICENSE
DESTINATION share/rawtoaces/data
)
endif()
endif ( RTA_INSTALL_DATABASE )
#################################################
##
## Install targets
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/
CACHE PATH "Location of header files" )
export( EXPORT RAWTOACESTargets )
install( EXPORT RAWTOACESTargets
FILE RAWTOACESTargets.cmake
DESTINATION lib/cmake/RAWTOACES
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
config/RAWTOACESConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/RAWTOACESConfig.cmake
INSTALL_DESTINATION lib/cmake/RAWTOACES
PATH_VARS INCLUDE_INSTALL_DIR
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/RAWTOACESConfigVersion.cmake
VERSION ${RAWTOACES_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/RAWTOACESConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/RAWTOACESConfigVersion.cmake
DESTINATION lib/cmake/RAWTOACES
)