# libAferImage CMakeLists.txt

PROJECT(AFTERIMAGE)
if(WIN32)
  # required for the following feature & bug fix:
  # 3.15: Added $<REMOVE_DUPLICATES:list> generator expression
  # 3.16: Bug fix with CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS: the auto-generated exports
  #       are now updated only when the object files providing the symbols are updated
  cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
  # Set CMP0091 (MSVC runtime library flags are selected by an abstraction) to OLD
  # to keep the old way of selecting the runtime library with the -MD/-MDd compiler flag
  cmake_policy(SET CMP0091 OLD)
else()
  cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
endif()

SET(LIB_NAME libAfterImage)

# Microsoft Visual Studio:
IF(MSVC)
  # Define
  ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DNO_DEBUG_OUTPUT /D_MBCS /D_LIB /wd4996 /wd4267 /wd4018 /wd4244")
ENDIF()

set(FREETYPE_INCLUDE_DIR "" CACHE PATH "Path to Freetype include dir")
set(ZLIB_INCLUDE_DIR "" CACHE PATH "Path to zlib include dir")

if(NOT EXISTS "${FREETYPE_INCLUDE_DIR}/ft2build.h")
  message(ERROR "Can't find ft2build.h in ${FREETYPE_INCLUDE_DIR}")
endif()

if(NOT EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
  message(ERROR "Can't find zlib.h in ${ZLIB_INCLUDE_DIR}")
endif()

INCLUDE_DIRECTORIES(${FREETYPE_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})

set (LIB_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")

FILE(GLOB H_FILES "*.h")

SET(SRC_FILES
    libpng/png.c libpng/pngmem.c libpng/pngrio.c libpng/pngset.c libpng/pngwio.c libpng/pngwutil.c
    libpng/pngerror.c libpng/pngpread.c libpng/pngrtran.c libpng/pngtest.c libpng/pngwrite.c
    libpng/pngget.c libpng/pngread.c libpng/pngrutil.c libpng/pngtrans.c libpng/pngwtran.c
    libjpeg/jcapimin.c libjpeg/jcapistd.c libjpeg/jccoefct.c libjpeg/jccolor.c libjpeg/jcdctmgr.c libjpeg/jchuff.c libjpeg/jcinit.c
    libjpeg/jcmainct.c libjpeg/jcmarker.c libjpeg/jcmaster.c libjpeg/jcomapi.c libjpeg/jcparam.c libjpeg/jcphuff.c libjpeg/jcprepct.c
    libjpeg/jcsample.c libjpeg/jctrans.c libjpeg/jdapimin.c libjpeg/jdapistd.c libjpeg/jdatadst.c libjpeg/jdatasrc.c libjpeg/jdcoefct.c
    libjpeg/jdcolor.c libjpeg/transupp.c libjpeg/jaricom.c libjpeg/jdarith.c libjpeg/jcarith.c libjpeg/jddctmgr.c libjpeg/jdhuff.c
    libjpeg/jdinput.c libjpeg/jdmainct.c libjpeg/jdmarker.c libjpeg/jdmaster.c libjpeg/jdmerge.c libjpeg/jdpostct.c libjpeg/jdsample.c
    libjpeg/jdtrans.c libjpeg/jerror.c libjpeg/jfdctflt.c libjpeg/jfdctfst.c libjpeg/jfdctint.c libjpeg/jidctflt.c libjpeg/jidctfst.c
    libjpeg/jidctint.c libjpeg/jmemmgr.c libjpeg/jmemnobs.c libjpeg/jquant1.c libjpeg/jquant2.c libjpeg/jutils.c
    libungif/dgif_lib.c libungif/egif_lib.c libungif/gif_err.c libungif/gifalloc.c libungif/gif_hash.c afterbase.c ascmap.c asfont.c
    asimage.c asstorage.c asvisual.c blender.c bmp.c char2uni.c
    export.c import.c transform.c ungif.c xcf.c ximage.c xpm.c draw.c
    imencdec.c scanline.c
    afterrootpngwrite.c
)

ADD_LIBRARY(${LIB_NAME} STATIC ${H_FILES} ${SRC_FILES})

install(TARGETS ${LIB_NAME} DESTINATION ${LIB_DESTINATION})
