|
| 1 | +# Build scripts are adopted to OpenCV project |
| 2 | +# Main CMakeLists.txt to build the OpenJPEG project using CMake (www.cmake.org) |
| 3 | +# Written by Mathieu Malaterre |
| 4 | + |
| 5 | +cmake_policy(SET CMP0003 NEW) |
| 6 | +if(POLICY CMP0042) |
| 7 | + cmake_policy(SET CMP0042 NEW) |
| 8 | +endif() |
| 9 | + |
| 10 | +set(OPENJPEG_LIBRARY_NAME libopenjp2) |
| 11 | + |
| 12 | +project(openjpeg C) |
| 13 | + |
| 14 | +#----------------------------------------------------------------------------- |
| 15 | +# OPENJPEG version number, useful for packaging and doxygen doc: |
| 16 | +set(OPENJPEG_VERSION_MAJOR 2) |
| 17 | +set(OPENJPEG_VERSION_MINOR 3) |
| 18 | +set(OPENJPEG_VERSION_BUILD 1) |
| 19 | +set(OPENJPEG_VERSION |
| 20 | + "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}") |
| 21 | +set(PACKAGE_VERSION |
| 22 | + "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}") |
| 23 | + |
| 24 | +# Because autotools does not support X.Y notation for SOVERSION, we have to use |
| 25 | +# two numbering, one for the openjpeg version and one for openjpeg soversion |
| 26 | +# version | soversion |
| 27 | +# 1.0 | 0 |
| 28 | +# 1.1 | 1 |
| 29 | +# 1.2 | 2 |
| 30 | +# 1.3 | 3 |
| 31 | +# 1.4 | 4 |
| 32 | +# 1.5 | 5 |
| 33 | +# 1.5.1 | 5 |
| 34 | +# 2.0 | 6 |
| 35 | +# 2.0.1 | 6 |
| 36 | +# 2.1 | 7 |
| 37 | +# 2.1.1 | 7 |
| 38 | +# 2.1.2 | 7 |
| 39 | +# 2.2.0 | 7 |
| 40 | +# 2.3.0 | 7 |
| 41 | +# 2.3.1 | 7 |
| 42 | +# above is the recommendation by the OPJ team. If you really need to override this default, |
| 43 | +# you can specify your own OPENJPEG_SOVERSION at cmake configuration time: |
| 44 | +# cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg |
| 45 | +if(NOT OPENJPEG_SOVERSION) |
| 46 | + set(OPENJPEG_SOVERSION 7) |
| 47 | +endif() |
| 48 | + |
| 49 | +set(OPENJPEG_LIBRARY_PROPERTIES |
| 50 | + VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}" |
| 51 | + SOVERSION "${OPENJPEG_SOVERSION}" |
| 52 | +) |
| 53 | + |
| 54 | +set(OPENJPEG_BUILD "opencv-${OPENCV_VERSION}-openjp2-${OPENJPEG_VERSION}") |
| 55 | +if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 56 | + set(OPENJPEG_BUILD "${OPENJPEG_BUILD}-debug") |
| 57 | +endif() |
| 58 | + |
| 59 | +message(STATUS "OpenJPEG: VERSION = ${OPENJPEG_VERSION}, BUILD = ${OPENJPEG_BUILD}") |
| 60 | + |
| 61 | +# -------------------------------------------------------------------------- |
| 62 | +# On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security |
| 63 | +# warnings |
| 64 | +if(WIN32) |
| 65 | + if(NOT BORLAND) |
| 66 | + if(NOT CYGWIN) |
| 67 | + if(NOT MINGW) |
| 68 | + if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS) |
| 69 | + add_definitions( |
| 70 | + -D_CRT_FAR_MAPPINGS_NO_DEPRECATE |
| 71 | + -D_CRT_IS_WCTYPE_NO_DEPRECATE |
| 72 | + -D_CRT_MANAGED_FP_NO_DEPRECATE |
| 73 | + -D_CRT_NONSTDC_NO_DEPRECATE |
| 74 | + -D_CRT_SECURE_NO_DEPRECATE |
| 75 | + -D_CRT_SECURE_NO_DEPRECATE_GLOBALS |
| 76 | + -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE |
| 77 | + -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE |
| 78 | + -D_CRT_VCCLRIT_NO_DEPRECATE |
| 79 | + -D_SCL_SECURE_NO_DEPRECATE |
| 80 | + ) |
| 81 | + endif() |
| 82 | + endif() |
| 83 | + endif() |
| 84 | + endif() |
| 85 | +endif() |
| 86 | + |
| 87 | +#----------------------------------------------------------------------------- |
| 88 | +# Big endian test: |
| 89 | +include(TestBigEndian) |
| 90 | +test_big_endian(OPJ_BIG_ENDIAN) |
| 91 | + |
| 92 | +#----------------------------------------------------------------------------- |
| 93 | +# opj_config.h generation (1/2) |
| 94 | + |
| 95 | +# Check if some include files are provided by the system |
| 96 | +# These files are mandatory, so if they are not provided OpenJPEG library can't be built |
| 97 | +include(CheckIncludeFile) |
| 98 | +macro(ensure_file_include INCLUDE_FILENAME VARIABLE_NAME MANDATORY_STATUS) |
| 99 | + check_include_file(${INCLUDE_FILENAME} ${VARIABLE_NAME}) |
| 100 | + if(NOT ${VARIABLE_NAME}) |
| 101 | + if(${MANDATORY_STATUS}) |
| 102 | + message(STATUS "The file '${INCLUDE_FILENAME}' is mandatory for OpenJPEG build, but not found on your system") |
| 103 | + return() |
| 104 | + else() |
| 105 | + message(STATUS "The file '${INCLUDE_FILENAME}' is optional for OpenJPEG build and not found on your system." |
| 106 | + " Internal implementation will be used.") |
| 107 | + endif() |
| 108 | + endif() |
| 109 | +endmacro() |
| 110 | + |
| 111 | +ensure_file_include("string.h" HAVE_STRING_H YES) |
| 112 | +ensure_file_include("memory.h" HAVE_MEMORY_H YES) |
| 113 | +ensure_file_include("stdlib.h" HAVE_STDLIB_H YES) |
| 114 | +ensure_file_include("stdio.h" HAVE_STDIO_H YES) |
| 115 | +ensure_file_include("math.h" HAVE_MATH_H YES) |
| 116 | +ensure_file_include("float.h" HAVE_FLOAT_H YES) |
| 117 | +ensure_file_include("time.h" HAVE_TIME_H YES) |
| 118 | +ensure_file_include("stdarg.h" HAVE_STDARG_H YES) |
| 119 | +ensure_file_include("ctype.h" HAVE_CTYPE_H YES) |
| 120 | +ensure_file_include("assert.h" HAVE_ASSERT_H YES) |
| 121 | + |
| 122 | +# For the following files, we provide an alternative, they are not mandatory |
| 123 | +ensure_file_include("stdint.h" OPJ_HAVE_STDINT_H NO) |
| 124 | +ensure_file_include("inttypes.h" OPJ_HAVE_INTTYPES_H NO) |
| 125 | + |
| 126 | +# why check this one ? for openjpip ? |
| 127 | +CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) |
| 128 | +CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) |
| 129 | +CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H) |
| 130 | +CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) |
| 131 | + |
| 132 | +# Allocating Aligned Memory Blocks |
| 133 | +include(CheckIncludeFiles) |
| 134 | +check_include_files(malloc.h OPJ_HAVE_MALLOC_H) |
| 135 | +include(CheckSymbolExists) |
| 136 | +# _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx |
| 137 | +check_symbol_exists(_aligned_malloc malloc.h OPJ_HAVE__ALIGNED_MALLOC) |
| 138 | +# posix_memalign (needs _POSIX_C_SOURCE >= 200112L on Linux) |
| 139 | +set(_prev_CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}) |
| 140 | +set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L) |
| 141 | +check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN) |
| 142 | +set(CMAKE_REQUIRED_DEFINITIONS ${_prev_CMAKE_REQUIRED_DEFINITIONS}) |
| 143 | +unset(_prev_CMAKE_REQUIRED_DEFINITIONS) |
| 144 | +# memalign (obsolete) |
| 145 | +check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN) |
| 146 | +#----------------------------------------------------------------------------- |
| 147 | +# opj_config.h generation (2/2) |
| 148 | +configure_file( |
| 149 | + ${CMAKE_CURRENT_LIST_DIR}/openjp2/opj_config.h.cmake.in |
| 150 | + ${CMAKE_CURRENT_BINARY_DIR}/openjp2/opj_config.h |
| 151 | + @ONLY |
| 152 | +) |
| 153 | + |
| 154 | +configure_file( |
| 155 | + ${CMAKE_CURRENT_LIST_DIR}/openjp2/opj_config_private.h.cmake.in |
| 156 | + ${CMAKE_CURRENT_BINARY_DIR}/openjp2/opj_config_private.h |
| 157 | + @ONLY |
| 158 | +) |
| 159 | + |
| 160 | +add_subdirectory(openjp2) |
| 161 | + |
| 162 | +set_target_properties(${OPENJPEG_LIBRARY_NAME} |
| 163 | + PROPERTIES |
| 164 | + OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME} |
| 165 | + DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" |
| 166 | + COMPILE_PDB_NAME ${OPENJPEG_LIBRARY_NAME} |
| 167 | + COMPILE_PDB_NAME_DEBUG "${OPENJPEG_LIBRARY_NAME}${OPENCV_DEBUG_POSTFIX}" |
| 168 | + ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH} |
| 169 | +) |
| 170 | + |
| 171 | +if(ENABLE_SOLUTION_FOLDERS) |
| 172 | + set_target_properties(${OPENJPEG_LIBRARY_NAME} |
| 173 | + PROPERTIES |
| 174 | + FOLDER "3rdparty" |
| 175 | + ) |
| 176 | +endif() |
| 177 | + |
| 178 | +ocv_install_3rdparty_licenses(${OPENJPEG_LIBRARY_NAME} README.md LICENSE) |
| 179 | + |
| 180 | +# Setting all necessary variables |
| 181 | +set(OPENJPEG_LIBRARIES ${OPENJPEG_LIBRARY_NAME} PARENT_SCOPE) |
| 182 | +set(OPENJPEG_VERSION ${OPENJPEG_VERSION} PARENT_SCOPE) |
| 183 | +set(OPENJPEG_MAJOR_VERSION ${OPENJPEG_VERSION_MAJOR} PARENT_SCOPE) |
| 184 | +set(OPENJPEG_MINOR_VERSION ${OPENJPEG_VERSION_MINOR} PARENT_SCOPE) |
| 185 | +set(OPENJPEG_BUILD_VERSION ${OPENJPEG_VERSION_BUILD} PARENT_SCOPE) |
| 186 | +get_target_property(_openjpeg_include_dirs ${OPENJPEG_LIBRARY_NAME} INCLUDE_DIRECTORIES) |
| 187 | +set(OPENJPEG_INCLUDE_DIRS ${_openjpeg_include_dirs} PARENT_SCOPE) |
| 188 | + |
| 189 | +# OpenJPEG can't be built only if configuration script doesn't encounter any problem |
| 190 | +if(NOT DEFINED OCV_CAN_BUILD_OPENJPEG) |
| 191 | + # all prerequisites are fulfilled |
| 192 | + set(OCV_CAN_BUILD_OPENJPEG TRUE PARENT_SCOPE) |
| 193 | +endif() |
0 commit comments