forked from lensfun/lensfun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
276 lines (236 loc) · 9.81 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
# require at least cmake 2.8
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR )
# path for helper modules
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake/modules")
GET_FILENAME_COMPONENT(SOURCE_BASE_DIR ${CMAKE_SOURCE_DIR} PATH CACHE)
# global setup
project(lensfun C CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
IF (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
ELSE()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wformat-security")
ENDIF()
# version
SET(VERSION_MAJOR 0)
SET(VERSION_MINOR 3)
SET(VERSION_MICRO 95)
SET(VERSION_BUGFIX 0)
SET(VERSION_API 2)
# This is the version of the *shipped* database, which is not necessarily the
# highest version number supported
SET(LENSFUN_DB_VERSION 2)
# check if some include are available
INCLUDE(CheckIncludeFiles)
CHECK_INCLUDE_FILES(endian.h HAVE_ENDIAN_H)
# set include directories
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/lensfun)
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "[XxIi][0-9]?86|[Aa][Mm][Dd]64")
SET(X86_ON ON)
else()
SET(X86_ON OFF)
ENDIF()
# options controlling the build process
OPTION(BUILD_STATIC "Build static library" OFF)
OPTION(BUILD_WITH_MSVC_STATIC_RUNTIME "Build using static MSVC runtime" OFF)
OPTION(BUILD_TESTS "Build test suite" OFF)
OPTION(BUILD_LENSTOOL "Build the lenstool (requires libpng)" OFF)
OPTION(BUILD_FOR_SSE "Build with support for SSE" ${X86_ON})
OPTION(BUILD_FOR_SSE2 "Build with support for SSE2" ${X86_ON})
OPTION(BUILD_DOC "Build documentation with doxygen" OFF)
OPTION(INSTALL_PYTHON_MODULE "Install Python module for the helper scripts" ON)
OPTION(INSTALL_HELPER_SCRIPTS "Install various helper scripts" ON)
IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Debug CACHE STRING
"Choose the type of build, options are: Debug, Release"
FORCE
)
ENDIF()
# place all .exe and .dll files in same folder to avoid issues with tests
IF(WIN32)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
ENDIF()
# set local install prefix on windows
IF(WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE PATH "Install prefix for Lensfun" FORCE)
ENDIF()
# overwrite some folders before GNUInstallDirs is loaded
IF (WIN32 AND NOT DEFINED CMAKE_INSTALL_DATAROOTDIR)
SET(CMAKE_INSTALL_DATAROOTDIR "$ENV{ALLUSERSPROFILE}" CACHE PATH "read-only architecture-independent data root (share)")
ENDIF()
# get standard GNU install directories for the current platform
INCLUDE(GNUInstallDirs)
IF(NOT DEFINED CMAKE_INSTALL_DATAROOTDIR)
SET(CMAKE_INSTALL_DATAROOTDIR "share" CACHE PATH "read-only architecture-independent data root (share)")
ENDIF()
IF(BUILD_FOR_SSE)
SET(VECTORIZATION_SSE 1)
IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
SET(VECTORIZATION_SSE_FLAGS "-msse")
ENDIF()
ENDIF()
IF(BUILD_FOR_SSE2)
SET(VECTORIZATION_SSE2 1)
IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
SET(VECTORIZATION_SSE2_FLAGS "-msse2")
ENDIF()
ENDIF()
IF(WIN32)
# base path for searching for glib on windows
IF(NOT GLIB2_BASE_DIR)
SET(GLIB2_BASE_DIR "${SOURCE_BASE_DIR}/glib-2.28.1" CACHE STRING "Base path of glib2 dir." FORCE)
ENDIF()
# install glib dll on windows next to lensfun.dll
IF (GLIB2_DLL)
INSTALL(FILES ${GLIB2_DLL} DESTINATION ${CMAKE_INSTALL_BINDIR})
ENDIF()
ENDIF()
IF (BUILD_TESTS)
# automatic tests need at least glib version 2.40
# NOTE: must be one of the macros listed in https://developer.gnome.org/glib/stable/glib-Version-Information.html
SET(LENSFUN_GLIB_REQUIREMENT_MACRO "GLIB_VERSION_2_40")
FIND_PACKAGE(GLIB2 REQUIRED)
ELSE()
SET(LENSFUN_GLIB_REQUIREMENT_MACRO "GLIB_VERSION_2_26")
FIND_PACKAGE(GLIB2 REQUIRED)
ENDIF()
INCLUDE_DIRECTORIES(SYSTEM ${GLIB2_INCLUDE_DIRS})
LINK_DIRECTORIES(${GLIB2_LIBRARY_DIRS})
IF(BUILD_STATIC)
ADD_DEFINITIONS(-DCONF_LENSFUN_STATIC)
ENDIF()
# some windows and MSVC specific settings
IF(WIN32)
IF (MSVC)
IF(BUILD_WITH_MSVC_STATIC_RUNTIME)
# compile everything for the static C runtime
FOREACH(TYPE C CXX)
# makefiles use blank configuration
FOREACH(CFG "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
SET(NEW_FLAGS "${CMAKE_${TYPE}_FLAGS${CFG}}")
# fix up static libc flags
STRING(REPLACE "/MD" "/MT" NEW_FLAGS "${NEW_FLAGS}")
# *FORCE* to override whats already placed into the cache
SET(CMAKE_${TYPE}_FLAGS${CFG} "${NEW_FLAGS}" CACHE STRING
"CMAKE_${TYPE}_FLAGS${CFG} (overwritten to ensure static build)" FORCE)
ENDFOREACH(CFG)
ENDFOREACH(TYPE)
# link only with the static C runtime !! THIS IS A MUST !!
SET(NEW_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
# ensure that the flags are not duplicaated on subsequent runs
STRING(REPLACE " /NODEFAULTLIB:\"MSVCRT.lib\" /NODEFAULTLIB:\"MSVCRTd.lib\"" "" NEW_FLAGS "${NEW_FLAGS}")
# note that flag names (NODEFAULTLIB) etc.) are case sensitive
SET(CMAKE_EXE_LINKER_FLAGS
"${NEW_FLAGS} /NODEFAULTLIB:\"MSVCRT.lib\" /NODEFAULTLIB:\"MSVCRTd.lib\""
CACHE STRING "for MSVC" FORCE
)
ENDIF()
ENDIF(MSVC)
ENDIF(WIN32)
# create config.h file
CONFIGURE_FILE(include/lensfun/config.h.in.cmake ${CMAKE_BINARY_DIR}/config.h)
# create lensfun.h file
CONFIGURE_FILE(include/lensfun/lensfun.h.in ${CMAKE_BINARY_DIR}/lensfun.h @ONLY)
# include libs
ADD_SUBDIRECTORY(libs)
# build the test suite
IF(BUILD_TESTS)
enable_testing()
ADD_SUBDIRECTORY(tests)
ENDIF()
# apps subdir
IF(BUILD_LENSTOOL)
FIND_PACKAGE(PNG REQUIRED)
ENDIF()
ADD_SUBDIRECTORY(apps)
# install include files
INSTALL(FILES ${CMAKE_BINARY_DIR}/lensfun.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lensfun)
# install db files
FILE(GLOB DATABASE_FILES data/db/*.xml)
INSTALL(FILES ${DATABASE_FILES} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/lensfun/version_${LENSFUN_DB_VERSION})
INSTALL(FILES data/db/timestamp.txt DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/lensfun/version_${LENSFUN_DB_VERSION})
FILE(GLOB DATABASE_DTD data/db/*.dtd data/db/*.xsd)
INSTALL(FILES ${DATABASE_DTD} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/lensfun/version_${LENSFUN_DB_VERSION})
# build documentation
IF(BUILD_DOC)
ADD_SUBDIRECTORY(docs)
ENDIF()
IF(WIN32 AND NOT BUILD_STATIC)
FIND_FILE(GLIB2_DLL
NAMES glib-2.dll glib-2-vs9.dll
PATHS "${GLIB2_BASE_DIR}/bin"
NO_SYSTEM_ENVIRONMENT_PATH)
INSTALL(FILES ${GLIB2_DLL} DESTINATION ${CMAKE_INSTALL_BINDIR})
ENDIF()
# print some information
MESSAGE(STATUS "-------------------------------------------------------------------------------------")
MESSAGE(STATUS "Building Lensfun ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}.${VERSION_BUGFIX}")
MESSAGE(STATUS "-------------------------------------------------------------------------------------")
IF(BUILD_STATIC)
MESSAGE(STATUS "Build as static library")
ELSE()
MESSAGE(STATUS "Build as dynamic/shared library")
ENDIF()
IF (NOT CMAKE_CONFIGURATION_TYPES)
MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
ENDIF()
MESSAGE(STATUS "Build doc: ${BUILD_DOC}")
MESSAGE(STATUS "Build test suite: ${BUILD_TESTS}")
MESSAGE(STATUS "Build lenstool: ${BUILD_LENSTOOL}")
MESSAGE(STATUS "Build with support for SSE: ${BUILD_FOR_SSE}")
MESSAGE(STATUS "Build with support for SSE2: ${BUILD_FOR_SSE2}")
MESSAGE(STATUS "Install helper scripts: ${INSTALL_HELPER_SCRIPTS}")
MESSAGE(STATUS "\nInstall prefix: ${CMAKE_INSTALL_PREFIX}")
MESSAGE(STATUS "\nUsing: ")
MESSAGE(STATUS "GLIB2 include dir: ${GLIB2_INCLUDE_DIRS}")
MESSAGE(STATUS "GLIB2 library: ${GLIB2_LIBRARIES}")
IF(GLIB2_DLL)
MESSAGE(STATUS "GLIB2 DLL: ${GLIB2_DLL}")
ENDIF()
IF(BUILD_LENSTOOL)
MESSAGE(STATUS "libpng include dir: ${PNG_INCLUDE_DIRS}")
MESSAGE(STATUS "libpng lib: ${PNG_LIBRARIES}")
MESSAGE(STATUS "zlib include dir: ${ZLIB_INCLUDE_DIRS}")
MESSAGE(STATUS "zlib lib: ${ZLIB_LIBRARIES}")
ENDIF()
# Package
# This needs some testing, in particular for right package naming for different
# package managers and distributions. Debian works fine.
SET(CPACK_PACKAGE_NAME "lensfun")
SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_MICRO}.${VERSION_BUGFIX}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${V_MAJOR}.${V_MINOR}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}.${VERSION_BUGFIX}")
SET(CPACK_SOURCE_GENERATOR "TGZ;TBZ2")
SET(CPACK_PACKAGE_CONTACT "[email protected]")
SET(CPACK_SET_DESTDIR "ON")
IF(BUILD_AUXFUN)
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libglib2.0-0 (>=2.0.0), libpng (>=1.0), zlib (>=1.0)")
ELSE()
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libglib2.0-0 (>=2.0.0)")
ENDIF()
IF(CPACK_BINARY_DEB)
# workaround to set correct debian package name
SET(CPACK_DEBIAN_PACKAGE_NAME "liblensfun${VERSION_API}")
STRING(TOLOWER "${CPACK_DEBIAN_PACKAGE_NAME}" CPACK_PACKAGE_NAME_LOWERCASE)
FIND_PROGRAM(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
if(DPKG_PROGRAM)
EXECUTE_PROCESS(
COMMAND ${DPKG_PROGRAM} --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}.${VERSION_BUGFIX}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
else(DPKG_PROGRAM)
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME_LOWERCASE}_${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}.${VERSION_BUGFIX}_${CMAKE_SYSTEM_NAME}")
endif(DPKG_PROGRAM)
ENDIF(CPACK_BINARY_DEB)
INCLUDE(CPack)
if(CMAKE_BUILD_TYPE STREQUAL "Coverage" AND CMAKE_COMPILER_IS_GNUCXX)
include(CodeCoverage)
setup_target_for_coverage(coverage ctest coverage)
endif(CMAKE_BUILD_TYPE STREQUAL "Coverage" AND CMAKE_COMPILER_IS_GNUCXX)