upgpkg: wordpress 6.2.1-1
[ArchLinux/community.git] / gmic / trunk / FindCImg.cmake
blob7399a978ff7d948a7ea643e128d82b752228fb70
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})
6 # CImg.h header
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.")
13   endif()
14 endif()
16 include(FindPackageHandleStandardArgs)
17 find_package_handle_standard_args(CImg
18   REQUIRED_VARS HEADER_PATH
21 # Build options
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)
36 set(COMPILE_FLAGS)
37 set(LINK_FLAGS)
38 set(CLI_COMPILE_FLAGS)
39 set(EXTRA_LIBRARY_TARGETS)
41 ## Add dependencies
43 # OpenMP support
44 if(ENABLE_OPENMP)
45   find_package(OpenMP)
46   if(OpenMP_FOUND)
47     list(APPEND COMPILE_FLAGS "cimg_use_openmp")
48     list(APPEND EXTRA_LIBRARY_TARGETS OpenMP::OpenMP_CXX)
49   endif()
50 endif()
52 # Zlib support
53 if(ENABLE_ZLIB)
54   find_package(ZLIB)
56   if(ZLIB_FOUND)
57     list(APPEND COMPILE_FLAGS "cimg_use_zlib")
58     list(APPEND EXTRA_LIBRARY_TARGETS ZLIB::ZLIB)
59   endif()
60 endif()
62 # Curl support
63 if(ENABLE_CURL)
64   find_package(CURL)
66   if(CURL_FOUND)
67     list(APPEND COMPILE_FLAGS "cimg_use_curl")
68     list(APPEND EXTRA_LIBRARY_TARGETS CURL::libcurl)
69   endif()
70 endif()
72 # X11 support
73 if(ENABLE_X)
74   find_package(X11)
76   if(X11_FOUND)
77     list(APPEND COMPILE_FLAGS "cimg_display=1" "cimg_appname=\"gmic\"")
78     list(APPEND EXTRA_LIBRARY_TARGETS X11::X11)
79   else()
80     list(APPEND COMPILE_FLAGS "cimg_display=0" "cimg_appname=\"gmic\"")
81   endif()
83   if(ENABLE_XSHM AND X11_XShm_FOUND)
84     list(APPEND COMPILE_FLAGS "cimg_use_xshm")
85     list(APPEND EXTRA_LIBRARY_TARGETS X11::Xext)
86   endif()
87 endif()
89 if(ENABLE_FFTW)
90   find_package(FFTW3)
92   if(FFTW3_FOUND)
93     list(APPEND COMPILE_FLAGS "cimg_use_fftw3")
94     list(APPEND EXTRA_LIBRARY_TARGETS ${FFTW3_LIBRARIES} -lfftw3_threads)
95   endif()
96 endif()
98 if(ENABLE_OPENCV)
99   find_package(OpenCV)
101   if(OPENCV_FOUND)
102     list(APPEND CLI_COMPILE_FLAGS "cimg_use_opencv")
103     list(APPEND EXTRA_LIBRARY_TARGETS ${OpenCV_LIBRARIES})
104   endif()
105 endif()
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++)
113   endif()
114 endif()
116 if(ENABLE_TIFF)
117   find_package(TIFF)
119   if(TIFF_FOUND)
120     list(APPEND CLI_COMPILE_FLAGS "cimg_use_tiff")
121     list(APPEND EXTRA_LIBRARY_TARGETS TIFF::TIFF)
122   endif()
123 endif()
125 if(ENABLE_PNG)
126   find_package(PNG)
128   if(PNG_FOUND)
129     list(APPEND CLI_COMPILE_FLAGS "cimg_use_png")
130     list(APPEND EXTRA_LIBRARY_TARGETS PNG::PNG)
131   endif()
132 endif()
134 if(ENABLE_JPEG)
135   find_package(JPEG)
137   if(JPEG_FOUND)
138     list(APPEND CLI_COMPILE_FLAGS "cimg_use_jpeg")
139     list(APPEND EXTRA_LIBRARY_TARGETS JPEG::JPEG)
140   endif()
141 endif()
143 if(ENABLE_OPENEXR)
144   find_package(OpenEXR)
146   if(OpenEXR_FOUND)
147     list(APPEND CLI_COMPILE_FLAGS "cimg_use_openexr")
148     list(APPEND EXTRA_LIBRARY_TARGETS OpenEXR::OpenEXR)
149   endif()
150 endif()
152 if(MINGW)
153   list(APPEND LINK_FLAGS "-Wl,--stack,16777216")
154 endif()
156 find_package(Threads)
157 if(Threads_FOUND)
158   list(APPEND EXTRA_LIBRARY_TARGETS Threads::Threads)
159 endif()
162 # Library definition
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})