CMakeLists.txt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. set(the_description "Image I/O")
  2. ocv_add_module(imgcodecs opencv_imgproc WRAP java objc python)
  3. # ----------------------------------------------------------------------------
  4. # CMake file for imgcodecs. See root CMakeLists.txt
  5. # Some parts taken from version of Hartmut Seichter, HIT Lab NZ.
  6. # Jose Luis Blanco, 2008
  7. # ----------------------------------------------------------------------------
  8. ocv_clear_vars(GRFMT_LIBS)
  9. if(HAVE_WINRT_CX AND NOT WINRT)
  10. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
  11. endif()
  12. if (HAVE_AVIF)
  13. ocv_include_directories(${AVIF_INCLUDE_DIR})
  14. list(APPEND GRFMT_LIBS ${AVIF_LIBRARY})
  15. endif()
  16. if(HAVE_JPEG)
  17. ocv_include_directories(${JPEG_INCLUDE_DIR} ${${JPEG_LIBRARY}_BINARY_DIR})
  18. list(APPEND GRFMT_LIBS ${JPEG_LIBRARIES})
  19. endif()
  20. if(HAVE_WEBP)
  21. add_definitions(-DHAVE_WEBP)
  22. ocv_include_directories(${WEBP_INCLUDE_DIR})
  23. list(APPEND GRFMT_LIBS ${WEBP_LIBRARIES})
  24. endif()
  25. if(HAVE_SPNG)
  26. add_definitions(${SPNG_DEFINITIONS})
  27. ocv_include_directories(${SPNG_INCLUDE_DIR})
  28. list(APPEND GRFMT_LIBS ${SPNG_LIBRARY})
  29. endif()
  30. if(HAVE_PNG)
  31. add_definitions(${PNG_DEFINITIONS})
  32. ocv_include_directories(${PNG_INCLUDE_DIR})
  33. list(APPEND GRFMT_LIBS ${PNG_LIBRARIES})
  34. endif()
  35. if(HAVE_GDCM)
  36. ocv_include_directories(${GDCM_INCLUDE_DIRS})
  37. list(APPEND GRFMT_LIBS ${GDCM_LIBRARIES})
  38. endif()
  39. if(HAVE_TIFF)
  40. ocv_include_directories(${TIFF_INCLUDE_DIR})
  41. list(APPEND GRFMT_LIBS ${TIFF_LIBRARIES})
  42. endif()
  43. if(HAVE_JPEGXL)
  44. ocv_include_directories(${JPEGXL_INCLUDE_DIRS})
  45. message(STATUS "JPEGXL_INCLUDE_DIRS: ${JPEGXL_INCLUDE_DIRS}")
  46. list(APPEND GRFMT_LIBS ${JPEGXL_LIBRARIES})
  47. endif()
  48. if(HAVE_OPENJPEG)
  49. ocv_include_directories(${OPENJPEG_INCLUDE_DIRS})
  50. list(APPEND GRFMT_LIBS ${OPENJPEG_LIBRARIES})
  51. endif()
  52. if(HAVE_JASPER)
  53. ocv_include_directories(${JASPER_INCLUDE_DIR})
  54. list(APPEND GRFMT_LIBS ${JASPER_LIBRARIES})
  55. if(OPENCV_IO_FORCE_JASPER)
  56. add_definitions(-DOPENCV_IMGCODECS_FORCE_JASPER=1)
  57. else()
  58. message(STATUS "imgcodecs: Jasper codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/14058")
  59. endif()
  60. endif()
  61. if(HAVE_OPENEXR)
  62. include_directories(SYSTEM ${OPENEXR_INCLUDE_PATHS})
  63. list(APPEND GRFMT_LIBS ${OPENEXR_LIBRARIES})
  64. if(OPENCV_IO_FORCE_OPENEXR
  65. OR NOT BUILD_OPENEXR # external OpenEXR versions are not disabled
  66. )
  67. add_definitions(-DOPENCV_IMGCODECS_USE_OPENEXR=1)
  68. else()
  69. message(STATUS "imgcodecs: OpenEXR codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/21326")
  70. endif()
  71. endif()
  72. if(HAVE_PNG OR HAVE_TIFF OR HAVE_OPENEXR OR HAVE_SPNG OR HAVE_JPEGXL)
  73. ocv_include_directories(${ZLIB_INCLUDE_DIRS})
  74. list(APPEND GRFMT_LIBS ${ZLIB_LIBRARIES})
  75. endif()
  76. if(HAVE_GDAL)
  77. include_directories(SYSTEM ${GDAL_INCLUDE_DIR})
  78. list(APPEND GRFMT_LIBS ${GDAL_LIBRARY})
  79. endif()
  80. if(HAVE_IMGCODEC_GIF)
  81. add_definitions(-DHAVE_IMGCODEC_GIF)
  82. endif()
  83. if(HAVE_IMGCODEC_HDR)
  84. add_definitions(-DHAVE_IMGCODEC_HDR)
  85. endif()
  86. if(HAVE_IMGCODEC_SUNRASTER)
  87. add_definitions(-DHAVE_IMGCODEC_SUNRASTER)
  88. endif()
  89. if(HAVE_IMGCODEC_PXM)
  90. add_definitions(-DHAVE_IMGCODEC_PXM)
  91. endif()
  92. if (HAVE_IMGCODEC_PFM)
  93. add_definitions(-DHAVE_IMGCODEC_PFM)
  94. endif()
  95. file(GLOB grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.hpp)
  96. file(GLOB grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.cpp)
  97. list(APPEND grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/bitstrm.hpp)
  98. list(APPEND grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/bitstrm.cpp)
  99. list(APPEND grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/rgbe.hpp)
  100. list(APPEND grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/rgbe.cpp)
  101. list(APPEND grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/exif.hpp)
  102. list(APPEND grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/exif.cpp)
  103. source_group("Src\\grfmts" FILES ${grfmt_hdrs} ${grfmt_srcs})
  104. set(imgcodecs_hdrs
  105. ${CMAKE_CURRENT_LIST_DIR}/src/precomp.hpp
  106. ${CMAKE_CURRENT_LIST_DIR}/src/utils.hpp
  107. )
  108. set(imgcodecs_srcs
  109. ${CMAKE_CURRENT_LIST_DIR}/src/loadsave.cpp
  110. ${CMAKE_CURRENT_LIST_DIR}/src/utils.cpp
  111. )
  112. file(GLOB imgcodecs_ext_hdrs
  113. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp"
  114. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp"
  115. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.h"
  116. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/legacy/*.h"
  117. )
  118. if(APPLE OR APPLE_FRAMEWORK)
  119. list(APPEND imgcodecs_srcs ${CMAKE_CURRENT_LIST_DIR}/src/apple_conversions.h)
  120. list(APPEND imgcodecs_srcs ${CMAKE_CURRENT_LIST_DIR}/src/apple_conversions.mm)
  121. endif()
  122. if(IOS OR XROS)
  123. list(APPEND imgcodecs_srcs ${CMAKE_CURRENT_LIST_DIR}/src/ios_conversions.mm)
  124. list(APPEND IMGCODECS_LIBRARIES "-framework UIKit")
  125. endif()
  126. if(APPLE AND (NOT IOS) AND (NOT XROS))
  127. list(APPEND imgcodecs_srcs ${CMAKE_CURRENT_LIST_DIR}/src/macosx_conversions.mm)
  128. list(APPEND IMGCODECS_LIBRARIES "-framework AppKit")
  129. endif()
  130. if(APPLE_FRAMEWORK)
  131. list(APPEND IMGCODECS_LIBRARIES "-framework Accelerate" "-framework CoreGraphics" "-framework QuartzCore")
  132. endif()
  133. if(TRUE)
  134. # these variables are set by 'ocv_append_build_options(IMGCODECS ...)'
  135. foreach(P ${IMGCODECS_INCLUDE_DIRS})
  136. ocv_include_directories(${P})
  137. endforeach()
  138. foreach(P ${IMGCODECS_LIBRARY_DIRS})
  139. link_directories(${P})
  140. endforeach()
  141. endif()
  142. source_group("Src" FILES ${imgcodecs_srcs} ${imgcodecs_hdrs})
  143. source_group("Include" FILES ${imgcodecs_ext_hdrs})
  144. ocv_set_module_sources(HEADERS ${imgcodecs_ext_hdrs} SOURCES ${imgcodecs_srcs} ${imgcodecs_hdrs} ${grfmt_srcs} ${grfmt_hdrs})
  145. ocv_module_include_directories()
  146. ocv_create_module(${GRFMT_LIBS} ${IMGCODECS_LIBRARIES})
  147. macro(ocv_imgcodecs_configure_target)
  148. if(APPLE)
  149. add_apple_compiler_options(${the_module})
  150. endif()
  151. if(MSVC AND NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT)
  152. set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
  153. endif()
  154. ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
  155. endmacro()
  156. if(NOT BUILD_opencv_world)
  157. ocv_imgcodecs_configure_target()
  158. endif()
  159. ocv_add_accuracy_tests()
  160. if(TARGET opencv_test_imgcodecs AND HAVE_JASPER AND "$ENV{OPENCV_IO_ENABLE_JASPER}")
  161. ocv_target_compile_definitions(opencv_test_imgcodecs PRIVATE OPENCV_IMGCODECS_ENABLE_JASPER_TESTS=1)
  162. endif()
  163. if(TARGET opencv_test_imgcodecs AND HAVE_OPENEXR AND "$ENV{OPENCV_IO_ENABLE_OPENEXR}")
  164. ocv_target_compile_definitions(opencv_test_imgcodecs PRIVATE OPENCV_IMGCODECS_ENABLE_OPENEXR_TESTS=1)
  165. endif()
  166. if(TARGET opencv_test_imgcodecs AND ((HAVE_PNG AND NOT (PNG_VERSION_STRING VERSION_LESS "1.6.31")) OR HAVE_SPNG))
  167. # details: https://github.com/glennrp/libpng/commit/68cb0aaee3de6371b81a4613476d9b33e43e95b1
  168. ocv_target_compile_definitions(opencv_test_imgcodecs PRIVATE OPENCV_IMGCODECS_PNG_WITH_EXIF=1)
  169. endif()
  170. ocv_add_perf_tests()