# CMake file for cinepaint directory
#
# To be able to create a config.h header file
INCLUDE (CheckIncludeFiles)
INCLUDE (FindPkgConfig)
# usage: CHECK_INCLUDE_FILES (<header> <RESULT_VARIABLE> )
CHECK_INCLUDE_FILES(alloca.h HAVE_ALLOCA_H)
IF(HAVE_ALLOCA_H)
  SET(HAVE_ALLOCA 1)
ENDIF(HAVE_ALLOCA_H)

CHECK_INCLUDE_FILES(dirent.h HAVE_DIRENT_H)

CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H)

CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)

CHECK_INCLUDE_FILES(memory.h HAVE_MEMORY_H)

CHECK_INCLUDE_FILES(ndir.h HAVE_NDIR_H)

CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)

CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H)

CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)

CHECK_INCLUDE_FILES(string.h HAVE_STRING_H)

CHECK_INCLUDE_FILES(sys/dir.h HAVE_SYS_DIR_H)

CHECK_INCLUDE_FILES(sys/ndir.h HAVE_SYS_NDIR_H)

CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)

CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)

CHECK_INCLUDE_FILES(sys/wait.h HAVE_SYS_WAIT_H)

CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)

CHECK_INCLUDE_FILES(libintl.h HAVE_LIBINTL_H)

INCLUDE (CheckFunctionExists)

CHECK_FUNCTION_EXISTS(dcgettext HAVE_DCGETTEXT)

CHECK_FUNCTION_EXISTS(gettext HAVE_GETTEXT)

INCLUDE (CheckSymbolExists) 

CHECK_INCLUDE_FILES(locale.h HAVE_LOCALE_H)
IF(HAVE_LOCALE_H)
  CHECK_SYMBOL_EXISTS(LC_MESSAGES "locale.h" HAVE_LC_MESSAGES) 
ENDIF(HAVE_LOCALE_H)

#this may not be a complete check for stdc headers.
CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)

INCLUDE (TestBigEndian)
TEST_BIG_ENDIAN(WORDS_BIGENDIAN)

# This may need to be set by trying to compile a small program. For unix it is correct
SET(RETSIGTYPE void)

SET(MAJOR_VERSION 0)
SET(MINOR_VERSION 25)
SET(MICRO_VERSION 0)

SET(PROGRAM_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}-${MICRO_VERSION})
SET(VERSION ${PROGRAM_VERSION})

SET(PREFIX ${CMAKE_INSTALL_PREFIX})

SET(programdotdir .cinepaint)
SET(FILMGIMP_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})

# Looking for GTK1 or GTK2
FIND_PACKAGE(GTK REQUIRED)
IF(GTK_FOUND)
ELSE(GTK_FOUND)
  pkg_check_modules (GTK2     glib-2.0>=2.10 gtk+-2.0)
  IF(GTK2_FOUND)
    SET(GTK_INCLUDE_DIR ${GTK2_INCLUDE_DIRS})
    SET(GTK_LIBRARIES ${GTK2_LIBRARIES})
    SET(GTK_LIBRARY_DIRS ${GTK2_LIBRARY_DIRS})
  ELSE(GTK2_FOUND)
    MESSAGE(SEND_ERROR "Could not find any compatible version of GTK.")
  ENDIF(GTK2_FOUND)
ENDIF(GTK_FOUND)
FIND_PACKAGE(PNG)

SET(DATA_DIR_INFIX "share")
SET(PROGRAM_DATA_DIR_INFIX ${DATA_DIR_INFIX}/cinepaint/${VERSION})
SET(PROGRAM_PLUGINS_DIR_INFIX lib/cinepaint/${VERSION}/plug-ins)
SET(PROGRAM_EXTRA_DIR_INFIX lib/cinepaint/${VERSION}/extra)

# I am not sure what to set this to on windows platform
SET(DATA_DIR ${PREFIX}/${DATADIR_INFIX})
SET(PROGRAM_DATA_DIR ${DATA_DIR}/cinepaint/${VERSION})
SET(PROGRAM_PLUGINS_DIR ${PREFIX}/lib/cinepaint/${VERSION}/plug-ins)


CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/lib/version.h.in 
               ${CMAKE_CURRENT_SOURCE_DIR}/lib/version.h @ONLY)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/lib/config.h.cmake
               ${CMAKE_CURRENT_SOURCE_DIR}/lib/config.h )

IF(HAVE_LIBINTL_H)
  SET(ENABLE_NLS "#define ENABLE_NLS")
ENDIF(HAVE_LIBINTL_H)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libgimp/gimpintl.h.in
               ${CMAKE_CURRENT_SOURCE_DIR}/libgimp/gimpintl.h )

LINK_DIRECTORIES( ${GTK_LIBRARY_DIRS} )

add_subdirectory(lib/wire)
add_subdirectory(lib/fl_i18n)
add_subdirectory(libhalf)
add_subdirectory(app)
add_subdirectory(plug-ins plug-ins/object)
add_subdirectory(lib)

# scripts to be installed

ADD_CUSTOM_COMMAND(
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/user_install
   COMMAND  sed -e 's/\@platform\@//g' < ${CMAKE_CURRENT_SOURCE_DIR}/user_install.in >
                    ${CMAKE_CURRENT_BINARY_DIR}/user_install.tmp
   COMMAND mv ${CMAKE_CURRENT_BINARY_DIR}/user_install.tmp
              ${CMAKE_CURRENT_BINARY_DIR}/user_install
   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/user_install.in
   )


STRING(REPLACE "/" "\\/" ESCAPEDPREFIX ${PREFIX})

# Note that for MacOS this needs to be revised 
# for the @OSX_ICC...@ variables
ADD_CUSTOM_COMMAND(
   OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/gimprc
   COMMAND  sed -e s/\@platform\@//g
		-e s/\@prefix\@/${ESCAPEDPREFIX}/g 
	        -e s/\@exec_prefix\@/\${prefix}/g
	        -e s/\@programdatadir\@/\${prefix}\\/share\\/cinepaint\\/${VERSION}/g
	        -e s/\@programplugindir\@/\${exec_prefix}\\/lib\\/cinepaint\\/${VERSION}/g
		-e s/\@OSX_ICC_PROFILE_PATHS\@//g
		-e s/\@OSX_ICC_EFFECT_PROFILE_PATH\@//g
		   < ${CMAKE_CURRENT_SOURCE_DIR}/gimprc.in
		    > ${CMAKE_CURRENT_SOURCE_DIR}/gimprc.tmp
   COMMAND mv ${CMAKE_CURRENT_SOURCE_DIR}/gimprc.tmp
           ${CMAKE_CURRENT_SOURCE_DIR}/gimprc
   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gimprc.in VERBATIM
   )

ADD_CUSTOM_TARGET(RCFile ALL echo
      ""
      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/user_install 
              ${CMAKE_CURRENT_SOURCE_DIR}/gimprc
   )


INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/user_install
  DESTINATION ${PROGRAM_DATA_DIR_INFIX})
  

INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/gimprc ./tips.txt
        DESTINATION ${PROGRAM_DATA_DIR_INFIX})

INSTALL(FILES ./data/brushes/confettif16.gbr
./data/brushes/19circlef16.gbr
./data/brushes/15circlef16.gbr
./data/brushes/9fcirclef16.gbr
./data/brushes/11circlef16.gbr
./data/brushes/dunesf16.gbr
./data/brushes/3fcirclef16.gbr
./data/brushes/callig4f16.gbr
./data/brushes/5x5squareBlurf16.gbr
./data/brushes/19fcirclef16.gbr
./data/brushes/10x10squaref16.gbr
./data/brushes/13fcirclef16.gbr
./data/brushes/callig1f16.gbr
./data/brushes/5fcirclef16.gbr
./data/brushes/7circlef16.gbr
./data/brushes/3circlef16.gbr
./data/brushes/pixelf16.gbr
./data/brushes/galaxyf16.gbr
./data/brushes/callig3f16.gbr
./data/brushes/15fcirclef16.gbr
./data/brushes/17circlef16.gbr
./data/brushes/13circlef16.gbr
./data/brushes/NS1-Charcoal01.gbr
./data/brushes/NS1-Charcoal02.gbr
./data/brushes/NS1-Charcoal03.gbr
./data/brushes/NS1-Charcoal04.gbr
./data/brushes/NS1-Charcoal05.gbr
./data/brushes/NS1-Charcoal06.gbr
./data/brushes/NS1-Charcoal07.gbr
./data/brushes/NS1-Charcoal08.gbr
./data/brushes/NS1-Charcoal09.gbr
./data/brushes/NS1-Charcoal10.gbr
./data/brushes/NS1-Charcoal11.gbr
./data/brushes/NS1-Charcoal12.gbr
./data/brushes/NS1-Charcoal13.gbr
./data/brushes/NS1-Charcoal14.gbr
./data/brushes/NS1-Charcoal15.gbr
./data/brushes/NS1-Charcoal16.gbr
./data/brushes/NS1-Charcoal17.gbr
./data/brushes/NS1-Charcoal18.gbr
./data/brushes/NS1-Charcoal19.gbr
./data/brushes/NS1-Charcoal20.gbr
./data/brushes/NS1-Charcoal21.gbr
./data/brushes/NS1-Charcoal22.gbr
./data/brushes/NS1-Charcoal23.gbr
./data/brushes/NS1-Charcoal24.gbr
./data/brushes/NS1-Charcoal25.gbr
./data/brushes/NS1-Charcoal26.gbr
./data/brushes/NS1-Charcoal27.gbr
./data/brushes/NS1-Charcoal28.gbr
./data/brushes/NS1-Charcoal29.gbr
./data/brushes/NS1-Charcoal30.gbr
./data/brushes/NS1-Charcoal31.gbr
./data/brushes/NS1-Charcoal32.gbr
./data/brushes/NS1-Charcoal33.gbr
./data/brushes/20x20squaref16.gbr
./data/brushes/NS1-Charcoal34.gbr
./data/brushes/galaxy_bigf16.gbr
./data/brushes/NS1-Charcoal35.gbr
./data/brushes/NS1-Charcoal36.gbr
./data/brushes/NS1-Charcoal37.gbr
./data/brushes/NS1-Charcoal38.gbr
./data/brushes/NS1-Charcoal39.gbr
./data/brushes/20x20squareBlurf16.gbr
./data/brushes/7fcirclef16.gbr
./data/brushes/NS1-Charcoal40.gbr
./data/brushes/NS1-Charcoal41.gbr
./data/brushes/NS1-Charcoal42.gbr
./data/brushes/NS1-Charcoal43.gbr
./data/brushes/NS1-Charcoal44.gbr
./data/brushes/NS1-Charcoal45.gbr
./data/brushes/NS1-Charcoal46.gbr
./data/brushes/NS1-Charcoal47.gbr
./data/brushes/NS1-Charcoal48.gbr
./data/brushes/NS1-Charcoal49.gbr
./data/brushes/NS1-Charcoal50.gbr
./data/brushes/NS1-Charcoal51.gbr
./data/brushes/NS1-Charcoal52.gbr
./data/brushes/NS1-Charcoal53.gbr
./data/brushes/NS1-Charcoal54.gbr
./data/brushes/NS1-Charcoal55.gbr
./data/brushes/NS1-Charcoal56.gbr
./data/brushes/NS1-Charcoal57.gbr
./data/brushes/NS1-Charcoal58.gbr
./data/brushes/NS1-Charcoal59.gbr
./data/brushes/NS1-Charcoal60.gbr
./data/brushes/NS1-Charcoal61.gbr
./data/brushes/NS1-Charcoal62.gbr
./data/brushes/NS1-Charcoal63.gbr
./data/brushes/NS1-Charcoal64.gbr
./data/brushes/NS1-Charcoal65.gbr
./data/brushes/galaxy_smallf16.gbr
./data/brushes/17fcirclef16.gbr
./data/brushes/11fcirclef16.gbr
./data/brushes/10x10squareBlurf16.gbr
./data/brushes/9circlef16.gbr
./data/brushes/callig2f16.gbr
./data/brushes/5circlef16.gbr
./data/brushes/1circlef16.gbr
./data/brushes/5x5squaref16.gbr
./data/brushes/SketchBrush-32.gih
./data/brushes/hsparks.gih
./data/brushes/vine.gih
./data/brushes/SketchBrush-64.gih
./data/brushes/feltpen.gih
./data/brushes/SketchBrush-16.gih
DESTINATION ${PROGRAM_DATA_DIR_INFIX}/brushes)
