CMakeLists.txt 7.0 KB

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