ENH: jpwl subdirectory is now build also on Unix systems.
[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 4)
32 SET(OPENJPEG_VERSION_BUILD 0)
33 SET(OPENJPEG_VERSION
34   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
35
36 # This setting of SOVERSION assumes that any API change
37 # will increment either the minor or major version number of openjpeg
38 SET(OPENJPEG_LIBRARY_PROPERTIES
39   VERSION   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
40   SOVERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}"
41 )
42 # You will also need to define a value for the following variables:
43 # OPENJPEG_INSTALL_BIN_DIR          - binary dir (executables)
44 # OPENJPEG_INSTALL_LIB_DIR          - library dir (libs)
45 # OPENJPEG_INSTALL_DATA_DIR         - share dir (say, examples, data, etc)
46 # OPENJPEG_INSTALL_INCLUDE_DIR      - include dir (headers)
47
48
49 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
50 # warnings
51 IF(WIN32)
52   IF(NOT BORLAND)
53     IF(NOT CYGWIN)
54       IF(NOT MINGW)
55         IF(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
56           ADD_DEFINITIONS(
57             -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
58             -D_CRT_IS_WCTYPE_NO_DEPRECATE
59             -D_CRT_MANAGED_FP_NO_DEPRECATE
60             -D_CRT_NONSTDC_NO_DEPRECATE
61             -D_CRT_SECURE_NO_DEPRECATE
62             -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
63             -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
64             -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
65             -D_CRT_VCCLRIT_NO_DEPRECATE
66             -D_SCL_SECURE_NO_DEPRECATE
67             )
68         ENDIF(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
69       ENDIF(NOT MINGW)
70     ENDIF(NOT CYGWIN)
71   ENDIF(NOT BORLAND)
72 ENDIF(WIN32)
73
74
75 # --------------------------------------------------------------------------
76 # Install directories
77
78 STRING(TOLOWER ${PROJECT_NAME} projectname)
79 SET(subdir "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
80
81 IF(NOT OPENJPEG_INSTALL_BIN_DIR)
82   SET(OPENJPEG_INSTALL_BIN_DIR "bin")
83 ENDIF(NOT OPENJPEG_INSTALL_BIN_DIR)
84
85 IF(NOT OPENJPEG_INSTALL_LIB_DIR)
86   SET(OPENJPEG_INSTALL_LIB_DIR "lib")
87 ENDIF(NOT OPENJPEG_INSTALL_LIB_DIR)
88
89 IF(NOT OPENJPEG_INSTALL_DATA_DIR)
90   SET(OPENJPEG_INSTALL_DATA_DIR "share/${subdir}")
91 ENDIF(NOT OPENJPEG_INSTALL_DATA_DIR)
92
93 IF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
94   SET(OPENJPEG_INSTALL_INCLUDE_DIR "include/${subdir}")
95 ENDIF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
96
97 IF(NOT OPENJPEG_INSTALL_DOC_DIR)
98   SET(OPENJPEG_INSTALL_DOC_DIR "share/doc/${subdir}")
99 ENDIF(NOT OPENJPEG_INSTALL_DOC_DIR)
100
101 IF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
102   SET(OPENJPEG_INSTALL_PACKAGE_DIR ${OPENJPEG_INSTALL_LIB_DIR}/${subdir}
103     CACHE INTERNAL "")
104 ENDIF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
105
106 #-----------------------------------------------------------------------------
107 # Test for some required system information.
108 INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityC.cmake)
109
110 #-----------------------------------------------------------------------------
111 # Test for getopt being available in this system
112 INCLUDE (${PROJECT_SOURCE_DIR}/CMake/CheckHaveGetopt.cmake )
113
114 #-----------------------------------------------------------------------------
115 # Setup file for setting custom ctest vars
116 CONFIGURE_FILE(
117   ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CTestCustom.cmake.in
118   ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
119   @ONLY
120   )
121
122 #-----------------------------------------------------------------------------
123 # OpenJPEG build configuration options.
124 OPTION(BUILD_SHARED_LIBS "Build OpenJPEG with shared libraries." OFF)
125
126 #-----------------------------------------------------------------------------
127 SET (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
128 SET (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
129 MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
130
131
132 #-----------------------------------------------------------------------------
133 # For the codec...
134 OPTION(BUILD_EXAMPLES "Build the Examples (codec...)." ON)
135
136
137 # configure name mangling to allow multiple libraries to coexist
138 # peacefully
139 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
140 SET(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
141 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
142                ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
143                @ONLY IMMEDIATE)
144 ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
145
146 #-----------------------------------------------------------------------------
147 # Always build the library
148 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
149 SUBDIRS(
150   libopenjpeg
151   mj2
152   jpwl
153   )
154
155 IF(NOT UNIX)
156 SUBDIRS(
157   jp3d
158   indexer_JPIP
159   )
160 ENDIF(NOT UNIX)
161
162 #-----------------------------------------------------------------------------
163 # Build example only if requested
164 IF(BUILD_EXAMPLES)
165   SUBDIRS(codec)
166 ENDIF(BUILD_EXAMPLES)
167
168 #-----------------------------------------------------------------------------
169 # For the documentation
170 OPTION(BUILD_DOCUMENTATION "Build the doxygen documentation" OFF)
171 IF(BUILD_DOCUMENTATION)
172   SUBDIRS(doc)
173 ENDIF(BUILD_DOCUMENTATION)
174
175 #-----------------------------------------------------------------------------
176 # For openjpeg team if they ever want CDash+CMake
177 OPTION(BUILD_TESTING "Build the tests." OFF)
178 IF(BUILD_TESTING)
179   ENABLE_TESTING()
180   INCLUDE(CTest)
181 ENDIF(BUILD_TESTING)
182
183 # Adding test with dataset from:
184 # http://www.crc.ricoh.com/~gormish/jpeg2000conformance/
185 # -> wget http://www.crc.ricoh.com/~gormish/jpeg2000conformance/j2kp4files_v1_5.zip
186 # http://www.jpeg.org/jpeg2000guide/testimages/testimages.html
187 #-----------------------------------------------------------------------------
188 # Adding JPEG2000_CONFORMANCE_DATA_ROOT
189 FIND_PATH(JPEG2000_CONFORMANCE_DATA_ROOT testimages.html
190   ${OPENJPEG_SOURCE_DIR}/../jpeg2000testimages
191   $ENV{JPEG2000_CONFORMANCE_DATA_ROOT}
192 )
193
194 #-----------------------------------------------------------------------------
195 # Compiler specific flags:
196 IF(CMAKE_COMPILER_IS_GNUCC)
197   # For all builds, make sure openjpeg is std99 compliant:
198   # SET(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
199   # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
200   SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
201 ENDIF(CMAKE_COMPILER_IS_GNUCC)
202
203 # install all targets referenced as OPENJPEGTargets
204 install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
205 CONFIGURE_FILE( ${OPENJPEG_SOURCE_DIR}/CMake/OpenJPEGConfig.cmake.in
206   ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
207   @ONLY
208 )
209 INSTALL( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
210   DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
211 )
212