1 # Main CMakeLists.txt to build the OpenJPEG project using CMake (www.cmake.org)
2 # Written by Mathieu Malaterre
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
9 # set(OPENJPEG_NAMESPACE "GDCMOPENJPEG")
10 cmake_minimum_required(VERSION 2.8.2)
12 if(COMMAND CMAKE_POLICY)
13 cmake_policy(SET CMP0003 NEW)
16 if(NOT OPENJPEG_NAMESPACE)
17 set(OPENJPEG_NAMESPACE "OPENJPEG")
18 set(OPENJPEG_STANDALONE 1)
21 #string(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
22 set(OPENJPEG_LIBRARY_NAME openjp2)
24 project(${OPENJPEG_NAMESPACE} C)
26 # Do full dependency headers.
27 include_regular_expression("^.*$")
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)
35 "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
37 "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
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
52 # above is the recommendation by the OPJ team. If you really need to override this default,
53 # you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
54 # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
55 if(NOT OPENJPEG_SOVERSION)
56 SET(OPENJPEG_SOVERSION 7)
57 endif(NOT OPENJPEG_SOVERSION)
58 set(OPENJPEG_LIBRARY_PROPERTIES
59 VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
60 SOVERSION "${OPENJPEG_SOVERSION}"
63 # --------------------------------------------------------------------------
64 # Path to additional CMake modules
66 ${CMAKE_SOURCE_DIR}/cmake
69 # --------------------------------------------------------------------------
70 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
76 if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
78 -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
79 -D_CRT_IS_WCTYPE_NO_DEPRECATE
80 -D_CRT_MANAGED_FP_NO_DEPRECATE
81 -D_CRT_NONSTDC_NO_DEPRECATE
82 -D_CRT_SECURE_NO_DEPRECATE
83 -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
84 -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
85 -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
86 -D_CRT_VCCLRIT_NO_DEPRECATE
87 -D_SCL_SECURE_NO_DEPRECATE
96 # --------------------------------------------------------------------------
99 string(TOLOWER ${PROJECT_NAME} projectname)
100 set(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
102 if(NOT OPENJPEG_INSTALL_BIN_DIR)
103 set(OPENJPEG_INSTALL_BIN_DIR "bin")
106 if(NOT OPENJPEG_INSTALL_LIB_DIR)
107 set(OPENJPEG_INSTALL_LIB_DIR "lib")
110 if(NOT OPENJPEG_INSTALL_SHARE_DIR)
111 set(OPENJPEG_INSTALL_SHARE_DIR "share")
114 if(NOT OPENJPEG_INSTALL_DATA_DIR)
115 set(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
118 if(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
119 set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
122 if(NOT OPENJPEG_INSTALL_MAN_DIR)
123 set(OPENJPEG_INSTALL_MAN_DIR "share/man/")
126 if(NOT OPENJPEG_INSTALL_DOC_DIR)
127 set(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
130 if(NOT OPENJPEG_INSTALL_JNI_DIR)
132 set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_BIN_DIR})
134 set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR})
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}")
145 #-----------------------------------------------------------------------------
147 include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
148 TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
150 #-----------------------------------------------------------------------------
151 # Setup file for setting custom ctest vars
153 ${CMAKE_SOURCE_DIR}/cmake/CTestCustom.cmake.in
154 ${CMAKE_BINARY_DIR}/CTestCustom.cmake
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)
165 #-----------------------------------------------------------------------------
166 # configure name mangling to allow multiple libraries to coexist
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
175 #-----------------------------------------------------------------------------
176 # Compiler specific flags:
177 if(CMAKE_COMPILER_IS_GNUCC)
178 # For all builds, make sure openjpeg is std99 compliant:
179 # set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
180 # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
181 set(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
184 #-----------------------------------------------------------------------------
185 # opj_config.h generation (1/2)
187 # Check if some include files are provided by the system
188 include(EnsureFileInclude)
189 # These files are mandatory
190 ensure_file_include("string.h" HAVE_STRING_H YES)
191 ensure_file_include("memory.h" HAVE_MEMORY_H YES)
192 ensure_file_include("stdlib.h" HAVE_STDLIB_H YES)
193 ensure_file_include("stdio.h" HAVE_STDIO_H YES)
194 ensure_file_include("math.h" HAVE_MATH_H YES)
195 ensure_file_include("float.h" HAVE_FLOAT_H YES)
196 ensure_file_include("time.h" HAVE_TIME_H YES)
197 ensure_file_include("stdarg.h" HAVE_STDARG_H YES)
198 ensure_file_include("ctype.h" HAVE_CTYPE_H YES)
199 ensure_file_include("assert.h" HAVE_ASSERT_H YES)
201 # For the following files, we provide an alternative, they are not mandatory
202 ensure_file_include("stdint.h" OPJ_HAVE_STDINT_H NO)
203 ensure_file_include("inttypes.h" OPJ_HAVE_INTTYPES_H NO)
205 # why check this one ? for openjpip ?
206 include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
207 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
208 CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
209 CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
210 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
212 # Enable Large file support
213 include(TestLargeFiles)
214 OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
216 #-----------------------------------------------------------------------------
218 if(BUILD_JPIP_SERVER)
219 find_package(CURL REQUIRED)
220 find_package(FCGI REQUIRED)
221 find_package(Threads REQUIRED)
222 if(NOT CMAKE_USE_PTHREADS_INIT)
223 message(FATAL_ERROR "Only pthread are supported")
226 add_subdirectory(src/lib)
228 #-----------------------------------------------------------------------------
230 option(BUILD_CODEC "Build the CODEC executables" ON)
231 option(BUILD_MJ2 "Build the MJ2 executables." OFF)
232 option(BUILD_JPWL "Build the JPWL library and executables" OFF)
233 option(BUILD_JPIP "Build the JPIP library and executables." OFF)
235 option(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
237 option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
238 option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
239 option(BUILD_JP3D "Build the JP3D comp" OFF)
240 mark_as_advanced(BUILD_VIEWER)
241 mark_as_advanced(BUILD_JAVA)
242 mark_as_advanced(BUILD_JP3D)
244 if(BUILD_CODEC OR BUILD_MJ2)
245 # OFF: It will only build 3rd party libs if they are not found on the system
246 # ON: 3rd party libs will ALWAYS be build, and used
247 option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
248 add_subdirectory(thirdparty)
249 add_subdirectory(src/bin)
251 add_subdirectory(wrapping)
253 #-----------------------------------------------------------------------------
254 # opj_config.h generation (2/2)
256 ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in
257 ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
262 ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in
263 ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h
267 #-----------------------------------------------------------------------------
268 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
269 option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
271 add_subdirectory(doc)
274 #-----------------------------------------------------------------------------
276 option(BUILD_TESTING "Build the tests." OFF)
282 # Search openjpeg data needed for the tests
283 # They could be found via svn on the OpenJPEG google code project
284 # svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo)
285 find_path(OPJ_DATA_ROOT README-OPJ-Data
286 PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data
287 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
290 # Add repository where to find tests
291 add_subdirectory(tests)
294 message(FATAL_ERROR "You need build codec to run the tests")
298 #-----------------------------------------------------------------------------
299 # install all targets referenced as OPENJPEGTargets
300 install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
301 configure_file( ${OPENJPEG_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
302 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
305 install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
306 DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
309 #-----------------------------------------------------------------------------
310 # install CHANGES and LICENSE
311 if(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
312 install(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
314 install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
316 include (cmake/OpenJPEGCPack.cmake)
318 #-----------------------------------------------------------------------------
321 # install in lib and not share (see multi-arch note above)
322 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in
323 ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY)
324 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION
325 ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
328 # install in lib and not share (see multi-arch note above)
329 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpwl/libopenjpwl.pc.cmake.in
330 ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc @ONLY)
331 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc DESTINATION
332 ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
336 # install in lib and not share (see multi-arch note above)
337 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in
338 ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY)
339 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION
340 ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
344 # install in lib and not share (see multi-arch note above)
345 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp3d/libopenjp3d.pc.cmake.in
346 ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc @ONLY)
347 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc DESTINATION
348 ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
352 #-----------------------------------------------------------------------------