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.6)
12 IF(COMMAND CMAKE_POLICY)
13 CMAKE_POLICY(SET CMP0003 NEW)
14 ENDIF(COMMAND CMAKE_POLICY)
16 IF(NOT OPENJPEG_NAMESPACE)
17 SET(OPENJPEG_NAMESPACE "OPENJPEG")
18 SET(OPENJPEG_STANDALONE 1)
19 ENDIF(NOT OPENJPEG_NAMESPACE)
21 STRING(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
23 PROJECT(${OPENJPEG_NAMESPACE} C)
25 # Do full dependency headers.
26 INCLUDE_REGULAR_EXPRESSION("^.*$")
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)
34 "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
36 "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
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
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}"
59 # --------------------------------------------------------------------------
60 # Path to additional CMake modules
62 ${CMAKE_SOURCE_DIR}/CMake
65 # --------------------------------------------------------------------------
66 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
72 IF(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
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
85 ENDIF(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
92 # --------------------------------------------------------------------------
95 STRING(TOLOWER ${PROJECT_NAME} projectname)
96 SET(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
98 IF(NOT OPENJPEG_INSTALL_BIN_DIR)
99 SET(OPENJPEG_INSTALL_BIN_DIR "bin")
100 ENDIF(NOT OPENJPEG_INSTALL_BIN_DIR)
102 IF(NOT OPENJPEG_INSTALL_LIB_DIR)
103 SET(OPENJPEG_INSTALL_LIB_DIR "lib")
104 ENDIF(NOT OPENJPEG_INSTALL_LIB_DIR)
106 IF(NOT OPENJPEG_INSTALL_SHARE_DIR)
107 SET(OPENJPEG_INSTALL_SHARE_DIR "share")
108 ENDIF(NOT OPENJPEG_INSTALL_SHARE_DIR)
110 IF(NOT OPENJPEG_INSTALL_DATA_DIR)
111 SET(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
112 ENDIF(NOT OPENJPEG_INSTALL_DATA_DIR)
114 IF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
115 SET(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
116 ENDIF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
118 IF(NOT OPENJPEG_INSTALL_MAN_DIR)
119 SET(OPENJPEG_INSTALL_MAN_DIR "share/man/")
120 ENDIF(NOT OPENJPEG_INSTALL_MAN_DIR)
122 IF(NOT OPENJPEG_INSTALL_DOC_DIR)
123 SET(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
124 ENDIF(NOT OPENJPEG_INSTALL_DOC_DIR)
126 IF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
127 # We could install *.cmake files in share/ however those files contains
128 # hardcoded path to libraries on a multi-arch system (fedora/debian) those
129 # path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu)
130 SET(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
131 ENDIF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
133 #-----------------------------------------------------------------------------
135 INCLUDE (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
136 TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
138 #-----------------------------------------------------------------------------
139 # Setup file for setting custom ctest vars
141 ${CMAKE_SOURCE_DIR}/CMake/CTestCustom.cmake.in
142 ${CMAKE_BINARY_DIR}/CTestCustom.cmake
146 #-----------------------------------------------------------------------------
147 # OpenJPEG build configuration options.
148 OPTION(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
149 SET (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
150 SET (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
151 MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
153 #-----------------------------------------------------------------------------
154 # configure name mangling to allow multiple libraries to coexist
156 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
157 SET(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
158 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
159 ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
161 ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
163 #-----------------------------------------------------------------------------
166 # install in lib and not share (see multi-arch note above)
167 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libopenjpeg1.pc.cmake
168 ${CMAKE_CURRENT_BINARY_DIR}/libopenjpeg1.pc @ONLY)
169 INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpeg1.pc DESTINATION
170 ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
171 INSTALL( CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink
173 \"\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_SHARE_DIR}/pkgconfig/libopenjpeg.pc\")")
176 #-----------------------------------------------------------------------------
177 # Compiler specific flags:
178 IF(CMAKE_COMPILER_IS_GNUCC)
179 # For all builds, make sure openjpeg is std99 compliant:
180 # SET(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
181 # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
182 SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
183 ENDIF(CMAKE_COMPILER_IS_GNUCC)
185 #-----------------------------------------------------------------------------
186 # opj_config.h generation (1/2)
187 INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
188 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
189 CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
190 CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H)
191 CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
192 CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H)
193 CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
194 CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
195 CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
196 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
199 #-----------------------------------------------------------------------------
201 INCLUDE_DIRECTORIES(BEFORE ${OPENJPEG_BINARY_DIR})
202 ADD_SUBDIRECTORY(libopenjpeg)
204 #-----------------------------------------------------------------------------
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)
211 OPTION(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
213 OPTION(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
214 OPTION(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
215 MARK_AS_ADVANCED(BUILD_VIEWER)
216 MARK_AS_ADVANCED(BUILD_JAVA)
218 IF(BUILD_CODEC OR BUILD_MJ2)
219 # OFF: It will only build 3rd party libs if they are not found on the system
220 # ON: 3rd party libs will ALWAYS be build, and used
221 OPTION(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
222 ADD_SUBDIRECTORY(thirdparty)
223 ADD_SUBDIRECTORY(applications)
224 ENDIF (BUILD_CODEC OR BUILD_MJ2)
226 #-----------------------------------------------------------------------------
227 # opj_config.h generation (2/2)
228 CONFIGURE_FILE("${OPENJPEG_SOURCE_DIR}/opj_config.h.cmake.in"
229 "${OPENJPEG_BINARY_DIR}/opj_config.h"
233 #-----------------------------------------------------------------------------
234 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
235 OPTION(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
237 ADD_SUBDIRECTORY(doc)
240 #-----------------------------------------------------------------------------
242 OPTION(BUILD_TESTING "Build the tests." OFF)
248 # Search openjpeg data needed for the tests
249 # They could be found via svn on the OpenJPEG google code project
250 # svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo)
251 FIND_PATH(OPJ_DATA_ROOT README-OPJ-Data
254 ${CMAKE_SOURCE_DIR}/../data
257 # Add repository where to find tests
258 ADD_SUBDIRECTORY(tests)
261 message(FATAL_ERROR "You need build codec to run the tests")
265 #-----------------------------------------------------------------------------
266 # install all targets referenced as OPENJPEGTargets
267 INSTALL(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
268 CONFIGURE_FILE( ${OPENJPEG_SOURCE_DIR}/CMake/OpenJPEGConfig.cmake.in
269 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
272 INSTALL( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
273 DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
276 #-----------------------------------------------------------------------------
277 # install CHANGES and LICENSE
278 IF(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
279 INSTALL(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
280 ENDIF(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
281 INSTALL(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
283 INCLUDE (CMake/OpenJPEGCPack.cmake)