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 ( )
2024-01-15 20:35:47 +08:00
endmacro ( _cimg_check_path )
2019-11-16 20:50:43 +08:00
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
)
2024-01-15 20:35:47 +08:00
endif ( NOT CIMG_INCLUDE_DIR )
2019-11-16 20:50:43 +08:00
if ( CIMG_INCLUDE_DIR )
_cimg_check_path ( )
2024-01-15 20:35:47 +08:00
endif ( CIMG_INCLUDE_DIR )
2019-11-16 20:50:43 +08:00
2022-04-18 19:54:08 +08:00
2024-01-15 20:35:47 +08:00
if ( CIMG_FOUND )
2022-04-18 19:54:08 +08:00
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 ###
2024-01-15 20:35:47 +08:00
if ( UNIX OR APPLE )
2022-04-18 19:54:08 +08:00
find_package ( X11 QUIET ) # xshm xrandr are detected as well
2024-01-15 20:35:47 +08:00
if ( X11_FOUND )
2022-04-18 19:54:08 +08:00
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 ###
2024-01-15 20:35:47 +08:00
if ( X11_XShm_FOUND )
2022-04-18 19:54:08 +08:00
set ( CIMG_DEFINITIONS ${ CIMG_DEFINITIONS } -Dcimg_use_xshm )
message ( STATUS "FindCImg.cmake: xshm found" )
2024-01-15 20:35:47 +08:00
else ( X11_XShm_FOUND )
2022-04-18 19:54:08 +08:00
message ( STATUS "!!! FindCIMG.cmake !!! xshm NOT found." )
2024-01-15 20:35:47 +08:00
endif ( X11_XShm_FOUND )
2022-04-18 19:54:08 +08:00
### X11 extension :: XRANDR ###
2024-01-15 20:35:47 +08:00
if ( X11_Xrandr_FOUND )
2022-04-18 19:54:08 +08:00
set ( CIMG_DEFINITIONS ${ CIMG_DEFINITIONS } -Dcimg_use_xrandr )
set ( CIMG_LIBRARIES ${ CIMG_LIBRARIES } ${ X11_Xrandr_LIB } )
message ( STATUS "FindCImg.cmake: xrandr found" )
2024-01-15 20:35:47 +08:00
else ( X11_Xrandr_FOUND )
2022-04-18 19:54:08 +08:00
message ( STATUS "!!! FindCIMG.cmake !!! xrandr NOT found" )
2024-01-15 20:35:47 +08:00
endif ( X11_Xrandr_FOUND )
2022-04-18 19:54:08 +08:00
### PThread is required when using X11 display engine ###
2023-10-26 05:22:17 +08:00
find_package ( Threads QUIET )
2024-01-15 20:35:47 +08:00
if ( Threads_FOUND )
2023-10-26 05:22:17 +08:00
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" )
2024-01-15 20:35:47 +08:00
else ( PTHREAD_FOUND )
2022-04-18 19:54:08 +08:00
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" )
2024-01-15 20:35:47 +08:00
endif ( )
2022-04-18 19:54:08 +08:00
2024-01-15 20:35:47 +08:00
else ( X11_FOUND )
2022-04-18 19:54:08 +08:00
message ( STATUS "!!! FindCIMG.cmake !!! X11 NOT found." )
message ( WARNING "FindCImg.cmake: display disabled" )
set ( CIMG_DEFINITIONS ${ CIMG_DEFINITIONS } -Dcimg_display=0 )
2024-01-15 20:35:47 +08:00
endif ( X11_FOUND )
endif ( UNIX OR APPLE )
2022-04-18 19:54:08 +08:00
2024-01-15 20:35:47 +08:00
endif ( CIMG_FOUND )
2022-04-18 19:54:08 +08:00
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
2024-01-15 20:35:47 +08:00
if ( CIMG_FOUND )
2022-04-18 19:54:08 +08:00
# 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 )