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.5)
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} C)
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 5)
36 set(OPENJPEG_VERSION_BUILD 0)
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
62 # above is the recommendation by the OPJ team. If you really need to override this default,
63 # you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
64 # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
65 if(NOT OPENJPEG_SOVERSION)
66 set(OPENJPEG_SOVERSION 7)
67 endif(NOT OPENJPEG_SOVERSION)
68 set(OPENJPEG_LIBRARY_PROPERTIES
69 VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
70 SOVERSION "${OPENJPEG_SOVERSION}"
73 # --------------------------------------------------------------------------
74 # Path to additional CMake modules
76 ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake
79 # --------------------------------------------------------------------------
80 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
86 if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
88 -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
89 -D_CRT_IS_WCTYPE_NO_DEPRECATE
90 -D_CRT_MANAGED_FP_NO_DEPRECATE
91 -D_CRT_NONSTDC_NO_DEPRECATE
92 -D_CRT_SECURE_NO_DEPRECATE
93 -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
94 -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
95 -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
96 -D_CRT_VCCLRIT_NO_DEPRECATE
97 -D_SCL_SECURE_NO_DEPRECATE
106 # --------------------------------------------------------------------------
107 # Install directories
108 string(TOLOWER ${PROJECT_NAME} PROJECT_NAME)
109 include(GNUInstallDirs)
111 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
112 option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
114 set(OPENJPEG_INSTALL_SUBDIR "${PROJECT_NAME}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
116 if(NOT OPENJPEG_INSTALL_JNI_DIR)
118 set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_BINDIR})
120 set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_LIBDIR})
124 if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
125 set(OPENJPEG_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${OPENJPEG_INSTALL_SUBDIR}")
129 if (${CMAKE_VERSION} VERSION_LESS 3.0)
130 # For cmake >= 3.0, we turn on CMP0042 and
131 # https://cmake.org/cmake/help/v3.0/policy/CMP0042.html mentions
132 # "Projects wanting @rpath in a target’s install name may remove any setting of the INSTALL_NAME_DIR and CMAKE_INSTALL_NAME_DIR variables"
133 list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}")
135 option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF)
138 #-----------------------------------------------------------------------------
141 include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
142 TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
145 #-----------------------------------------------------------------------------
146 # Setup file for setting custom ctest vars
148 ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/CTestCustom.cmake.in
149 ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/CTestCustom.cmake
153 #-----------------------------------------------------------------------------
154 # OpenJPEG build configuration options.
155 option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
156 option(BUILD_STATIC_LIBS "Build OpenJPEG static library." ON)
157 set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
158 set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
159 mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
161 #-----------------------------------------------------------------------------
162 # configure name mangling to allow multiple libraries to coexist
164 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
165 set(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
166 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
167 ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
171 #-----------------------------------------------------------------------------
172 # Compiler specific flags:
173 if(CMAKE_COMPILER_IS_GNUCC)
174 # For all builds, make sure openjpeg is std99 compliant:
175 # set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
176 # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
177 set(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>")
178 set(OPENJP2_COMPILE_OPTIONS ${OPENJP2_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>" -Wall -Wextra -Wconversion -Wunused-parameter -Wdeclaration-after-statement -Werror=declaration-after-statement)
181 #-----------------------------------------------------------------------------
182 # opj_config.h generation (1/2)
184 # Check if some include files are provided by the system
185 include(EnsureFileInclude)
186 # These files are mandatory
187 ensure_file_include("string.h" HAVE_STRING_H YES)
188 ensure_file_include("memory.h" HAVE_MEMORY_H YES)
189 ensure_file_include("stdlib.h" HAVE_STDLIB_H YES)
190 ensure_file_include("stdio.h" HAVE_STDIO_H YES)
191 ensure_file_include("math.h" HAVE_MATH_H YES)
192 ensure_file_include("float.h" HAVE_FLOAT_H YES)
193 ensure_file_include("time.h" HAVE_TIME_H YES)
194 ensure_file_include("stdarg.h" HAVE_STDARG_H YES)
195 ensure_file_include("ctype.h" HAVE_CTYPE_H YES)
196 ensure_file_include("assert.h" HAVE_ASSERT_H YES)
198 # For the following files, we provide an alternative, they are not mandatory
199 ensure_file_include("stdint.h" OPJ_HAVE_STDINT_H NO)
200 ensure_file_include("inttypes.h" OPJ_HAVE_INTTYPES_H NO)
202 # why check this one ? for openjpip ?
203 include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
204 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
205 CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
206 CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
207 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
209 # Enable Large file support
210 include(TestLargeFiles)
211 OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
213 # Allocating Aligned Memory Blocks
214 include(CheckIncludeFiles)
215 check_include_files(malloc.h OPJ_HAVE_MALLOC_H)
216 include(CheckSymbolExists)
217 # _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx
218 check_symbol_exists(_aligned_malloc malloc.h OPJ_HAVE__ALIGNED_MALLOC)
219 # posix_memalign (needs _POSIX_C_SOURCE >= 200112L on Linux)
220 set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L)
221 check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN)
222 unset(CMAKE_REQUIRED_DEFINITIONS)
223 # memalign (obsolete)
224 check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN)
225 #-----------------------------------------------------------------------------
227 if(BUILD_JPIP_SERVER)
228 find_package(CURL REQUIRED)
229 find_package(FCGI REQUIRED)
230 find_package(Threads REQUIRED)
231 if(NOT CMAKE_USE_PTHREADS_INIT)
232 message(FATAL_ERROR "Only pthread are supported")
235 add_subdirectory(src/lib)
236 option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
238 option(BUILD_UNIT_TESTS "Build unit tests (bench_dwt, test_sparse_array, etc..)" OFF)
241 #-----------------------------------------------------------------------------
243 option(BUILD_CODEC "Build the CODEC executables" ON)
244 option(BUILD_JPIP "Build the JPIP library and executables." OFF)
246 option(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
248 option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
249 option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
250 mark_as_advanced(BUILD_VIEWER)
251 mark_as_advanced(BUILD_JAVA)
254 # OFF: It will only build 3rd party libs if they are not found on the system
255 # ON: 3rd party libs will ALWAYS be build, and used
256 option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
257 add_subdirectory(thirdparty)
258 add_subdirectory(src/bin)
260 add_subdirectory(wrapping)
262 #-----------------------------------------------------------------------------
263 # opj_config.h generation (2/2)
265 ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in
266 ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
271 ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in
272 ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h
276 #-----------------------------------------------------------------------------
277 # build documentation in doc subdir:
279 add_subdirectory(doc)
282 #-----------------------------------------------------------------------------
284 option(BUILD_TESTING "Build the tests." OFF)
290 # Search openjpeg data needed for the tests
291 # They could be found via git on the OpenJPEG GitHub code project
292 # git clone https://github.com/uclouvain/openjpeg-data.git
293 find_path(OPJ_DATA_ROOT README-OPJ-Data
294 PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data
295 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
298 # Add repository where to find tests
299 add_subdirectory(tests)
302 message(FATAL_ERROR "You need build codec to run the tests")
306 #-----------------------------------------------------------------------------
307 # install all targets referenced as OPENJPEGTargets (relocatable with CMake 3.0+)
308 install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
309 if (${CMAKE_VERSION} VERSION_LESS 3.0)
311 set(PACKAGE_CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR})
312 configure_file( ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
313 ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/OpenJPEGConfig.cmake
317 include(CMakePackageConfigHelpers)
318 configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/OpenJPEGConfig.cmake.in
319 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
320 INSTALL_DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
321 PATH_VARS CMAKE_INSTALL_INCLUDEDIR)
324 install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
325 DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
328 #-----------------------------------------------------------------------------
330 include (cmake/OpenJPEGCPack.cmake)
332 #-----------------------------------------------------------------------------
334 # enabled by default on Unix or if using GCC, disabled by default on other platforms
335 if(UNIX OR CMAKE_COMPILER_IS_GNUCC)
336 option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" ON)
338 option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" OFF)
340 if(BUILD_PKGCONFIG_FILES)
341 macro(set_variable_from_rel_or_absolute_path var root rel_or_abs_path)
342 if(IS_ABSOLUTE "${rel_or_abs_path}")
343 set(${var} "${rel_or_abs_path}")
345 set(${var} "${root}/${rel_or_abs_path}")
348 set_variable_from_rel_or_absolute_path("bindir" "\\\${prefix}" "${CMAKE_INSTALL_BINDIR}")
349 set_variable_from_rel_or_absolute_path("mandir" "\\\${prefix}" "${CMAKE_INSTALL_MANDIR}")
350 set_variable_from_rel_or_absolute_path("docdir" "\\\${prefix}" "${CMAKE_INSTALL_DOCDIR}")
351 set_variable_from_rel_or_absolute_path("libdir" "\\\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
352 set_variable_from_rel_or_absolute_path("includedir" "\\\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR}")
354 # install in lib and not share (CMAKE_INSTALL_LIBDIR takes care of it for multi-arch)
355 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in
356 ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY)
357 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION
358 ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
361 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in
362 ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY)
363 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION
364 ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
368 #-----------------------------------------------------------------------------
370 # build our version of astyle
371 SET (WITH_ASTYLE FALSE CACHE BOOL "If you plan to contribute you should reindent with scripts/prepare-commit.sh (using 'our' astyle)")