CMakeLists.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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_JPEG)
  13. ocv_include_directories(${JPEG_INCLUDE_DIR} ${${JPEG_LIBRARY}_BINARY_DIR})
  14. list(APPEND GRFMT_LIBS ${JPEG_LIBRARIES})
  15. endif()
  16. if(HAVE_WEBP)
  17. add_definitions(-DHAVE_WEBP)
  18. ocv_include_directories(${WEBP_INCLUDE_DIR})
  19. list(APPEND GRFMT_LIBS ${WEBP_LIBRARIES})
  20. endif()
  21. if(HAVE_PNG)
  22. add_definitions(${PNG_DEFINITIONS})
  23. ocv_include_directories(${PNG_INCLUDE_DIR})
  24. list(APPEND GRFMT_LIBS ${PNG_LIBRARIES})
  25. endif()
  26. if(HAVE_GDCM)
  27. ocv_include_directories(${GDCM_INCLUDE_DIRS})
  28. list(APPEND GRFMT_LIBS ${GDCM_LIBRARIES})
  29. endif()
  30. if(HAVE_TIFF)
  31. ocv_include_directories(${TIFF_INCLUDE_DIR})
  32. list(APPEND GRFMT_LIBS ${TIFF_LIBRARIES})
  33. endif()
  34. if(HAVE_OPENJPEG)
  35. ocv_include_directories(${OPENJPEG_INCLUDE_DIRS})
  36. list(APPEND GRFMT_LIBS ${OPENJPEG_LIBRARIES})
  37. endif()
  38. if(HAVE_JASPER)
  39. ocv_include_directories(${JASPER_INCLUDE_DIR})
  40. list(APPEND GRFMT_LIBS ${JASPER_LIBRARIES})
  41. if(OPENCV_IO_FORCE_JASPER)
  42. add_definitions(-DOPENCV_IMGCODECS_FORCE_JASPER=1)
  43. else()
  44. message(STATUS "imgcodecs: Jasper codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/14058")
  45. endif()
  46. endif()
  47. if(HAVE_OPENEXR)
  48. include_directories(SYSTEM ${OPENEXR_INCLUDE_PATHS})
  49. list(APPEND GRFMT_LIBS ${OPENEXR_LIBRARIES})
  50. if(OPENCV_IO_FORCE_OPENEXR
  51. OR NOT BUILD_OPENEXR # external OpenEXR versions are not disabled
  52. )
  53. add_definitions(-DOPENCV_IMGCODECS_USE_OPENEXR=1)
  54. else()
  55. message(STATUS "imgcodecs: OpenEXR codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/21326")
  56. endif()
  57. endif()
  58. if(HAVE_PNG OR HAVE_TIFF OR HAVE_OPENEXR)
  59. ocv_include_directories(${ZLIB_INCLUDE_DIRS})
  60. list(APPEND GRFMT_LIBS ${ZLIB_LIBRARIES})
  61. endif()
  62. if(HAVE_GDAL)
  63. include_directories(SYSTEM ${GDAL_INCLUDE_DIR})
  64. list(APPEND GRFMT_LIBS ${GDAL_LIBRARY})
  65. endif()
  66. if(HAVE_IMGCODEC_HDR)
  67. add_definitions(-DHAVE_IMGCODEC_HDR)
  68. endif()
  69. if(HAVE_IMGCODEC_SUNRASTER)
  70. add_definitions(-DHAVE_IMGCODEC_SUNRASTER)
  71. endif()
  72. if(HAVE_IMGCODEC_PXM)
  73. add_definitions(-DHAVE_IMGCODEC_PXM)
  74. endif()
  75. if (HAVE_IMGCODEC_PFM)
  76. add_definitions(-DHAVE_IMGCODEC_PFM)
  77. endif()
  78. file(GLOB grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.hpp)
  79. file(GLOB grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/grfmt*.cpp)
  80. list(APPEND grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/bitstrm.hpp)
  81. list(APPEND grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/bitstrm.cpp)
  82. list(APPEND grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/rgbe.hpp)
  83. list(APPEND grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/rgbe.cpp)
  84. list(APPEND grfmt_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/exif.hpp)
  85. list(APPEND grfmt_srcs ${CMAKE_CURRENT_LIST_DIR}/src/exif.cpp)
  86. source_group("Src\\grfmts" FILES ${grfmt_hdrs} ${grfmt_srcs})
  87. set(imgcodecs_hdrs
  88. ${CMAKE_CURRENT_LIST_DIR}/src/precomp.hpp
  89. ${CMAKE_CURRENT_LIST_DIR}/src/utils.hpp
  90. )
  91. set(imgcodecs_srcs
  92. ${CMAKE_CURRENT_LIST_DIR}/src/loadsave.cpp
  93. ${CMAKE_CURRENT_LIST_DIR}/src/utils.cpp
  94. )
  95. file(GLOB imgcodecs_ext_hdrs
  96. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp"
  97. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp"
  98. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.h"
  99. "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/legacy/*.h"
  100. )
  101. if(APPLE OR APPLE_FRAMEWORK)
  102. list(APPEND imgcodecs_srcs ${CMAKE_CURRENT_LIST_DIR}/src/apple_conversions.h)
  103. list(APPEND imgcodecs_srcs ${CMAKE_CURRENT_LIST_DIR}/src/apple_conversions.mm)
  104. endif()
  105. if(IOS)
  106. list(APPEND imgcodecs_srcs ${CMAKE_CURRENT_LIST_DIR}/src/ios_conversions.mm)
  107. list(APPEND IMGCODECS_LIBRARIES "-framework UIKit")
  108. endif()
  109. if(APPLE AND (NOT IOS))
  110. list(APPEND imgcodecs_srcs ${CMAKE_CURRENT_LIST_DIR}/src/macosx_conversions.mm)
  111. list(APPEND IMGCODECS_LIBRARIES "-framework AppKit")
  112. endif()
  113. if(APPLE_FRAMEWORK)
  114. list(APPEND IMGCODECS_LIBRARIES "-framework Accelerate" "-framework CoreGraphics" "-framework QuartzCore")
  115. endif()
  116. if(TRUE)
  117. # these variables are set by 'ocv_append_build_options(IMGCODECS ...)'
  118. foreach(P ${IMGCODECS_INCLUDE_DIRS})
  119. ocv_include_directories(${P})
  120. endforeach()
  121. foreach(P ${IMGCODECS_LIBRARY_DIRS})
  122. link_directories(${P})
  123. endforeach()
  124. endif()
  125. source_group("Src" FILES ${imgcodecs_srcs} ${imgcodecs_hdrs})
  126. source_group("Include" FILES ${imgcodecs_ext_hdrs})
  127. ocv_set_module_sources(HEADERS ${imgcodecs_ext_hdrs} SOURCES ${imgcodecs_srcs} ${imgcodecs_hdrs} ${grfmt_srcs} ${grfmt_hdrs})
  128. ocv_module_include_directories()
  129. ocv_create_module(${GRFMT_LIBS} ${IMGCODECS_LIBRARIES})
  130. macro(ocv_imgcodecs_configure_target)
  131. if(APPLE)
  132. add_apple_compiler_options(${the_module})
  133. endif()
  134. if(MSVC AND NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT)
  135. set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
  136. endif()
  137. ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
  138. endmacro()
  139. if(NOT BUILD_opencv_world)
  140. ocv_imgcodecs_configure_target()
  141. endif()
  142. ocv_add_accuracy_tests()
  143. if(TARGET opencv_test_imgcodecs AND HAVE_JASPER AND "$ENV{OPENCV_IO_ENABLE_JASPER}")
  144. ocv_target_compile_definitions(opencv_test_imgcodecs PRIVATE OPENCV_IMGCODECS_ENABLE_JASPER_TESTS=1)
  145. endif()
  146. if(TARGET opencv_test_imgcodecs AND HAVE_OPENEXR AND "$ENV{OPENCV_IO_ENABLE_OPENEXR}")
  147. ocv_target_compile_definitions(opencv_test_imgcodecs PRIVATE OPENCV_IMGCODECS_ENABLE_OPENEXR_TESTS=1)
  148. endif()
  149. if(TARGET opencv_test_imgcodecs AND HAVE_PNG AND NOT (PNG_VERSION VERSION_LESS "1.6.31"))
  150. # details: https://github.com/glennrp/libpng/commit/68cb0aaee3de6371b81a4613476d9b33e43e95b1
  151. ocv_target_compile_definitions(opencv_test_imgcodecs PRIVATE OPENCV_IMGCODECS_PNG_WITH_EXIF=1)
  152. endif()
  153. ocv_add_perf_tests()