2019-11-16 20:50:43 +08:00
# - Try to find CImg lib
#
# CIMG_FOUND - system has CImg lib
# CIMG_INCLUDE_DIR - the CImg include directory
macro ( _cimg_check_path )
if ( EXISTS "${CIMG_INCLUDE_DIR}/CImg.h" )
2022-04-18 19:54:08 +08:00
set ( CIMG_FOUND TRUE )
2019-11-16 20:50:43 +08:00
endif ( )
2022-04-18 19:54:08 +08:00
if ( NOT CIMG_FOUND )
2019-11-16 20:50:43 +08:00
message ( STATUS "CImg include path was specified but no CImg.h file was found: ${CIMG_INCLUDE_DIR}" )
endif ( )
endmacro ( )
if ( NOT CIMG_INCLUDE_DIR )
message ( STATUS "CImg: trying to locate CImg library" )
find_path ( CIMG_INCLUDE_DIR NAMES CImg.h
P A T H S
$ { C I m g _ D I R }
$ { C I m g _ D I R } / i n c l u d e
$ { C I m g _ D I R } / c i m g
$ { C I m g _ D I R } / i n c l u d e / c i m g
$ { C I m g _ D I R } / c i m g / i n c l u d e
2022-04-18 19:54:08 +08:00
$ { C I M G _ D I R }
$ { C I M G _ D I R } / i n c l u d e
$ { C I M G _ D I R } / c i m g
$ { C I M G _ D I R } / i n c l u d e / c i m g
$ { C I M G _ D I R } / c i m g / i n c l u d e
2019-11-16 20:50:43 +08:00
$ { C M A K E _ I N S T A L L _ P R E F I X }
$ { C M A K E _ I N S T A L L _ P R E F I X } / c i m g
$ { C M A K E _ I N S T A L L _ P R E F I X } / i n c l u d e
$ { C M A K E _ I N S T A L L _ P R E F I X } / i n c l u d e / c i m g
$ { C M A K E _ I N S T A L L _ P R E F I X } / c i m g / i n c l u d e
2022-04-18 19:54:08 +08:00
$ { C I M G _ P K G C O N F _ I N C L U D E _ D I R S }
/ u s r / l o c a l / i n c l u d e
/ u s r / i n c l u d e
$ { K D E 4 _ I N C L U D E _ D I R }
2019-11-16 20:50:43 +08:00
$ { K D E 4 _ I N C L U D E _ D I R } / c i m g
$ { K D E 4 _ I N C L U D E _ D I R } / i n c l u d e
$ { K D E 4 _ I N C L U D E _ D I R } / i n c l u d e / c i m g
$ { K D E 4 _ I N C L U D E _ D I R } / c i m g / i n c l u d e
)
endif ( )
if ( CIMG_INCLUDE_DIR )
_cimg_check_path ( )
endif ( )
2022-04-18 19:54:08 +08:00
if ( CIMG_FOUND )
list ( APPEND CIMG_INCLUDE_DIRS
$ { C I M G _ I N C L U D E _ D I R }
)
### DISPLAY :: X11 on unix-based system and GDI on windows ###
if ( UNIX OR APPLE )
find_package ( X11 QUIET ) # xshm xrandr are detected as well
if ( X11_FOUND )
set ( CIMG_INCLUDE_DIRS ${ CIMG_INCLUDE_DIRS } ${ X11_INCLUDE_DIR } )
set ( CIMG_LIBRARIES ${ CIMG_LIBRARIES } ${ X11_LIBRARIES } )
message ( STATUS "FindCImg.cmake: X11 found." )
### X11 extension :: XSHM ###
if ( X11_XShm_FOUND )
set ( CIMG_DEFINITIONS ${ CIMG_DEFINITIONS } -Dcimg_use_xshm )
message ( STATUS "FindCImg.cmake: xshm found" )
else ( X11_XShm_FOUND )
message ( STATUS "!!! FindCIMG.cmake !!! xshm NOT found." )
endif ( X11_XShm_FOUND )
### X11 extension :: XRANDR ###
if ( X11_Xrandr_FOUND )
set ( CIMG_DEFINITIONS ${ CIMG_DEFINITIONS } -Dcimg_use_xrandr )
set ( CIMG_LIBRARIES ${ CIMG_LIBRARIES } ${ X11_Xrandr_LIB } )
message ( STATUS "FindCImg.cmake: xrandr found" )
else ( X11_Xrandr_FOUND )
message ( STATUS "!!! FindCIMG.cmake !!! xrandr NOT found" )
endif ( X11_Xrandr_FOUND )
### PThread is required when using X11 display engine ###
2023-10-26 05:22:17 +08:00
find_package ( Threads QUIET )
if ( Threads_FOUND )
set ( CIMG_INCLUDE_DIRS ${ CIMG_INCLUDE_DIRS } )
set ( CIMG_LIBRARIES ${ CIMG_LIBRARIES } Threads::Threads )
2022-04-18 19:54:08 +08:00
message ( STATUS "FindCImg.cmake: pthread found" )
else ( PTHREAD_FOUND )
message ( STATUS "!!! FindCIMG.cmake !!! pthread NOT found. pthread required by cimg for running X11." )
message ( FATAL_ERROR "You need a display engine such as X11 (linux, macosx) or GDI (windows) to compile this program. Please install libs and developpement headers" )
endif ( PTHREAD_FOUND )
else ( X11_FOUND )
message ( STATUS "!!! FindCIMG.cmake !!! X11 NOT found." )
message ( WARNING "FindCImg.cmake: display disabled" )
set ( CIMG_DEFINITIONS ${ CIMG_DEFINITIONS } -Dcimg_display=0 )
endif ( X11_FOUND )
endif ( UNIX OR APPLE )
endif ( )
set ( CIMG_INCLUDE_DIRS ${ CIMG_INCLUDE_DIRS } CACHE STRING "include directories for cimg dependancies" )
set ( CIMG_LIBRARIES ${ CIMG_LIBRARIES } CACHE STRING "cimg required and optional 3rd party libraries" )
set ( CIMG_DEFINITIONS ${ CIMG_DEFINITIONS } CACHE STRING "cimg_use_xxx defines" )
set ( CIMG_C_FLAGS ${ CIMG_C_FLAGS } CACHE STRING "c flags for cimg" )
set ( CIMG_CXX_FLAGS ${ CIMG_CXX_FLAGS } CACHE STRING "c++ flags for cimg" )
2019-11-16 20:50:43 +08:00
include ( FindPackageHandleStandardArgs )
2022-04-18 19:54:08 +08:00
find_package_handle_standard_args ( CImg DEFAULT_MSG CIMG_INCLUDE_DIR CIMG_FOUND )
mark_as_advanced ( CIMG_INCLUDE_DIR )
2019-11-16 20:50:43 +08:00
2022-04-18 19:54:08 +08:00
if ( CIMG_FOUND )
# Library definition
add_library ( CImg::CImg INTERFACE IMPORTED )
target_compile_options ( CImg::CImg INTERFACE ${ CIMG_C_FLAGS } ${ CIMG_CXX_FLAGS } )
target_compile_definitions ( CImg::CImg INTERFACE ${ CIMG_DEFINITIONS } )
target_link_libraries ( CImg::CImg INTERFACE ${ CIMG_LIBRARIES } )
target_include_directories ( CImg::CImg INTERFACE ${ CIMG_INCLUDE_DIRS } )
2023-10-26 05:22:17 +08:00
endif ( CIMG_FOUND )