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 1)
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
56 # above is the recommendation by the OPJ team. If you really need to override this default,
57 # you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
58 # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
59 if(NOT OPENJPEG_SOVERSION)
60 set(OPENJPEG_SOVERSION 7)
61 endif(NOT OPENJPEG_SOVERSION)
62 set(OPENJPEG_LIBRARY_PROPERTIES
63 VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
64 SOVERSION "${OPENJPEG_SOVERSION}"
67 # --------------------------------------------------------------------------
68 # Path to additional CMake modules
70 ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake
73 # --------------------------------------------------------------------------
74 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
80 if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
82 -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
83 -D_CRT_IS_WCTYPE_NO_DEPRECATE
84 -D_CRT_MANAGED_FP_NO_DEPRECATE
85 -D_CRT_NONSTDC_NO_DEPRECATE
86 -D_CRT_SECURE_NO_DEPRECATE
87 -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
88 -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
89 -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
90 -D_CRT_VCCLRIT_NO_DEPRECATE
91 -D_SCL_SECURE_NO_DEPRECATE
100 # --------------------------------------------------------------------------
101 # Install directories
102 string(TOLOWER ${PROJECT_NAME} PROJECT_NAME)
103 include(GNUInstallDirs)
105 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
106 option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
108 set(OPENJPEG_INSTALL_SUBDIR "${PROJECT_NAME}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
110 if(NOT OPENJPEG_INSTALL_JNI_DIR)
112 set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_BINDIR})
114 set(OPENJPEG_INSTALL_JNI_DIR ${CMAKE_INSTALL_LIBDIR})
118 if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
119 set(OPENJPEG_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${OPENJPEG_INSTALL_SUBDIR}")
123 option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF)
126 #-----------------------------------------------------------------------------
129 include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
130 TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
133 #-----------------------------------------------------------------------------
134 # Setup file for setting custom ctest vars
136 ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/CTestCustom.cmake.in
137 ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/CTestCustom.cmake
141 #-----------------------------------------------------------------------------
142 # OpenJPEG build configuration options.
143 option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
144 option(BUILD_STATIC_LIBS "Build OpenJPEG static library." ON)
145 set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
146 set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
147 mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
149 #-----------------------------------------------------------------------------
150 # configure name mangling to allow multiple libraries to coexist
152 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
153 set(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
154 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
155 ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
159 #-----------------------------------------------------------------------------
160 # Compiler specific flags:
161 if(CMAKE_COMPILER_IS_GNUCC)
162 # For all builds, make sure openjpeg is std99 compliant:
163 # set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
164 # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
165 set(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>")
166 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)
169 #-----------------------------------------------------------------------------
170 # opj_config.h generation (1/2)
172 # Check if some include files are provided by the system
173 include(EnsureFileInclude)
174 # These files are mandatory
175 ensure_file_include("string.h" HAVE_STRING_H YES)
176 ensure_file_include("memory.h" HAVE_MEMORY_H YES)
177 ensure_file_include("stdlib.h" HAVE_STDLIB_H YES)
178 ensure_file_include("stdio.h" HAVE_STDIO_H YES)
179 ensure_file_include("math.h" HAVE_MATH_H YES)
180 ensure_file_include("float.h" HAVE_FLOAT_H YES)
181 ensure_file_include("time.h" HAVE_TIME_H YES)
182 ensure_file_include("stdarg.h" HAVE_STDARG_H YES)
183 ensure_file_include("ctype.h" HAVE_CTYPE_H YES)
184 ensure_file_include("assert.h" HAVE_ASSERT_H YES)
185 ensure_file_include("stdint.h" HAVE_STDINT_H YES)
186 ensure_file_include("inttypes.h" HAVE_INTTYPES_H YES)
188 # why check this one ? for openjpip ?
189 include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
190 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
191 CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
192 CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
193 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
195 # Enable Large file support
196 include(TestLargeFiles)
197 OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
199 # Allocating Aligned Memory Blocks
200 include(CheckIncludeFiles)
201 check_include_files(malloc.h OPJ_HAVE_MALLOC_H)
202 include(CheckSymbolExists)
203 # _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx
204 check_symbol_exists(_aligned_malloc malloc.h OPJ_HAVE__ALIGNED_MALLOC)
205 # posix_memalign (needs _POSIX_C_SOURCE >= 200112L on Linux)
206 set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L)
207 check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN)
208 unset(CMAKE_REQUIRED_DEFINITIONS)
209 # memalign (obsolete)
210 check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN)
211 #-----------------------------------------------------------------------------
213 if(BUILD_JPIP_SERVER)
214 find_package(CURL REQUIRED)
215 find_package(FCGI REQUIRED)
216 find_package(Threads REQUIRED)
217 if(NOT CMAKE_USE_PTHREADS_INIT)
218 message(FATAL_ERROR "Only pthread are supported")
221 add_subdirectory(src/lib)
222 option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
224 option(BUILD_UNIT_TESTS "Build unit tests (bench_dwt, test_sparse_array, etc..)" OFF)
227 #-----------------------------------------------------------------------------
229 option(BUILD_CODEC "Build the CODEC executables" ON)
230 option(BUILD_JPIP "Build the JPIP library and executables." OFF)
232 option(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
234 option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
235 option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
236 mark_as_advanced(BUILD_VIEWER)
237 mark_as_advanced(BUILD_JAVA)
240 # OFF: It will only build 3rd party libs if they are not found on the system
241 # ON: 3rd party libs will ALWAYS be build, and used
242 option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
243 add_subdirectory(thirdparty)
244 add_subdirectory(src/bin)
246 add_subdirectory(wrapping)
248 #-----------------------------------------------------------------------------
249 # opj_config.h generation (2/2)
251 ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in
252 ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
257 ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in
258 ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h
262 #-----------------------------------------------------------------------------
263 # build documentation in doc subdir:
265 add_subdirectory(doc)
268 #-----------------------------------------------------------------------------
270 option(BUILD_TESTING "Build the tests." OFF)
276 # Search openjpeg data needed for the tests
277 # They could be found via git on the OpenJPEG GitHub code project
278 # git clone https://github.com/uclouvain/openjpeg-data.git
279 find_path(OPJ_DATA_ROOT README-OPJ-Data
280 PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data
281 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
284 # Add repository where to find tests
285 add_subdirectory(tests)
288 message(FATAL_ERROR "You need build codec to run the tests")
292 #-----------------------------------------------------------------------------
293 # install all targets referenced as OPENJPEGTargets (relocatable with CMake 3.0+)
294 install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
295 include(CMakePackageConfigHelpers)
296 configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/OpenJPEGConfig.cmake.in
297 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
298 INSTALL_DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
299 PATH_VARS CMAKE_INSTALL_INCLUDEDIR)
300 write_basic_package_version_file(
301 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfigVersion.cmake
302 COMPATIBILITY SameMajorVersion
303 VERSION ${OPENJPEG_VERSION})
306 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
307 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfigVersion.cmake
308 DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
310 #-----------------------------------------------------------------------------
312 include (cmake/OpenJPEGCPack.cmake)
314 #-----------------------------------------------------------------------------
316 macro(set_variable_from_rel_or_absolute_path var root rel_or_abs_path)
317 if(IS_ABSOLUTE "${rel_or_abs_path}")
318 set(${var} "${rel_or_abs_path}")
320 set(${var} "${root}/${rel_or_abs_path}")
323 set_variable_from_rel_or_absolute_path("bindir" "\\\${prefix}" "${CMAKE_INSTALL_BINDIR}")
324 set_variable_from_rel_or_absolute_path("mandir" "\\\${prefix}" "${CMAKE_INSTALL_MANDIR}")
325 set_variable_from_rel_or_absolute_path("docdir" "\\\${prefix}" "${CMAKE_INSTALL_DOCDIR}")
326 set_variable_from_rel_or_absolute_path("libdir" "\\\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
327 set_variable_from_rel_or_absolute_path("includedir" "\\\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR}")
329 # install in lib and not share (CMAKE_INSTALL_LIBDIR takes care of it for multi-arch)
330 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in
331 ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY)
332 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION
333 ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
336 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in
337 ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY)
338 install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION
339 ${CMAKE_INSTALL_LIBDIR}/pkgconfig )
342 #-----------------------------------------------------------------------------
344 # build our version of astyle
345 SET (WITH_ASTYLE FALSE CACHE BOOL "If you plan to contribute you should reindent with scripts/prepare-commit.sh (using 'our' astyle)")