CMakeLists.txt 7.3 KB

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