############################################
#
#  (C) 2023 Michele Calgaro
#  Michele (DOT) Calgaro (AT) yahoo.it
#
#  Improvements and feedback are welcome
#
#  This file is released under GPL >= 2
#
############################################


##### set project version

include( TDEVersion )
cmake_minimum_required( VERSION ${TDE_CMAKE_MINIMUM_VERSION} )
tde_set_project_version( )


##### general package setup

project( libksquirrel )

set(LIBKSQUIRREL_VERSION_MAJOR 0)
set(LIBKSQUIRREL_VERSION_MINOR 8)
set(LIBKSQUIRREL_VERSION_PATCH 0)
set(LIBKSQUIRREL_VERSION_STRING
    "${LIBKSQUIRREL_VERSION_MAJOR}.${LIBKSQUIRREL_VERSION_MINOR}.${LIBKSQUIRREL_VERSION_PATCH}")


##### include essential cmake modules

include( FindPkgConfig          )
include( CheckFunctionExists    )
include( CheckSymbolExists      )
include( CheckIncludeFile       )
include( CheckLibraryExists     )
include( CheckCSourceCompiles   )
include( CheckCXXSourceCompiles )


##### include our cmake modules

include( TDEMacros )


##### setup install paths

include( TDESetupPaths )
tde_setup_paths( )


##### optional stuff

option( WITH_ALL_OPTIONS "Enable all optional support"         OFF )
option( WITH_JPEG        "Build camera code with jpeg support" ${WITH_ALL_OPTIONS} )
option( WITH_LCMS        "Build codecs with lcms support"      ${WITH_ALL_OPTIONS} )

option( WITH_GCC_VISIBILITY "Enable fvisibility and fvisibility-inlines-hidden" ${WITH_ALL_OPTIONS} )


##### user requested modules

option( BUILD_ALL      "Build all"            ON           )
option( BUILD_DOC      "Build documentation"  ${BUILD_ALL} )

option( BUILD_AVS      "Build avs codec"      ${BUILD_ALL} )
option( BUILD_BMP      "Build bmp codec"      ${BUILD_ALL} )
option( BUILD_CAMERA   "Build camera codec"   ${BUILD_ALL} )
option( BUILD_CUT      "Build cut codec"      ${BUILD_ALL} )
option( BUILD_DDS      "Build dds codec"      ${BUILD_ALL} )
option( BUILD_DICOM    "Build dicom codec"    ${BUILD_ALL} )
option( BUILD_DJVU     "Build djvu codec"     ${BUILD_ALL} )
option( BUILD_DXF      "Build dxf codec"      OFF          )
option( BUILD_EPS      "Build eps codec"      ${BUILD_ALL} )
option( BUILD_FIG      "Build fig codec"      ${BUILD_ALL} )
option( BUILD_FLI      "Build fli codec"      ${BUILD_ALL} )
option( BUILD_GIF      "Build gif codec"      ${BUILD_ALL} )
option( BUILD_HDR      "Build hdr codec"      ${BUILD_ALL} )
option( BUILD_ICO      "Build ico codec"      ${BUILD_ALL} )
option( BUILD_IFF      "Build iff codec"      ${BUILD_ALL} )
option( BUILD_JBIG     "Build jbig codec"     ${BUILD_ALL} )
option( BUILD_JPEG2000 "Build jpeg2000 codec" ${BUILD_ALL} )
option( BUILD_JPEG     "Build jpeg codec"     ${BUILD_ALL} )
option( BUILD_KOALA    "Build koala codec"    ${BUILD_ALL} )
option( BUILD_LEAF     "Build leaf codec"     ${BUILD_ALL} )
option( BUILD_LIF      "Build lif codec"      ${BUILD_ALL} )
option( BUILD_LJPEG    "Build ljpeg codec"    ${BUILD_ALL} )
option( BUILD_MAC      "Build mac codec"      ${BUILD_ALL} )
option( BUILD_MDL      "Build mdl codec"      ${BUILD_ALL} )
option( BUILD_MNG      "Build mng codec"      ${BUILD_ALL} )
option( BUILD_MSP      "Build msp codecs"     ${BUILD_ALL} )
option( BUILD_MTV      "Build mtv codec"      ${BUILD_ALL} )
option( BUILD_NEO      "Build neo codec"      ${BUILD_ALL} )
option( BUILD_OPENEXR  "Build openexr codec"  ${BUILD_ALL} )
option( BUILD_PCX      "Build pcx codec"      ${BUILD_ALL} )
option( BUILD_PI1      "Build pi1 codec"      ${BUILD_ALL} )
option( BUILD_PI3      "Build pi3 codec"      ${BUILD_ALL} )
option( BUILD_PICT     "Build pict codec"     ${BUILD_ALL} )
option( BUILD_PIX      "Build pix codec"      ${BUILD_ALL} )
option( BUILD_PNG      "Build png codec"      ${BUILD_ALL} )
option( BUILD_PNM      "Build pnm codec"      ${BUILD_ALL} )
option( BUILD_PSD      "Build psd codec"      ${BUILD_ALL} )
option( BUILD_PSP      "Build psp codec"      ${BUILD_ALL} )
option( BUILD_PXR      "Build pxr codec"      ${BUILD_ALL} )
option( BUILD_RAS      "Build ras codec"      ${BUILD_ALL} )
option( BUILD_RAWRGB   "Build rawrgb codec"   ${BUILD_ALL} )
option( BUILD_SCT      "Build sct codec"      ${BUILD_ALL} )
option( BUILD_SGI      "Build sgi codec"      ${BUILD_ALL} )
option( BUILD_SUN      "Build sun codec"      ${BUILD_ALL} )
option( BUILD_SVG      "Build svg codec"      ${BUILD_ALL} )
option( BUILD_TGA      "Build tga codec"      ${BUILD_ALL} )
option( BUILD_TIFF     "Build tiff codec"     ${BUILD_ALL} )
option( BUILD_TTF      "Build ttf codec"      ${BUILD_ALL} )
option( BUILD_UTAH     "Build utah codec"     ${BUILD_ALL} )
option( BUILD_WAL      "Build wal codec"      ${BUILD_ALL} )
option( BUILD_WBMP     "Build wbmp codec"     ${BUILD_ALL} )
option( BUILD_WMF      "Build wmf codec"      ${BUILD_ALL} )
option( BUILD_XBM      "Build xbm codec"      ${BUILD_ALL} )
option( BUILD_XCF      "Build xcf codec"      ${BUILD_ALL} )
option( BUILD_XCUR     "Build xcur codec"     ${BUILD_ALL} )
option( BUILD_XIM      "Build xim codec"      ${BUILD_ALL} )
option( BUILD_XPM      "Build xpm codec"      ${BUILD_ALL} )
option( BUILD_XWD      "Build xwd codec"      ${BUILD_ALL} )


##### configure checks

include( ConfigureChecks.cmake )


##### global compiler settings

add_definitions( -DHAVE_CONFIG_H )

set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined" )


##### write pkgconfig file

string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" PC_EXEC_PREFIX ${EXEC_INSTALL_PREFIX} )
string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" PC_INCLUDE_DIR ${INCLUDE_INSTALL_DIR} )
string( REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" PC_LIB_DIR ${LIB_INSTALL_DIR} )

configure_file( ksquirrellibs.pc.cmake ksquirrellibs.pc @ONLY )
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/ksquirrellibs.pc DESTINATION ${PKGCONFIG_INSTALL_DIR} )


##### source directories

add_subdirectory( kernel )
tde_conditional_add_subdirectory( BUILD_DOC doc )


##### write configure files

configure_file( config.h.cmake config.h @ONLY )
