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