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 3.5)
12 if(NOT OPENJPEG_NAMESPACE)
13 set(OPENJPEG_NAMESPACE "OPENJPEG")
14 set(OPENJPEG_STANDALONE 1)
17 #string(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
18 set(OPENJPEG_LIBRARY_NAME openjp2)
20 project(${OPENJPEG_NAMESPACE} C)
22 # Do full dependency headers.
23 include_regular_expression("^.*$")
25 #-----------------------------------------------------------------------------
26 # OPENJPEG version number, useful for packaging and doxygen doc:
27 set(OPENJPEG_VERSION_MAJOR 2)
28 set(OPENJPEG_VERSION_MINOR 5)
29 set(OPENJPEG_VERSION_BUILD 0)
31 "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
33 "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
35 # Because autotools does not support X.Y notation for SOVERSION, we have to use
36 # two numbering, one for the openjpeg version and one for openjpeg soversion
55 # above is the recommendation by the OPJ team. If you really need to override this default,
56 # you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
57 # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
58 if(NOT OPENJPEG_SOVERSION)
59 set(OPENJPEG_SOVERSION 7)
60 endif(NOT OPENJPEG_SOVERSION)
61 set(OPENJPEG_LIBRARY_PROPERTIES
62 VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
63 SOVERSION "${OPENJPEG_SOVERSION}"
66 # --------------------------------------------------------------------------
67 # Path to additional CMake modules
69 ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake
72 # --------------------------------------------------------------------------
73 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
79 if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
81 -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
82 -D_CRT_IS_WCTYPE_NO_DEPRECATE
83 -D_CRT_MANAGED_FP_NO_DEPRECATE
84 -D_CRT_NONSTDC_NO_DEPRECATE
85 -D_CRT_SECURE_NO_DEPRECATE
86 -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
87 -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
88 -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
89 -D_CRT_VCCLRIT_NO_DEPRECATE
90 -D_SCL_SECURE_NO_DEPRECATE
99 # --------------------------------------------------------------------------
100 # Install directories
101 string(TOLOWER ${PROJECT_NAME} PROJECT_NAME)
102 include(GNUInstallDirs)
104 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
105 option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
107 set(OPENJPEG_INSTALL_SUBDIR "${PROJECT_NAME}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
109 if(NOT OPENJPEG_INSTALL_JNI_DIR)
111 set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_BINDIR})
113 set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_LIBDIR})
117 if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
118 set(OPENJPEG_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${OPENJPEG_INSTALL_SUBDIR}")
122 option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF)
125 #-----------------------------------------------------------------------------
128 include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
129 TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
132 #-----------------------------------------------------------------------------
133 # Setup file for setting custom ctest vars
135 ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/CTestCustom.cmake.in
136 ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/CTestCustom.cmake
140 #-----------------------------------------------------------------------------
141 # OpenJPEG build configuration options.
142 option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
143 option(BUILD_STATIC_LIBS "Build OpenJPEG static library." ON)
144 set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
145 set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
146 mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
148 #-----------------------------------------------------------------------------
149 # configure name mangling to allow multiple libraries to coexist
151 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
152 set(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
153 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
154 ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
158 #-----------------------------------------------------------------------------
159 # Compiler specific flags:
160 if(CMAKE_COMPILER_IS_GNUCC)
161 # For all builds, make sure openjpeg is std99 compliant:
162 # set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
163 # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
164 set(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>")
165 set(OPENJP2_COMPILE_OPTIONS ${OPENJP2_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>" -Wall -Wextra -Wconversion -Wunused-parameter -Wdeclaration-after-statement -Werror=declaration-after-statement -Wstrict-prototypes -Werror=strict-prototypes -Wmissing-prototypes -Werror=missing-prototypes)
168 #-----------------------------------------------------------------------------
169 # opj_config.h generation (1/2)
171 # Check if some include files are provided by the system
172 include(EnsureFileInclude)
173 # These files are mandatory
174 ensure_file_include("string.h" HAVE_STRING_H YES)
175 ensure_file_include("memory.h" HAVE_MEMORY_H YES)
176 ensure_file_include("stdlib.h" HAVE_STDLIB_H YES)
177 ensure_file_include("stdio.h" HAVE_STDIO_H YES)
178 ensure_file_include("math.h" HAVE_MATH_H YES)
179 ensure_file_include("float.h" HAVE_FLOAT_H YES)
180 ensure_file_include("time.h" HAVE_TIME_H YES)
181 ensure_file_include("stdarg.h" HAVE_STDARG_H YES)
182 ensure_file_include("ctype.h" HAVE_CTYPE_H YES)
183 ensure_file_include("assert.h" HAVE_ASSERT_H YES)
184 ensure_file_include("stdint.h" HAVE_STDINT_H YES)
185 ensure_file_include("inttypes.h" HAVE_INTTYPES_H YES)
187 # why check this one ? for openjpip ?
188 include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
189 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
190 CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
191 CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
192 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
194 # Enable Large file support
195 include(TestLargeFiles)
196 OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
198 # Allocating Aligned Memory Blocks
199 include(CheckIncludeFiles)
200 check_include_files(malloc.h OPJ_HAVE_MALLOC_H)
201 include(CheckSymbolExists)
202 # _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx
203 check_symbol_exists(_aligned_malloc malloc.h OPJ_HAVE__ALIGNED_MALLOC)
204 # posix_memalign (needs _POSIX_C_SOURCE >= 200112L on Linux)
205 set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L)
206 check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN)
207 unset(CMAKE_REQUIRED_DEFINITIONS)
208 # memalign (obsolete)
209 check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN)
210 #-----------------------------------------------------------------------------
212 if(BUILD_JPIP_SERVER)
213 find_package(CURL REQUIRED)
214 find_package(FCGI REQUIRED)
215 find_package(Threads REQUIRED)
216 if(NOT CMAKE_USE_PTHREADS_INIT)
217 message(FATAL_ERROR "Only pthread are supported")
220 add_subdirectory(src/lib)
221 option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
223 option(BUILD_UNIT_TESTS "Build unit tests (bench_dwt, test_sparse_array, etc..)" OFF)
226 #-----------------------------------------------------------------------------
228 option(BUILD_CODEC "Build the CODEC executables" ON)
229 option(BUILD_JPIP "Build the JPIP library and executables." OFF)
231 option(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
233 option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
234 option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
235 mark_as_advanced(BUILD_VIEWER)
236 mark_as_advanced(BUILD_JAVA)
239 # OFF: It will only build 3rd party libs if they are not found on the system
240 # ON: 3rd party libs will ALWAYS be build, and used
241 option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
242 add_subdirectory(thirdparty)
243 add_subdirectory(src/bin)
245 add_subdirectory(wrapping)
247 #-----------------------------------------------------------------------------
248 # opj_config.h generation (2/2)
250 ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in
251 ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
256 ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in
257 ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h
261 #-----------------------------------------------------------------------------
262 # build documentation in doc subdir:
264 add_subdirectory(doc)
267 #-----------------------------------------------------------------------------
269 option(BUILD_TESTING "Build the tests." OFF)
275 # Search openjpeg data needed for the tests
276 # They could be found via git on the OpenJPEG GitHub code project
277 # git clone https://github.com/uclouvain/openjpeg-data.git
278 find_path(OPJ_DATA_ROOT README-OPJ-Data
279 PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data
280 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
283 # Add repository where to find tests
284 add_subdirectory(tests)
287 message(FATAL_ERROR "You need build codec to run the tests")
291 #-----------------------------------------------------------------------------
292 # install all targets referenced as OPENJPEGTargets (relocatable with CMake 3.0+)
293 install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
294 include(CMakePackageConfigHelpers)
295 configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/OpenJPEGConfig.cmake.in
296 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
297 INSTALL_DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
298 PATH_VARS CMAKE_INSTALL_INCLUDEDIR)
299 write_basic_package_version_file(
300 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfigVersion.cmake
301 COMPATIBILITY SameMajorVersion
302 VERSION ${OPENJPEG_VERSION})
305 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
306 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfigVersion.cmake
307 DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
309 #-----------------------------------------------------------------------------
311 include (cmake/OpenJPEGCPack.cmake)
313 #-----------------------------------------------------------------------------
315 # enabled by default on Unix or if using GCC, disabled by default on other platforms
316 if(UNIX OR CMAKE_COMPILER_IS_GNUCC)
317 option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" ON)
319 option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" OFF)
321 if(BUILD_PKGCONFIG_FILES)
322 macro(set_variable_from_rel_or_absolute_path var root rel_or_abs_path)
323 if(IS_ABSOLUTE "${rel_or_abs_path}")
324 set(${var} "${rel_or_abs_path}")
326 set(${var} "${root}/${rel_or_abs_path}")
329 set_variable_from_rel_or_absolute_path("bindir" "\\\${prefix}" "${CMAKE_INSTALL_BINDIR}")
330 set_variable_from_rel_or_absolute_path("mandir" "\\\${prefix}" "${CMAKE_INSTALL_MANDIR}")
331 set_variable_from_rel_or_absolute_path("docdir" "\\\${prefix}" "${CMAKE_INSTALL_DOCDIR}")
332 set_variable_from_rel_or_absolute_path("libdir" "\\\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
333 set_variable_from_rel_or_absolute_path("includedir" "\\\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR}")
335 # install in lib and not share (CMAKE_INSTALL_LIBDIR takes care of it for multi-arch)
336 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in
337 ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY)
338 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION
339 ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
342 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in
343 ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY)
344 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION
345 ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
349 #-----------------------------------------------------------------------------
351 # build our version of astyle
352 SET (WITH_ASTYLE FALSE CACHE BOOL "If you plan to contribute you should reindent with scripts/prepare-commit.sh (using 'our' astyle)")