forked from jasper-maint/jasper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
438 lines (377 loc) · 15.1 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
cmake_minimum_required (VERSION 2.8.11)
project(JasPer C)
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/cmake/modules/")
# This include should be placed as early as possible.
include(InSourceBuild)
include(CheckCCompilerFlag)
################################################################################
# Version information.
################################################################################
# The major, minor, and micro version numbers of the project.
set(JAS_VERSION_MAJOR 2)
set(JAS_VERSION_MINOR 0)
set(JAS_VERSION_PATCH 16)
# The project version.
set(JAS_VERSION
"${JAS_VERSION_MAJOR}.${JAS_VERSION_MINOR}.${JAS_VERSION_PATCH}")
message("Software version: ${JAS_VERSION}")
# The shared library versioning information, which is specified by the
# following variables: JAS_SO_VERSION, JAS_SO_MINOR, and JAS_SO_RELEASE.
# Each new software release should update the values of these variables.
#
# Guidelines for updating this information:
# If the code did not change (e.g., only documentation was updated), do
# nothing.
# If the code changed and the binary interface for the library did not change
# from the previous release (e.g., most bug fixes), increment JAS_SO_RELEASE.
# If the binary interface changed, but remains compatible with the previous
# release (e.g., only new functions were added), increment JAS_SO_MINOR and
# set JAS_SO_RELEASE to 0.
# If the binary interface changed in a way that breaks compatibility with the
# previous release (e.g., a function was deleted), increment JAS_SO_VERSION and
# set both JAS_SO_MINOR and JAS_SO_RELEASE to 0.
#
# History of shared library versioning information:
# JasPer 2.0.0: 4.0.0
if (APPLE AND CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(MACOSX true)
else()
set(MACOSX false)
endif()
# To fix a problem with OSX, increase JAS_SO_VERSION to 6 (instead of 5)
# when it is next increased.
set(JAS_SO_VERSION 4)
set(JAS_SO_MINOR 0)
set(JAS_SO_RELEASE 0)
# This is a temporary hack for OSX that should be removed when JAS_SO_VERSION
# is next incremented.
if (MACOSX)
set(JAS_SO_NAME "5.${JAS_SO_MINOR}.${JAS_SO_RELEASE}")
else()
set(JAS_SO_NAME "${JAS_SO_VERSION}.${JAS_SO_MINOR}.${JAS_SO_RELEASE}")
endif()
message("Shared library ABI version: ${JAS_SO_VERSION}")
message("Shared library build version: ${JAS_SO_NAME}")
################################################################################
# Include modules and set policies.
################################################################################
# Adhere to GNU filesystem layout conventions.
include(GNUInstallDirs)
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckCSourceCompiles)
include(CTest)
include(Sanitizers)
cmake_policy(SET CMP0012 NEW)
################################################################################
# Define options.
################################################################################
option(JAS_ENABLE_SHARED "Enable building of shared library" true)
option(JAS_ENABLE_HIDDEN "Hide internal symbols" false)
option(JAS_ENABLE_32BIT "Use 32 bit integers on 64 bit CPUs" false)
option(JAS_ENABLE_LIBJPEG "Enable the use of the JPEG Library" true)
option(JAS_ENABLE_OPENGL "Enable the use of the OpenGL/GLUT Library" true)
option(JAS_ENABLE_STRICT "Enable pedantic error checking" false)
option(JAS_ENABLE_AUTOMATIC_DEPENDENCIES "Enable automatic dependencies" true)
option(JAS_LOCAL "Enable local hacks for developers (do not enable)" false)
option(JAS_ENABLE_DOC "Enable building of the documentation" true)
option(JAS_ENABLE_PROGRAMS "Enable building of the programs" true)
################################################################################
#
################################################################################
#set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_C_STANDARD 11)
if ((CMAKE_GENERATOR MATCHES Xcode) OR
(CMAKE_GENERATOR MATCHES "Visual Studio"))
set(JAS_MULTICONFIGURATION_GENERATOR 1)
else()
set(JAS_MULTICONFIGURATION_GENERATOR 0)
endif()
message("JAS_MULTICONFIGURATION_GENERATOR ${JAS_MULTICONFIGURATION_GENERATOR}")
if (JAS_ENABLE_AUTOMATIC_DEPENDENCIES)
message(WARNING
"If this software is being built as a package for a Linux distribution, "
"you should probably set JAS_ENABLE_AUTOMATIC_DEPENDENCIES to false.")
set(JAS_REQUIRED "")
else()
set(JAS_REQUIRED "REQUIRED")
endif()
# The following lines have been temporarily moved above:
#if (APPLE AND CMAKE_SYSTEM_NAME MATCHES "Darwin")
# set(MACOSX true)
#else()
# set(MACOSX false)
#endif()
if (UNIX)
if (MACOSX)
set(JAS_PLATFORM "UNIX (OSX)")
else()
set(JAS_PLATFORM "UNIX (Not OSX)")
endif()
elseif (WIN32)
set(JAS_PLATFORM "Microsoft Windows")
else()
set(JAS_PLATFORM "Unknown")
endif()
message("Platform ${JAS_PLATFORM}")
if (JAS_ENABLE_SHARED AND MACOSX)
set(CMAKE_MACOSX_RPATH true)
endif()
if (JAS_ENABLE_SHARED)
set(JAS_DLL 1)
endif()
message("JAS_LOCAL ${JAS_LOCAL}")
message("CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}")
message("CMAKE_C_COMPILER_ID ${CMAKE_C_COMPILER_ID}")
message("CMAKE_C_COMPILER ${CMAKE_C_COMPILER}")
message("CMAKE_C_FLAGS ${CMAKE_C_FLAGS}")
if (JAS_LOCAL AND (CMAKE_BUILD_TYPE MATCHES "Debug"))
if (CMAKE_C_COMPILER_ID MATCHES "GNU" OR
CMAKE_C_COMPILER_ID MATCHES "Clang")
add_definitions("-O0")
endif()
endif()
# If a multiconfiguration generator is used, ensure that various output
# files are not placed in subdirectories (such as Debug and Release)
# as this will cause the CTest test suite to fail.
if (JAS_MULTICONFIGURATION_GENERATOR)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY .)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY .)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY .)
foreach (config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${config}" config)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config} .)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${config} .)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${config} .)
endforeach()
endif()
include(InstallRequiredSystemLibraries)
set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
set(CPACK_PACKAGE_VERSION "${JAS_VERSION}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "JasPer Image Processing Tool Kit")
set(CPACK_PACKAGE_VENDOR "Michael Adams")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR "${JAS_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${JAS_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${JAS_VERSION_PATCH}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY
"CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
set(CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_GENERATOR "TGZ")
include(CPack)
if (JAS_STRICT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wformat -Wmissing-prototypes -Wstrict-prototypes")
endif()
if (JAS_ENABLE_HIDDEN AND NOT WIN32)
# don't export internal symbols
check_c_compiler_flag("-fvisibility=hidden" JAS_HAVE_VISIBILITY)
if (JAS_HAVE_VISIBILITY)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -DJAS_HAVE_VISIBILITY")
endif()
if (NOT (CMAKE_BUILD_TYPE MATCHES "Debug"))
# remove unused internal symbols
check_c_compiler_flag("-ffunction-sections" HAVE_FUNCTION_SECTIONS)
check_c_compiler_flag("-fdata-sections" HAVE_DATA_SECTIONS)
check_c_compiler_flag("-Wl,--gc-sections" HAVE_GC_SECTIONS)
if (HAVE_FUNCTION_SECTIONS AND HAVE_DATA_SECTIONS AND HAVE_GC_SECTIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wl,--gc-sections")
endif()
endif()
endif()
################################################################################
# Perform plaform checks.
################################################################################
find_package(Doxygen)
find_package(LATEX COMPONENTS PDFLATEX)
find_program(BASH_PROGRAM bash)
# On some (or maybe all?) systems, LATEX_FOUND is not set by FindLATEX.
# So, instead, rely on LATEX_PDFLATEX_FOUND.
message("PDFLATEX_COMPILER: ${PDFLATEX_COMPILER}")
if ((NOT LATEX_FOUND) AND PDFLATEX_COMPILER)
message(WARNING "Setting LATEX_FOUND to true.")
message(WARNING "Your version of CMake may be buggy.")
set(LATEX_FOUND true)
endif()
message("LATEX_FOUND ${LATEX_FOUND}")
check_include_files(fcntl.h JAS_HAVE_FCNTL_H)
check_include_files(io.h JAS_HAVE_IO_H)
check_include_files(unistd.h JAS_HAVE_UNISTD_H)
check_include_files(windows.h JAS_HAVE_WINDOWS_H)
check_include_files(sys/time.h JAS_HAVE_SYS_TIME_H)
check_include_files(sys/types.h JAS_HAVE_SYS_TYPES_H)
check_function_exists(gettimeofday JAS_HAVE_GETTIMEOFDAY)
check_function_exists(getrusage JAS_HAVE_GETRUSAGE)
################################################################################
# Check for the JPEG library.
################################################################################
if (JAS_ENABLE_LIBJPEG)
find_package(JPEG ${JAS_LIBJPEG_REQUIRED})
message("JPEG library found: ${JPEG_FOUND}")
else()
set(JPEG_FOUND false)
endif()
if (JAS_ENABLE_LIBJPEG AND JPEG_FOUND)
set(JAS_HAVE_LIBJPEG 0)
message("JPEG include directory: ${JPEG_INCLUDE_DIR}")
message("JPEG libraries: ${JPEG_LIBRARIES}")
# In some versions of the JPEG library, the header file jpeglib.h
# does not include some of the header files upon which it depends
# (e.g., stdio.h and stdint.h). So, we cannot reliably use
# check_include_file here.
set(CMAKE_REQUIRED_INCLUDES ${JPEG_INCLUDE_DIR})
check_c_source_compiles("
#include <stdio.h>
#include <stdint.h>
#include <jpeglib.h>
int main() {}
" JAS_HAVE_JPEGLIB_H)
message("JAS_HAVE_JPEGLIB_H: ${JAS_HAVE_JPEGLIB_H}")
if(JAS_HAVE_JPEGLIB_H)
set(JAS_HAVE_LIBJPEG 1)
include_directories(${JPEG_INCLUDE_DIR})
else()
message(WARNING "The header file jpeglib.h appears to be missing.")
message(WARNING "Disabling LIBJPEG.")
set(JPEG_FOUND false)
set(JPEG_LIBRARIES "")
set(JPEG_INCLUDE_DIR "")
set(JAS_ENABLE_LIBJPEG 0)
endif()
else()
set(JAS_HAVE_LIBJPEG 0)
set(JPEG_INCLUDE_DIR "")
set(JPEG_LIBRARIES "")
endif()
message("JAS_HAVE_LIBJPEG: ${JAS_HAVE_LIBJPEG}")
################################################################################
# Check for the OpenGL and GLUT libraries.
################################################################################
message("JAS_ENABLE_OPENGL: ${JAS_ENABLE_OPENGL}")
if (JAS_ENABLE_OPENGL)
find_package(OpenGL ${JAS_REQUIRED})
message("OpenGL library found: ${OPENGL_FOUND}")
else()
set(OPENGL_FOUND false)
endif()
if (JAS_ENABLE_OPENGL AND OPENGL_FOUND)
set(JAS_HAVE_OPENGL 0)
message("OpenGL include directory: ${OPENGL_INCLUDE_DIR}")
message("OpenGL libraries: ${OPENGL_LIBRARIES}")
find_package(GLUT ${JAS_REQUIRED})
message("GLUT library found: ${GLUT_FOUND}")
if (GLUT_FOUND)
message("GLUT include directory: ${GLUT_INCLUDE_DIR}")
message("GLUT libraries: ${GLUT_LIBRARIES}")
set(CMAKE_REQUIRED_INCLUDES ${GLUT_INCLUDE_DIR})
check_include_files(GL/glut.h JAS_HAVE_GL_GLUT_H)
check_include_files(glut.h JAS_HAVE_GLUT_H)
message("JAS_HAVE_GLUT_H: ${JAS_HAVE_GLUT_H}")
message("JAS_HAVE_GL_GLUT_H: ${JAS_HAVE_GL_GLUT_H}")
if (JAS_HAVE_GL_GLUT_H OR JAS_HAVE_GLUT_H)
set(JAS_HAVE_OPENGL 1)
include_directories(${GLUT_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
else()
message(WARNING "The header files GL/glut.h and glut.h both appear to be missing.")
message(WARNING "Disabling OpenGL.")
endif()
endif()
# On some systems (e.g., Fedora 21), there is a bug in the cmake code
# that detects GLUT libraries. The following ugliness is a workaround for
# this problem.
if (NOT GLUT_Xmu_LIBRARY OR NOT GLUT_Xmi_LIBRARY)
if (NOT GLUT_Xmu_LIBRARY)
set(GLUT_Xmu_LIBRARY "")
message(WARNING "Clearing bogus value for GLUT_Xmu_LIBRARY.")
message(WARNING "Your version of CMake may be buggy.")
endif()
if (NOT GLUT_Xmi_LIBRARY)
set(GLUT_Xmi_LIBRARY "")
message(WARNING "Clearing bogus value for GLUT_Xmi_LIBRARY.")
message(WARNING "Your version of CMake may be buggy.")
endif()
set(GLUT_LIBRARIES "${GLUT_glut_LIBRARY}")
endif()
else()
set(JAS_HAVE_OPENGL 0)
set(OPENGL_INCLUDE_DIR "")
set(OPENGL_LIBRARIES "")
set(GLUT_INCLUDE_DIR "")
set(GLUT_LIBRARIES "")
endif()
message("JAS_HAVE_OPENGL: ${JAS_HAVE_OPENGL}")
################################################################################
# Check for the Math library.
################################################################################
find_library(MATH_LIBRARY m)
if (NOT MATH_LIBRARY)
set(MATH_LIBRARY "")
endif()
################################################################################
#
################################################################################
if (JAS_MEMORY_LIMIT)
add_definitions("-DJAS_MEMORY_LIMIT=${JAS_MEMORY_LIMIT}")
endif()
################################################################################
#
################################################################################
if (JAS_ENABLE_SHARED)
# 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}/${CMAKE_INSTALL_LIBDIR}")
endif("${isSystemDir}" STREQUAL "-1")
endif()
################################################################################
#
################################################################################
add_subdirectory(src/libjasper)
if (JAS_ENABLE_PROGRAMS)
add_subdirectory(src/appl)
endif ()
if (JAS_ENABLE_DOC)
add_subdirectory(doc)
endif ()
# The package configuation (pc) file should be installed in
# ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build/jasper.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/build/jasper.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/build/jasper.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(FILES "README" DESTINATION "${CMAKE_INSTALL_DOCDIR}")
################################################################################
# Test suite
################################################################################
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/test/bin/wrapper.in"
"${CMAKE_CURRENT_BINARY_DIR}/test/bin/wrapper" @ONLY)
if (BASH_PROGRAM)
add_test(run_test_1
"${BASH_PROGRAM}" "${CMAKE_CURRENT_BINARY_DIR}/test/bin/wrapper"
"${CMAKE_CURRENT_SOURCE_DIR}/test/bin/run_test_1")
add_test(run_test_2
"${BASH_PROGRAM}" "${CMAKE_CURRENT_BINARY_DIR}/test/bin/wrapper"
"${CMAKE_CURRENT_SOURCE_DIR}/test/bin/run_test_2")
add_test(run_test_3
"${BASH_PROGRAM}" "${CMAKE_CURRENT_BINARY_DIR}/test/bin/wrapper"
"${CMAKE_CURRENT_SOURCE_DIR}/test/bin/run_test_3")
add_test(run_test_4
"${BASH_PROGRAM}" "${CMAKE_CURRENT_BINARY_DIR}/test/bin/wrapper"
"${CMAKE_CURRENT_SOURCE_DIR}/test/bin/run_test_4")
endif()