1 set(HEADER_URL "https://github.com/dtschump/CImg/raw/master/CImg.h")
2 set(HEADER_DIR ${CMAKE_SOURCE_DIR}/src)
3 set(HEADER_NAME CImg.h)
4 set(HEADER_PATH ${HEADER_DIR}/${HEADER_NAME})
7 if(NOT EXISTS ${HEADER_PATH})
8 file(DOWNLOAD ${HEADER_URL} ${HEADER_PATH} STATUS download_status)
10 list(GET download_status 0 status_code)
11 if(NOT ${status_code} EQUAL 0)
12 message(FATAL_ERROR "Missing ${HEADER_NAME} and unable to obtain it. Please download it from ${HEADER_URL} and save it to src/ directory.")
16 include(FindPackageHandleStandardArgs)
17 find_package_handle_standard_args(CImg
18 REQUIRED_VARS HEADER_PATH
22 option(ENABLE_CURL "Add support for curl" ON)
23 option(ENABLE_X "Add support for X11" ON)
24 option(ENABLE_XSHM "Add support for X11 Xshm extension" OFF)
25 option(ENABLE_FFMPEG "Add support for FFMpeg" ON)
26 option(ENABLE_FFTW "Add support for FFTW" ON)
27 option(ENABLE_GRAPHICSMAGICK "Add support for GrahicsMagick" ON)
28 option(ENABLE_JPEG "Add support for handling images in Jpeg format" ON)
29 option(ENABLE_OPENCV "Add support for OpenCV" OFF)
30 option(ENABLE_OPENEXR "Add support for handling images in EXR format" ON)
31 option(ENABLE_OPENMP "Add support for parallel processing" ON)
32 option(ENABLE_PNG "Add support for handling images in PNG format" ON)
33 option(ENABLE_TIFF "Add support for handling images in Tiff format" ON)
34 option(ENABLE_ZLIB "Add support for data compression via Zlib" ON)
38 set(CLI_COMPILE_FLAGS)
39 set(EXTRA_LIBRARY_TARGETS)
47 list(APPEND COMPILE_FLAGS "cimg_use_openmp")
48 list(APPEND EXTRA_LIBRARY_TARGETS OpenMP::OpenMP_CXX)
57 list(APPEND COMPILE_FLAGS "cimg_use_zlib")
58 list(APPEND EXTRA_LIBRARY_TARGETS ZLIB::ZLIB)
67 list(APPEND COMPILE_FLAGS "cimg_use_curl")
68 list(APPEND EXTRA_LIBRARY_TARGETS CURL::libcurl)
77 list(APPEND COMPILE_FLAGS "cimg_display=1" "cimg_appname=\"gmic\"")
78 list(APPEND EXTRA_LIBRARY_TARGETS X11::X11)
80 list(APPEND COMPILE_FLAGS "cimg_display=0" "cimg_appname=\"gmic\"")
83 if(ENABLE_XSHM AND X11_XShm_FOUND)
84 list(APPEND COMPILE_FLAGS "cimg_use_xshm")
85 list(APPEND EXTRA_LIBRARY_TARGETS X11::Xext)
93 list(APPEND COMPILE_FLAGS "cimg_use_fftw3")
94 list(APPEND EXTRA_LIBRARY_TARGETS ${FFTW3_LIBRARIES} -lfftw3_threads)
102 list(APPEND CLI_COMPILE_FLAGS "cimg_use_opencv")
103 list(APPEND EXTRA_LIBRARY_TARGETS ${OpenCV_LIBRARIES})
107 if(ENABLE_GRAPHICSMAGICK)
108 find_package(GraphicsMagick)
110 if(GraphicsMagick_FOUND)
111 list(APPEND CLI_COMPILE_FLAGS "cimg_use_magick")
112 list(APPEND EXTRA_LIBRARY_TARGETS GraphicsMagick::GraphicsMagick++)
120 list(APPEND CLI_COMPILE_FLAGS "cimg_use_tiff")
121 list(APPEND EXTRA_LIBRARY_TARGETS TIFF::TIFF)
129 list(APPEND CLI_COMPILE_FLAGS "cimg_use_png")
130 list(APPEND EXTRA_LIBRARY_TARGETS PNG::PNG)
138 list(APPEND CLI_COMPILE_FLAGS "cimg_use_jpeg")
139 list(APPEND EXTRA_LIBRARY_TARGETS JPEG::JPEG)
144 find_package(OpenEXR)
147 list(APPEND CLI_COMPILE_FLAGS "cimg_use_openexr")
148 list(APPEND EXTRA_LIBRARY_TARGETS OpenEXR::OpenEXR)
153 list(APPEND LINK_FLAGS "-Wl,--stack,16777216")
156 find_package(Threads)
158 list(APPEND EXTRA_LIBRARY_TARGETS Threads::Threads)
164 add_library(CImg::CImg INTERFACE IMPORTED)
166 target_compile_definitions(CImg::CImg INTERFACE ${COMPILE_FLAGS} ${CLI_COMPILE_FLAGS})
167 target_link_options(CImg::CImg INTERFACE ${LINK_FLAGS})
168 target_link_libraries(CImg::CImg INTERFACE ${EXTRA_LIBRARY_TARGETS})
169 target_include_directories(CImg::CImg INTERFACE ${HEADER_DIR})