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)
14 if (NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
15 cmake_policy(SET CMP0042 NEW)
19 if(NOT OPENJPEG_NAMESPACE)
20 set(OPENJPEG_NAMESPACE "OPENJPEG")
21 set(OPENJPEG_STANDALONE 1)
24 #string(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
25 set(OPENJPEG_LIBRARY_NAME openjp2)
27 project(${OPENJPEG_NAMESPACE})
29 # Do full dependency headers.
30 include_regular_expression("^.*$")
32 #-----------------------------------------------------------------------------
33 # OPENJPEG version number, useful for packaging and doxygen doc:
34 set(OPENJPEG_VERSION_MAJOR 2)
35 set(OPENJPEG_VERSION_MINOR 3)
36 set(OPENJPEG_VERSION_BUILD 1)
38 "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
40 "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
42 # Because autotools does not support X.Y notation for SOVERSION, we have to use
43 # two numbering, one for the openjpeg version and one for openjpeg soversion
60 # above is the recommendation by the OPJ team. If you really need to override this default,
61 # you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
62 # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
63 if(NOT OPENJPEG_SOVERSION)
64 set(OPENJPEG_SOVERSION 7)
65 endif(NOT OPENJPEG_SOVERSION)
66 set(OPENJPEG_LIBRARY_PROPERTIES
67 VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
68 SOVERSION "${OPENJPEG_SOVERSION}"
71 # --------------------------------------------------------------------------
72 # Path to additional CMake modules
74 ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake
77 # --------------------------------------------------------------------------
78 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
84 if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
86 -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
87 -D_CRT_IS_WCTYPE_NO_DEPRECATE
88 -D_CRT_MANAGED_FP_NO_DEPRECATE
89 -D_CRT_NONSTDC_NO_DEPRECATE
90 -D_CRT_SECURE_NO_DEPRECATE
91 -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
92 -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
93 -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
94 -D_CRT_VCCLRIT_NO_DEPRECATE
95 -D_SCL_SECURE_NO_DEPRECATE
104 # --------------------------------------------------------------------------
105 # Install directories
106 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
107 option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
109 string(TOLOWER ${PROJECT_NAME} projectname)
110 set(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
112 if(NOT OPENJPEG_INSTALL_BIN_DIR)
113 set(OPENJPEG_INSTALL_BIN_DIR "bin")
116 if(NOT OPENJPEG_INSTALL_LIB_DIR)
117 set(OPENJPEG_INSTALL_LIB_DIR "lib")
120 if(NOT OPENJPEG_INSTALL_SHARE_DIR)
121 set(OPENJPEG_INSTALL_SHARE_DIR "share")
124 if(NOT OPENJPEG_INSTALL_DATA_DIR)
125 set(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
128 if(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
129 set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
133 if(NOT OPENJPEG_INSTALL_MAN_DIR)
134 set(OPENJPEG_INSTALL_MAN_DIR "share/man/")
137 if(NOT OPENJPEG_INSTALL_DOC_DIR)
138 set(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
142 if(NOT OPENJPEG_INSTALL_JNI_DIR)
144 set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_BIN_DIR})
146 set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR})
150 if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
151 # We could install *.cmake files in share/ however those files contains
152 # hardcoded path to libraries on a multi-arch system (fedora/debian) those
153 # path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu)
154 set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
158 list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_LIB_DIR}")
159 option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF)
162 #-----------------------------------------------------------------------------
164 include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
165 TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
167 #-----------------------------------------------------------------------------
168 # Setup file for setting custom ctest vars
170 ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/CTestCustom.cmake.in
171 ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/CTestCustom.cmake
175 #-----------------------------------------------------------------------------
176 # OpenJPEG build configuration options.
177 option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
178 option(BUILD_STATIC_LIBS "Build OpenJPEG static library." ON)
179 set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
180 set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
181 mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
183 #-----------------------------------------------------------------------------
184 # configure name mangling to allow multiple libraries to coexist
186 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
187 set(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
188 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
189 ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
193 #-----------------------------------------------------------------------------
194 # Compiler specific flags:
195 if(CMAKE_COMPILER_IS_GNUCC)
196 # For all builds, make sure openjpeg is std99 compliant:
197 # set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
198 # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
199 set(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>")
200 set(OPENJP2_COMPILE_OPTIONS ${OPENJP2_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>" -Wall -Wextra -Wconversion -Wunused-parameter -Wdeclaration-after-statement -Werror=declaration-after-statement)
203 #-----------------------------------------------------------------------------
204 # opj_config.h generation (1/2)
206 # Check if some include files are provided by the system
207 include(EnsureFileInclude)
208 # These files are mandatory
209 ensure_file_include("string.h" HAVE_STRING_H YES)
210 ensure_file_include("memory.h" HAVE_MEMORY_H YES)
211 ensure_file_include("stdlib.h" HAVE_STDLIB_H YES)
212 ensure_file_include("stdio.h" HAVE_STDIO_H YES)
213 ensure_file_include("math.h" HAVE_MATH_H YES)
214 ensure_file_include("float.h" HAVE_FLOAT_H YES)
215 ensure_file_include("time.h" HAVE_TIME_H YES)
216 ensure_file_include("stdarg.h" HAVE_STDARG_H YES)
217 ensure_file_include("ctype.h" HAVE_CTYPE_H YES)
218 ensure_file_include("assert.h" HAVE_ASSERT_H YES)
220 # For the following files, we provide an alternative, they are not mandatory
221 ensure_file_include("stdint.h" OPJ_HAVE_STDINT_H NO)
222 ensure_file_include("inttypes.h" OPJ_HAVE_INTTYPES_H NO)
224 # why check this one ? for openjpip ?
225 include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
226 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
227 CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
228 CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
229 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
231 # Enable Large file support
232 include(TestLargeFiles)
233 OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
235 # Allocating Aligned Memory Blocks
236 include(CheckIncludeFiles)
237 check_include_files(malloc.h OPJ_HAVE_MALLOC_H)
238 include(CheckSymbolExists)
239 # _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx
240 check_symbol_exists(_aligned_malloc malloc.h OPJ_HAVE__ALIGNED_MALLOC)
241 # posix_memalign (needs _POSIX_C_SOURCE >= 200112L on Linux)
242 set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L)
243 check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN)
244 unset(CMAKE_REQUIRED_DEFINITIONS)
245 # memalign (obsolete)
246 check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN)
247 #-----------------------------------------------------------------------------
249 if(BUILD_JPIP_SERVER)
250 find_package(CURL REQUIRED)
251 find_package(FCGI REQUIRED)
252 find_package(Threads REQUIRED)
253 if(NOT CMAKE_USE_PTHREADS_INIT)
254 message(FATAL_ERROR "Only pthread are supported")
257 add_subdirectory(src/lib)
258 option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
260 option(BUILD_UNIT_TESTS "Build unit tests (bench_dwt, test_sparse_array, etc..)" OFF)
263 #-----------------------------------------------------------------------------
265 option(BUILD_CODEC "Build the CODEC executables" ON)
266 option(BUILD_MJ2 "Build the MJ2 executables." OFF)
267 option(BUILD_JPWL "Build the JPWL library and executables" OFF)
268 option(BUILD_JPIP "Build the JPIP library and executables." OFF)
270 option(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
272 option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
273 option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
274 option(BUILD_JP3D "Build the JP3D comp" OFF)
275 mark_as_advanced(BUILD_VIEWER)
276 mark_as_advanced(BUILD_JAVA)
277 mark_as_advanced(BUILD_JP3D)
279 if(BUILD_CODEC OR BUILD_MJ2)
280 # OFF: It will only build 3rd party libs if they are not found on the system
281 # ON: 3rd party libs will ALWAYS be build, and used
282 option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
283 add_subdirectory(thirdparty)
284 add_subdirectory(src/bin)
286 add_subdirectory(wrapping)
288 #-----------------------------------------------------------------------------
289 # opj_config.h generation (2/2)
291 ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in
292 ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
297 ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in
298 ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h
302 #-----------------------------------------------------------------------------
303 # build documentation in doc subdir:
305 add_subdirectory(doc)
308 #-----------------------------------------------------------------------------
310 option(BUILD_TESTING "Build the tests." OFF)
316 # Search openjpeg data needed for the tests
317 # They could be found via git on the OpenJPEG GitHub code project
318 # git clone https://github.com/uclouvain/openjpeg-data.git
319 find_path(OPJ_DATA_ROOT README-OPJ-Data
320 PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data
321 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
324 # Add repository where to find tests
325 add_subdirectory(tests)
328 message(FATAL_ERROR "You need build codec to run the tests")
332 #-----------------------------------------------------------------------------
333 # install all targets referenced as OPENJPEGTargets
334 install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
335 configure_file( ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
336 ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/OpenJPEGConfig.cmake
339 install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
340 DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
343 #-----------------------------------------------------------------------------
344 # install CHANGES and LICENSE
346 if(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
347 install(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
350 install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
353 include (cmake/OpenJPEGCPack.cmake)
355 #-----------------------------------------------------------------------------
357 # enabled by default on Unix or if using GCC, disabled by default on other platforms
358 if(UNIX OR CMAKE_COMPILER_IS_GNUCC)
359 option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" ON)
361 option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" OFF)
363 if(BUILD_PKGCONFIG_FILES)
364 # install in lib and not share (see multi-arch note above)
365 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in
366 ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY)
367 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION
368 ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
371 # install in lib and not share (see multi-arch note above)
372 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpwl/libopenjpwl.pc.cmake.in
373 ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc @ONLY)
374 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc DESTINATION
375 ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
379 # install in lib and not share (see multi-arch note above)
380 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in
381 ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY)
382 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION
383 ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
387 # install in lib and not share (see multi-arch note above)
388 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp3d/libopenjp3d.pc.cmake.in
389 ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc @ONLY)
390 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc DESTINATION
391 ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
395 #-----------------------------------------------------------------------------
397 # build our version of astyle
398 SET (WITH_ASTYLE FALSE CACHE BOOL "If you plan to contribute you should reindent with scripts/prepare-commit.sh (using 'our' astyle)")