[trunk] Mark OpenJPEG to be ABI incompatible with previous one, move to SONAME 7
[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 1)
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 #   2.1   |  7
51 # above is the recommendation by the OPJ team. If you really need to override this default,
52 # you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
53 # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
54 if(NOT OPENJPEG_SOVERSION)
55   SET(OPENJPEG_SOVERSION 7)
56 endif(NOT OPENJPEG_SOVERSION)
57 set(OPENJPEG_LIBRARY_PROPERTIES
58   VERSION   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
59   SOVERSION "${OPENJPEG_SOVERSION}"
60 )
61
62 # --------------------------------------------------------------------------
63 # Path to additional CMake modules
64 set(CMAKE_MODULE_PATH
65     ${CMAKE_SOURCE_DIR}/cmake
66     ${CMAKE_MODULE_PATH})
67
68 # --------------------------------------------------------------------------
69 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
70 # warnings
71 if(WIN32)
72   if(NOT BORLAND)
73     if(NOT CYGWIN)
74       if(NOT MINGW)
75         if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
76           add_definitions(
77             -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
78             -D_CRT_IS_WCTYPE_NO_DEPRECATE
79             -D_CRT_MANAGED_FP_NO_DEPRECATE
80             -D_CRT_NONSTDC_NO_DEPRECATE
81             -D_CRT_SECURE_NO_DEPRECATE
82             -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
83             -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
84             -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
85             -D_CRT_VCCLRIT_NO_DEPRECATE
86             -D_SCL_SECURE_NO_DEPRECATE
87             )
88         endif()
89       endif()
90     endif()
91   endif()
92 endif()
93
94
95 # --------------------------------------------------------------------------
96 # Install directories
97
98 string(TOLOWER ${PROJECT_NAME} projectname)
99 set(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
100
101 if(NOT OPENJPEG_INSTALL_BIN_DIR)
102   set(OPENJPEG_INSTALL_BIN_DIR "bin")
103 endif()
104
105 if(NOT OPENJPEG_INSTALL_LIB_DIR)
106   set(OPENJPEG_INSTALL_LIB_DIR "lib")
107 endif()
108
109 if(NOT OPENJPEG_INSTALL_SHARE_DIR)
110   set(OPENJPEG_INSTALL_SHARE_DIR "share")
111 endif()
112
113 if(NOT OPENJPEG_INSTALL_DATA_DIR)
114   set(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
115 endif()
116
117 if(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
118   set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
119 endif()
120
121 if(NOT OPENJPEG_INSTALL_MAN_DIR)
122   set(OPENJPEG_INSTALL_MAN_DIR "share/man/")
123 endif()
124
125 if(NOT OPENJPEG_INSTALL_DOC_DIR)
126   set(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
127 endif()
128
129 if(NOT OPENJPEG_INSTALL_JNI_DIR)
130   if(WIN32)
131     set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_BIN_DIR})
132   else()
133     set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR})
134   endif()
135 endif()
136
137 if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
138   # We could install *.cmake files in share/ however those files contains
139   # hardcoded path to libraries on a multi-arch system (fedora/debian) those
140   # path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu)
141   set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
142 endif()
143
144 #-----------------------------------------------------------------------------
145 # Big endian test:
146 include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
147 TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
148
149 #-----------------------------------------------------------------------------
150 # Setup file for setting custom ctest vars
151 configure_file(
152   ${CMAKE_SOURCE_DIR}/cmake/CTestCustom.cmake.in
153   ${CMAKE_BINARY_DIR}/CTestCustom.cmake
154   @ONLY
155   )
156
157 #-----------------------------------------------------------------------------
158 # OpenJPEG build configuration options.
159 option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
160 set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
161 set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
162 mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
163
164 #-----------------------------------------------------------------------------
165 # configure name mangling to allow multiple libraries to coexist
166 # peacefully
167 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
168 set(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
169 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
170                ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
171                @ONLY)
172 endif()
173
174 #-----------------------------------------------------------------------------
175 # Compiler specific flags:
176 if(CMAKE_COMPILER_IS_GNUCC)
177   # For all builds, make sure openjpeg is std99 compliant:
178   # set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
179   # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
180   set(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
181 endif()
182
183 #-----------------------------------------------------------------------------
184 # opj_config.h generation (1/2)
185
186 # Check if some include files are provided by the system
187 include(EnsureFileInclude)
188 # These files are mandatory
189 ensure_file_include("string.h"   HAVE_STRING_H YES)
190 ensure_file_include("memory.h"   HAVE_MEMORY_H YES)
191 ensure_file_include("stdlib.h"   HAVE_STDLIB_H YES)
192 ensure_file_include("stdio.h"    HAVE_STDIO_H  YES)
193 ensure_file_include("math.h"     HAVE_MATH_H   YES)
194 ensure_file_include("float.h"    HAVE_FLOAT_H  YES)
195 ensure_file_include("time.h"     HAVE_TIME_H   YES)
196 ensure_file_include("stdarg.h"   HAVE_STDARG_H YES)
197 ensure_file_include("ctype.h"    HAVE_CTYPE_H  YES)
198 ensure_file_include("assert.h"   HAVE_ASSERT_H YES)
199
200 # For the following files, we provide an alternative, they are not mandatory
201 ensure_file_include("stdint.h"   OPJ_HAVE_STDINT_H   NO)
202 ensure_file_include("inttypes.h" OPJ_HAVE_INTTYPES_H NO)
203
204 # why check this one ? for openjpip ?
205 include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
206 CHECK_INCLUDE_FILE("strings.h"      HAVE_STRINGS_H)
207 CHECK_INCLUDE_FILE("sys/stat.h"     HAVE_SYS_STAT_H)
208 CHECK_INCLUDE_FILE("sys/types.h"    HAVE_SYS_TYPES_H)
209 CHECK_INCLUDE_FILE("unistd.h"       HAVE_UNISTD_H)
210
211 # Enable Large file support
212 include(TestLargeFiles)
213 OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
214
215 #-----------------------------------------------------------------------------
216 # Build Library
217 if(BUILD_JPIP_SERVER)
218   find_package(CURL REQUIRED)
219   find_package(FCGI REQUIRED)
220   find_package(Threads REQUIRED)
221   if(NOT CMAKE_USE_PTHREADS_INIT)
222     message(FATAL_ERROR "Only pthread are supported")
223   endif()
224 endif()
225 add_subdirectory(src/lib)
226
227 #-----------------------------------------------------------------------------
228 # Build Applications
229 option(BUILD_CODEC "Build the CODEC executables" ON)
230 option(BUILD_MJ2 "Build the MJ2 executables." OFF)
231 option(BUILD_JPWL "Build the JPWL library and executables" OFF)
232 option(BUILD_JPIP "Build the JPIP library and executables." OFF)
233 if(BUILD_JPIP)
234   option(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
235 endif()
236 option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
237 option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
238 option(BUILD_JP3D "Build the JP3D comp" OFF)
239 mark_as_advanced(BUILD_VIEWER)
240 mark_as_advanced(BUILD_JAVA)
241 mark_as_advanced(BUILD_JP3D)
242
243 if(BUILD_CODEC OR BUILD_MJ2)
244   # OFF: It will only build 3rd party libs if they are not found on the system
245   # ON: 3rd party libs will ALWAYS be build, and used
246   option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
247   add_subdirectory(thirdparty)
248   add_subdirectory(src/bin)
249 endif ()
250 add_subdirectory(wrapping)
251
252 #-----------------------------------------------------------------------------
253 # opj_config.h generation (2/2)
254 configure_file(
255  ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in
256  ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
257  @ONLY
258  )
259  
260  configure_file(
261  ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in
262  ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h
263  @ONLY
264  )
265
266 #-----------------------------------------------------------------------------
267 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
268 option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
269 if(BUILD_DOC)
270   add_subdirectory(doc)
271 endif()
272
273 #-----------------------------------------------------------------------------
274 # Buld Testing
275 option(BUILD_TESTING "Build the tests." OFF)
276 if(BUILD_TESTING)
277   if(BUILD_CODEC)
278     enable_testing()
279     include(CTest)
280
281     # Search openjpeg data needed for the tests
282     # They could be found via svn on the OpenJPEG google code project
283     # svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo)
284     find_path(OPJ_DATA_ROOT README-OPJ-Data
285       PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data
286       NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
287       )
288
289     # Add repository where to find tests
290     add_subdirectory(tests)
291
292   else()
293     message(FATAL_ERROR "You need build codec to run the tests")
294   endif()
295 endif()
296
297 #-----------------------------------------------------------------------------
298 # install all targets referenced as OPENJPEGTargets
299 install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
300 configure_file( ${OPENJPEG_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
301   ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
302   @ONLY
303 )
304 install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
305   DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
306 )
307
308 #-----------------------------------------------------------------------------
309 # install CHANGES and LICENSE
310 if(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
311   install(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
312 endif()
313 install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
314
315 include (cmake/OpenJPEGCPack.cmake)
316
317 #-----------------------------------------------------------------------------
318 # pkgconfig support
319 if(UNIX)
320   # install in lib and not share (see multi-arch note above)
321   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in
322     ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY)
323   install( FILES  ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION
324     ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
325 #
326   if(BUILD_JPWL)
327   # install in lib and not share (see multi-arch note above)
328   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpwl/libopenjpwl.pc.cmake.in
329     ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc @ONLY)
330   install( FILES  ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc DESTINATION
331     ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
332   endif()
333 #
334   if(BUILD_JPIP)
335   # install in lib and not share (see multi-arch note above)
336   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in
337     ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY)
338   install( FILES  ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION
339     ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
340   endif()
341 #
342   if(BUILD_JP3D)
343   # install in lib and not share (see multi-arch note above)
344   configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp3d/libopenjp3d.pc.cmake.in
345     ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc @ONLY)
346   install( FILES  ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc DESTINATION
347     ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
348   endif()
349 endif()
350
351 #-----------------------------------------------------------------------------