[1.5] jp2_read_boxhdr() call ignores return value
[openjpeg.git] / CMakeLists.txt
1 # Main CMakeLists.txt to build the OpenJPEG project using CMake (www.cmake.org)
2 # Written by Mathieu Malaterre
3
4 # This CMake project will by default create a library called openjpeg
5 # But if you want to use this project within your own (CMake) project
6 # you will eventually like to prefix the library to avoid linking confusion
7 # For this purpose you can define a CMake var: OPENJPEG_NAMESPACE to whatever you like
8 # e.g.:
9 # SET(OPENJPEG_NAMESPACE "GDCMOPENJPEG")
10 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
11
12 IF(COMMAND CMAKE_POLICY)
13   CMAKE_POLICY(SET CMP0003 NEW)
14 ENDIF(COMMAND CMAKE_POLICY)
15
16 IF(NOT OPENJPEG_NAMESPACE)
17   SET(OPENJPEG_NAMESPACE "OPENJPEG")
18   SET(OPENJPEG_STANDALONE 1)
19 ENDIF(NOT OPENJPEG_NAMESPACE)
20 # In all cases:
21 STRING(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
22
23 PROJECT(${OPENJPEG_NAMESPACE} C)
24
25 # Do full dependency headers.
26 INCLUDE_REGULAR_EXPRESSION("^.*$")
27
28 #-----------------------------------------------------------------------------
29 # OPENJPEG version number, useful for packaging and doxygen doc:
30 SET(OPENJPEG_VERSION_MAJOR 1)
31 SET(OPENJPEG_VERSION_MINOR 5)
32 SET(OPENJPEG_VERSION_BUILD 0)
33 SET(OPENJPEG_VERSION
34   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
35 SET(PACKAGE_VERSION
36   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
37
38 # Because autotools does not support X.Y notation for SOVERSION, we have to use
39 # two numerorations, one for the openjpeg version and one for openjpeg soversion
40 # version | soversion
41 #   1.0   |  0
42 #   1.1   |  1
43 #   1.2   |  2
44 #   1.3   |  3
45 #   1.4   |  4
46 #   1.5   |  5
47 #   2.0   |  6
48 # above is the recommendation by the OPJ team. If you really need to override this default,
49 # you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
50 # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
51 if(NOT OPENJPEG_SOVERSION)
52   SET(OPENJPEG_SOVERSION 5)
53 endif(NOT OPENJPEG_SOVERSION)
54 SET(OPENJPEG_LIBRARY_PROPERTIES
55   VERSION   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
56   SOVERSION "${OPENJPEG_SOVERSION}"
57 )
58
59 # --------------------------------------------------------------------------
60 # Path to additional CMake modules
61 SET(CMAKE_MODULE_PATH
62     ${CMAKE_SOURCE_DIR}/CMake
63     ${CMAKE_MODULE_PATH})
64
65 # --------------------------------------------------------------------------
66 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
67 # warnings
68 IF(WIN32)
69   IF(NOT BORLAND)
70     IF(NOT CYGWIN)
71       IF(NOT MINGW)
72         IF(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
73           ADD_DEFINITIONS(
74             -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
75             -D_CRT_IS_WCTYPE_NO_DEPRECATE
76             -D_CRT_MANAGED_FP_NO_DEPRECATE
77             -D_CRT_NONSTDC_NO_DEPRECATE
78             -D_CRT_SECURE_NO_DEPRECATE
79             -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
80             -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
81             -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
82             -D_CRT_VCCLRIT_NO_DEPRECATE
83             -D_SCL_SECURE_NO_DEPRECATE
84             )
85         ENDIF(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
86       ENDIF(NOT MINGW)
87     ENDIF(NOT CYGWIN)
88   ENDIF(NOT BORLAND)
89 ENDIF(WIN32)
90
91
92 # --------------------------------------------------------------------------
93 # Install directories
94
95 STRING(TOLOWER ${PROJECT_NAME} projectname)
96 SET(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
97
98 IF(NOT OPENJPEG_INSTALL_BIN_DIR)
99   SET(OPENJPEG_INSTALL_BIN_DIR "bin")
100 ENDIF(NOT OPENJPEG_INSTALL_BIN_DIR)
101
102 IF(NOT OPENJPEG_INSTALL_LIB_DIR)
103   SET(OPENJPEG_INSTALL_LIB_DIR "lib")
104 ENDIF(NOT OPENJPEG_INSTALL_LIB_DIR)
105
106 # The following will compute the amount of parent dir to go
107 # from include to lib. it works nicely with 
108 # OPENJPEG_INSTALL_LIB_DIR=lib
109 # OPENJPEG_INSTALL_LIB_DIR=lib/
110 # OPENJPEG_INSTALL_LIB_DIR=/lib
111 # OPENJPEG_INSTALL_LIB_DIR=lib/gnu-linux-x64
112 STRING(REPLACE "/" ";" relative_to_lib ${OPENJPEG_INSTALL_LIB_DIR})
113 set(relative_parent "..")
114 foreach( elem ${relative_to_lib})
115   set( relative_parent "${relative_parent}/.." )
116 endforeach()
117
118 IF(NOT OPENJPEG_INSTALL_SHARE_DIR)
119   SET(OPENJPEG_INSTALL_SHARE_DIR "share")
120 ENDIF(NOT OPENJPEG_INSTALL_SHARE_DIR)
121
122 IF(NOT OPENJPEG_INSTALL_DATA_DIR)
123   SET(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
124 ENDIF(NOT OPENJPEG_INSTALL_DATA_DIR)
125
126 IF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
127   SET(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
128 ENDIF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
129
130 IF(NOT OPENJPEG_INSTALL_MAN_DIR)
131   SET(OPENJPEG_INSTALL_MAN_DIR "share/man/")
132 ENDIF(NOT OPENJPEG_INSTALL_MAN_DIR)
133
134 IF(NOT OPENJPEG_INSTALL_DOC_DIR)
135   SET(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
136 ENDIF(NOT OPENJPEG_INSTALL_DOC_DIR)
137
138 IF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
139   # We could install *.cmake files in share/ however those files contains
140   # hardcoded path to libraries on a multi-arch system (fedora/debian) those
141   # path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu)
142   SET(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
143 ENDIF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
144
145 #-----------------------------------------------------------------------------
146 # Big endian test:
147 INCLUDE (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
148 TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
149
150 #-----------------------------------------------------------------------------
151 # Setup file for setting custom ctest vars
152 CONFIGURE_FILE(
153   ${CMAKE_SOURCE_DIR}/CMake/CTestCustom.cmake.in
154   ${CMAKE_BINARY_DIR}/CTestCustom.cmake
155   @ONLY
156   )
157
158 #-----------------------------------------------------------------------------
159 # OpenJPEG build configuration options.
160 OPTION(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
161 SET (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
162 SET (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
163 MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
164
165 #-----------------------------------------------------------------------------
166 # configure name mangling to allow multiple libraries to coexist
167 # peacefully
168 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
169 SET(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
170 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
171                ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
172                @ONLY)
173 ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
174
175 #-----------------------------------------------------------------------------
176 # pkgconfig support
177 IF(UNIX)
178   # install in lib and not share (see multi-arch note above)
179   CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libopenjpeg1.pc.cmake
180     ${CMAKE_CURRENT_BINARY_DIR}/libopenjpeg1.pc @ONLY)
181   INSTALL( FILES  ${CMAKE_CURRENT_BINARY_DIR}/libopenjpeg1.pc DESTINATION
182     ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
183   INSTALL( CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink
184   \"libopenjpeg1.pc\"
185   \"\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_SHARE_DIR}/pkgconfig/libopenjpeg.pc\")")
186 ENDIF(UNIX)
187
188 #-----------------------------------------------------------------------------
189 # Compiler specific flags:
190 IF(CMAKE_COMPILER_IS_GNUCC)
191   # For all builds, make sure openjpeg is std99 compliant:
192   # SET(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
193   # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
194   SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
195 ENDIF(CMAKE_COMPILER_IS_GNUCC)
196
197 #-----------------------------------------------------------------------------
198 # opj_config.h generation (1/2)
199 INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
200 CHECK_INCLUDE_FILE("strings.h"      HAVE_STRINGS_H)
201 CHECK_INCLUDE_FILE("inttypes.h"     HAVE_INTTYPES_H)
202 CHECK_INCLUDE_FILE("memory.h"       HAVE_MEMORY_H)
203 CHECK_INCLUDE_FILE("stdint.h"       HAVE_STDINT_H)
204 CHECK_INCLUDE_FILE("stdlib.h"       HAVE_STDLIB_H)
205 CHECK_INCLUDE_FILE("string.h"       HAVE_STRING_H)
206 CHECK_INCLUDE_FILE("sys/stat.h"     HAVE_SYS_STAT_H)
207 CHECK_INCLUDE_FILE("sys/types.h"    HAVE_SYS_TYPES_H)
208 CHECK_INCLUDE_FILE("unistd.h"       HAVE_UNISTD_H)
209
210
211 #-----------------------------------------------------------------------------
212 # Build Library
213 INCLUDE_DIRECTORIES(BEFORE ${OPENJPEG_BINARY_DIR})
214 ADD_SUBDIRECTORY(libopenjpeg)
215
216 #-----------------------------------------------------------------------------
217 # Build Applications
218 OPTION(BUILD_CODEC "Build the CODEC executables" ON)
219 OPTION(BUILD_MJ2 "Build the MJ2 executables." OFF)
220 OPTION(BUILD_JPWL "Build the JPWL library and executables" OFF)
221 OPTION(BUILD_JPIP "Build the JPIP library and executables." OFF)
222 IF(BUILD_JPIP)
223   OPTION(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
224 ENDIF(BUILD_JPIP)
225 OPTION(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
226 OPTION(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
227 MARK_AS_ADVANCED(BUILD_VIEWER)
228 MARK_AS_ADVANCED(BUILD_JAVA)
229
230 IF(BUILD_CODEC OR BUILD_MJ2)
231   # OFF: It will only build 3rd party libs if they are not found on the system
232   # ON: 3rd party libs will ALWAYS be build, and used
233   OPTION(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
234   ADD_SUBDIRECTORY(thirdparty)
235   ADD_SUBDIRECTORY(applications)
236 ENDIF (BUILD_CODEC OR BUILD_MJ2)
237
238 #-----------------------------------------------------------------------------
239 # opj_config.h generation (2/2)
240 CONFIGURE_FILE("${OPENJPEG_SOURCE_DIR}/opj_config.h.cmake.in"
241  "${OPENJPEG_BINARY_DIR}/opj_config.h"
242  @ONLY
243  )
244
245 #-----------------------------------------------------------------------------
246 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
247 OPTION(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
248 IF(BUILD_DOC)
249     ADD_SUBDIRECTORY(doc)
250 ENDIF(BUILD_DOC)
251
252 #-----------------------------------------------------------------------------
253 # Buld Testing
254 OPTION(BUILD_TESTING "Build the tests." OFF)
255 IF(BUILD_TESTING)
256   IF(BUILD_CODEC)
257     ENABLE_TESTING()
258     INCLUDE(CTest)
259   
260     # Search openjpeg data needed for the tests
261     # They could be found via svn on the OpenJPEG google code project
262     # svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo) 
263     FIND_PATH(OPJ_DATA_ROOT README-OPJ-Data
264       PATHS
265       $ENV{OPJ_DATA_ROOT}
266       ${CMAKE_SOURCE_DIR}/../data
267       ${CMAKE_SOURCE_DIR}/../../data
268       )
269
270     # Add repository where to find tests
271     ADD_SUBDIRECTORY(tests)
272     
273   ELSE(BUILD_CODEC)
274     message(FATAL_ERROR "You need build codec to run the tests")
275   ENDIF(BUILD_CODEC)
276 ENDIF(BUILD_TESTING)
277
278 #-----------------------------------------------------------------------------
279 # install all targets referenced as OPENJPEGTargets
280 INSTALL(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
281 CONFIGURE_FILE( ${OPENJPEG_SOURCE_DIR}/CMake/OpenJPEGConfig.cmake.in
282   ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
283   @ONLY
284 )
285 INSTALL( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
286   DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
287 )
288
289 #-----------------------------------------------------------------------------
290 # install CHANGES and LICENSE
291 IF(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
292   INSTALL(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
293 ENDIF(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
294 INSTALL(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
295
296 INCLUDE (CMake/OpenJPEGCPack.cmake)