Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The Flutter tooling requires that developers have CMake 3.10 or later
- # installed. You should not increase this version, as doing so will cause
- # the plugin to fail to compile for some customers of the plugin.
- cmake_minimum_required(VERSION 3.10)
- project(image_magick_ffi_library VERSION 0.0.1 LANGUAGES C)
- add_library(image_magick_ffi SHARED
- "image_magick_ffi.c"
- )
- set_target_properties(image_magick_ffi PROPERTIES
- PUBLIC_HEADER image_magick_ffi.h
- OUTPUT_NAME "image_magick_ffi"
- )
- target_compile_definitions(image_magick_ffi PUBLIC DART_SHARED_LIB)
- # Include FetchContent module to download dependencies at configure time.
- include(FetchContent)
- ################################### Dart Sdk Api ###################################
- # Download the zipped folder of dart-sdk-api from the dependencies repo
- set(dart_sdk_api_zip_url "https://github.com/Haidar0096/image_magick_ffi_deps/raw/master/dart_sdk_api.zip")
- message(STATUS "Downloading dart-sdk-api from ${dart_sdk_api_zip_url}")
- FetchContent_Declare(
- dart_sdk_api
- URL ${dart_sdk_api_zip_url}
- DOWNLOAD_EXTRACT_TIMESTAMP TRUE
- )
- FetchContent_MakeAvailable(dart_sdk_api)
- # Include the include folder of dart_sdk_api from the downloaded zip
- include_directories(${dart_sdk_api_SOURCE_DIR}/include)
- # Create a target from the sources of the downloaded zip and link it to the executable
- file(GLOB_RECURSE DART_SDK_API_SOURCES "${dart_sdk_api_SOURCE_DIR}/src/*.c")
- add_library(dart_sdk_api STATIC ${DART_SDK_API_SOURCES})
- target_link_libraries(image_magick_ffi dart_sdk_api)
- ################################### Dart Sdk Api ###################################
- ################################### Json-C ###################################
- # Download the zipped include folder of json-c from the dependencies repo
- set(json_c_zip_url "https://github.com/Haidar0096/image_magick_ffi_deps/raw/master/json-c.zip")
- message(STATUS "Downloading json-c from ${json_c_zip_url}")
- FetchContent_Declare(
- json-c
- URL ${json_c_zip_url}
- DOWNLOAD_EXTRACT_TIMESTAMP TRUE
- )
- FetchContent_MakeAvailable(json-c)
- # Include the include folder of json-c from the downloaded zip
- include_directories(${json-c_SOURCE_DIR}/include)
- # Create a target from the sources of the downloaded zip and link it to the executable
- file(GLOB_RECURSE json-c-src ${json-c_SOURCE_DIR}/src/*.c)
- add_library(json-c-lib ${json-c-src})
- target_link_libraries(image_magick_ffi json-c-lib)
- ################################### Json-C ###################################
- ################################### Image Magick ###################################
- macro(setDir dir)
- # These values (Q8, Q16, HDRI) are set by the user of the plugin.
- # For android: they are set in the android/build.gradle file by defining a top-level
- # `ext` block and setting Q8=1 (or 0) or Q16=1 (or 0) and HDRI=1 (or 0) in the ext block.
- # For windows: they are set in the windows/CMakeLists.txt file by declaring them on the
- # top-level like set(Q8 1) (or 0) or set(Q16 1) (or 0) and set(HDRI 1) (or 0).
- if (Q8 AND NOT Q16)
- if (HDRI)
- message("Using Q8-HDRI libs for ImageMagick")
- set(dir ${dir}/Q8-HDRI)
- else ()
- message("Using Q8 libs for ImageMagick")
- set(dir ${dir}/Q8)
- endif ()
- elseif (Q16 AND NOT Q8)
- if (HDRI)
- message("Using Q16-HDRI libs for ImageMagick")
- set(dir ${dir}/Q16-HDRI)
- else ()
- message("Using Q16 libs for ImageMagick")
- set(dir ${dir}/Q16)
- endif ()
- elseif (Q8 AND Q16)
- message(FATAL_ERROR "Q8 and Q16 cannot be set to true at the same time")
- else ()
- message("Neither Q8 nor Q16 is defined, using Q8 (No HDRI) libs by default")
- set(dir ${dir}/Q8)
- endif ()
- endmacro()
- macro(downloadImageMagick dir downloadedContentName)
- # Download the zipped folder of ImageMagick from the dependencies repo
- set(image_magick_zip_url "https://github.com/Haidar0096/image_magick_ffi_deps/raw/master/ImageMagick/${dir}.zip")
- message("Downloading ImageMagick from ${image_magick_zip_url}")
- FetchContent_Declare(
- ${downloadedContentName}
- URL ${image_magick_zip_url}
- DOWNLOAD_EXTRACT_TIMESTAMP TRUE
- )
- FetchContent_MakeAvailable(${downloadedContentName})
- endmacro()
- if (WIN32)
- if (CMAKE_SIZEOF_VOID_P EQUAL 8)
- # 64 bits
- set(dir x64)
- elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
- # 32 bits
- set(dir x86)
- endif ()
- setDir(${dir})
- # Download ImageMagick from the dependencies repo
- downloadImageMagick(${dir} imagemagick-windows)
- # Include the include folder of ImageMagick from the downloaded zip
- include_directories(${imagemagick-windows_SOURCE_DIR}/include)
- # Link the ImageMagick libs from the downloaded zip to the executable
- file(GLOB_RECURSE ImageMagick-libs ${imagemagick-windows_SOURCE_DIR}/lib/*.lib)
- target_link_libraries(image_magick_ffi ${ImageMagick-libs})
- # Set the path to the ImageMagick dlls as a cache entry to be used in windows/CMakeLists.txt
- set(ImageMagick-dlls ${imagemagick-windows_SOURCE_DIR}/bin CACHE PATH "Path to ImageMagick dlls")
- elseif (ANDROID)
- message("haidar: we are on android")
- if (${ANDROID_ABI} STREQUAL "arm64-v8a")
- set(dir arm64-v8a)
- else ()
- message(FATAL_ERROR "Only arm64-v8a is supported for android at the moment")
- endif ()
- setDir(${dir})
- message("dir is ${dir}")
- # Download ImageMagick from the dependencies repo
- downloadImageMagick(${dir} imagemagick-arm64-v8a)
- message("downloaded into ${imagemagick-arm64-v8a_SOURCE_DIR}")
- # Include the include folder of ImageMagick from the downloaded zip
- include_directories(${imagemagick-arm64-v8a_SOURCE_DIR}/${dir}/include)
- # MagickCore
- add_library(magickcore SHARED IMPORTED)
- set_target_properties(magickcore PROPERTIES IMPORTED_LOCATION ${imagemagick-arm64-v8a_SOURCE_DIR}/${dir}/bin/libmagickcore-7.so)
- target_link_libraries(image_magick_ffi magickcore)
- # MagickWand
- add_library(magickwand SHARED IMPORTED)
- set_target_properties(magickwand PROPERTIES IMPORTED_LOCATION ${imagemagick-arm64-v8a_SOURCE_DIR}/${dir}/bin/libmagickwand-7.so)
- target_link_libraries(image_magick_ffi magickwand)
- # libomp
- add_library(omp SHARED IMPORTED)
- set_target_properties(omp PROPERTIES IMPORTED_LOCATION ${imagemagick-arm64-v8a_SOURCE_DIR}/${dir}/bin/libomp.so)
- target_link_libraries(image_magick_ffi omp)
- # libc++_shared
- add_library(cxx_shared SHARED IMPORTED)
- set_target_properties(cxx_shared PROPERTIES IMPORTED_LOCATION ${imagemagick-arm64-v8a_SOURCE_DIR}/${dir}/bin/libc++_shared.so)
- target_link_libraries(image_magick_ffi cxx_shared)
- # android log lib
- find_library(log-lib log)
- target_link_libraries(image_magick_ffi ${log-lib})
- endif ()
- ################################### Image Magick ###################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement