Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.07 KB | None | 0 0
  1. # The Flutter tooling requires that developers have CMake 3.10 or later
  2. # installed. You should not increase this version, as doing so will cause
  3. # the plugin to fail to compile for some customers of the plugin.
  4. cmake_minimum_required(VERSION 3.10)
  5.  
  6. project(image_magick_ffi_library VERSION 0.0.1 LANGUAGES C)
  7.  
  8. add_library(image_magick_ffi SHARED
  9. "image_magick_ffi.c"
  10. )
  11.  
  12. set_target_properties(image_magick_ffi PROPERTIES
  13. PUBLIC_HEADER image_magick_ffi.h
  14. OUTPUT_NAME "image_magick_ffi"
  15. )
  16.  
  17. target_compile_definitions(image_magick_ffi PUBLIC DART_SHARED_LIB)
  18.  
  19. # Include FetchContent module to download dependencies at configure time.
  20. include(FetchContent)
  21.  
  22. ################################### Dart Sdk Api ###################################
  23.  
  24. # Download the zipped folder of dart-sdk-api from the dependencies repo
  25. set(dart_sdk_api_zip_url "https://github.com/Haidar0096/image_magick_ffi_deps/raw/master/dart_sdk_api.zip")
  26. message(STATUS "Downloading dart-sdk-api from ${dart_sdk_api_zip_url}")
  27. FetchContent_Declare(
  28. dart_sdk_api
  29. URL ${dart_sdk_api_zip_url}
  30. DOWNLOAD_EXTRACT_TIMESTAMP TRUE
  31. )
  32. FetchContent_MakeAvailable(dart_sdk_api)
  33.  
  34. # Include the include folder of dart_sdk_api from the downloaded zip
  35. include_directories(${dart_sdk_api_SOURCE_DIR}/include)
  36.  
  37. # Create a target from the sources of the downloaded zip and link it to the executable
  38. file(GLOB_RECURSE DART_SDK_API_SOURCES "${dart_sdk_api_SOURCE_DIR}/src/*.c")
  39. add_library(dart_sdk_api STATIC ${DART_SDK_API_SOURCES})
  40. target_link_libraries(image_magick_ffi dart_sdk_api)
  41.  
  42. ################################### Dart Sdk Api ###################################
  43.  
  44. ################################### Json-C ###################################
  45.  
  46. # Download the zipped include folder of json-c from the dependencies repo
  47. set(json_c_zip_url "https://github.com/Haidar0096/image_magick_ffi_deps/raw/master/json-c.zip")
  48. message(STATUS "Downloading json-c from ${json_c_zip_url}")
  49. FetchContent_Declare(
  50. json-c
  51. URL ${json_c_zip_url}
  52. DOWNLOAD_EXTRACT_TIMESTAMP TRUE
  53. )
  54. FetchContent_MakeAvailable(json-c)
  55.  
  56. # Include the include folder of json-c from the downloaded zip
  57. include_directories(${json-c_SOURCE_DIR}/include)
  58.  
  59. # Create a target from the sources of the downloaded zip and link it to the executable
  60. file(GLOB_RECURSE json-c-src ${json-c_SOURCE_DIR}/src/*.c)
  61. add_library(json-c-lib ${json-c-src})
  62. target_link_libraries(image_magick_ffi json-c-lib)
  63.  
  64. ################################### Json-C ###################################
  65.  
  66. ################################### Image Magick ###################################
  67. macro(setDir dir)
  68. # These values (Q8, Q16, HDRI) are set by the user of the plugin.
  69.  
  70. # For android: they are set in the android/build.gradle file by defining a top-level
  71. # `ext` block and setting Q8=1 (or 0) or Q16=1 (or 0) and HDRI=1 (or 0) in the ext block.
  72.  
  73. # For windows: they are set in the windows/CMakeLists.txt file by declaring them on the
  74. # top-level like set(Q8 1) (or 0) or set(Q16 1) (or 0) and set(HDRI 1) (or 0).
  75.  
  76. if (Q8 AND NOT Q16)
  77. if (HDRI)
  78. message("Using Q8-HDRI libs for ImageMagick")
  79. set(dir ${dir}/Q8-HDRI)
  80. else ()
  81. message("Using Q8 libs for ImageMagick")
  82. set(dir ${dir}/Q8)
  83. endif ()
  84. elseif (Q16 AND NOT Q8)
  85. if (HDRI)
  86. message("Using Q16-HDRI libs for ImageMagick")
  87. set(dir ${dir}/Q16-HDRI)
  88. else ()
  89. message("Using Q16 libs for ImageMagick")
  90. set(dir ${dir}/Q16)
  91. endif ()
  92. elseif (Q8 AND Q16)
  93. message(FATAL_ERROR "Q8 and Q16 cannot be set to true at the same time")
  94. else ()
  95. message("Neither Q8 nor Q16 is defined, using Q8 (No HDRI) libs by default")
  96. set(dir ${dir}/Q8)
  97. endif ()
  98. endmacro()
  99.  
  100. macro(downloadImageMagick dir downloadedContentName)
  101. # Download the zipped folder of ImageMagick from the dependencies repo
  102. set(image_magick_zip_url "https://github.com/Haidar0096/image_magick_ffi_deps/raw/master/ImageMagick/${dir}.zip")
  103. message("Downloading ImageMagick from ${image_magick_zip_url}")
  104. FetchContent_Declare(
  105. ${downloadedContentName}
  106. URL ${image_magick_zip_url}
  107. DOWNLOAD_EXTRACT_TIMESTAMP TRUE
  108. )
  109. FetchContent_MakeAvailable(${downloadedContentName})
  110. endmacro()
  111.  
  112. if (WIN32)
  113. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  114. # 64 bits
  115. set(dir x64)
  116. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  117. # 32 bits
  118. set(dir x86)
  119. endif ()
  120.  
  121. setDir(${dir})
  122.  
  123. # Download ImageMagick from the dependencies repo
  124. downloadImageMagick(${dir} imagemagick-windows)
  125.  
  126. # Include the include folder of ImageMagick from the downloaded zip
  127. include_directories(${imagemagick-windows_SOURCE_DIR}/include)
  128.  
  129. # Link the ImageMagick libs from the downloaded zip to the executable
  130. file(GLOB_RECURSE ImageMagick-libs ${imagemagick-windows_SOURCE_DIR}/lib/*.lib)
  131. target_link_libraries(image_magick_ffi ${ImageMagick-libs})
  132.  
  133. # Set the path to the ImageMagick dlls as a cache entry to be used in windows/CMakeLists.txt
  134. set(ImageMagick-dlls ${imagemagick-windows_SOURCE_DIR}/bin CACHE PATH "Path to ImageMagick dlls")
  135.  
  136. elseif (ANDROID)
  137. message("haidar: we are on android")
  138. if (${ANDROID_ABI} STREQUAL "arm64-v8a")
  139. set(dir arm64-v8a)
  140. else ()
  141. message(FATAL_ERROR "Only arm64-v8a is supported for android at the moment")
  142. endif ()
  143.  
  144. setDir(${dir})
  145. message("dir is ${dir}")
  146.  
  147. # Download ImageMagick from the dependencies repo
  148. downloadImageMagick(${dir} imagemagick-arm64-v8a)
  149. message("downloaded into ${imagemagick-arm64-v8a_SOURCE_DIR}")
  150.  
  151. # Include the include folder of ImageMagick from the downloaded zip
  152. include_directories(${imagemagick-arm64-v8a_SOURCE_DIR}/${dir}/include)
  153.  
  154. # MagickCore
  155. add_library(magickcore SHARED IMPORTED)
  156. set_target_properties(magickcore PROPERTIES IMPORTED_LOCATION ${imagemagick-arm64-v8a_SOURCE_DIR}/${dir}/bin/libmagickcore-7.so)
  157. target_link_libraries(image_magick_ffi magickcore)
  158.  
  159. # MagickWand
  160. add_library(magickwand SHARED IMPORTED)
  161. set_target_properties(magickwand PROPERTIES IMPORTED_LOCATION ${imagemagick-arm64-v8a_SOURCE_DIR}/${dir}/bin/libmagickwand-7.so)
  162. target_link_libraries(image_magick_ffi magickwand)
  163.  
  164. # libomp
  165. add_library(omp SHARED IMPORTED)
  166. set_target_properties(omp PROPERTIES IMPORTED_LOCATION ${imagemagick-arm64-v8a_SOURCE_DIR}/${dir}/bin/libomp.so)
  167. target_link_libraries(image_magick_ffi omp)
  168.  
  169. # libc++_shared
  170. add_library(cxx_shared SHARED IMPORTED)
  171. set_target_properties(cxx_shared PROPERTIES IMPORTED_LOCATION ${imagemagick-arm64-v8a_SOURCE_DIR}/${dir}/bin/libc++_shared.so)
  172. target_link_libraries(image_magick_ffi cxx_shared)
  173.  
  174. # android log lib
  175. find_library(log-lib log)
  176. target_link_libraries(image_magick_ffi ${log-lib})
  177. endif ()
  178. ################################### Image Magick ###################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement