
# cmake helps to compile "beads"
# please install the cmake package depending on your linux distribution
# and type in the beads root directory :
# cmake .
# make
# make install
cmake_minimum_required(VERSION 2.18.4)


# The name of our project is "beads".  CMakeLists files in this project can
# refer to the root source directory of the project as ${beads_SOURCE_DIR} and
# to the root binary directory of the project as ${beads_BINARY_DIR}.
project(beads CXX C)



# We want C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "${BoldGreen}CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}${ColourReset}")

#IF( CMAKE_BASE_NAME MATCHES "cl")
#	message("on est sous Windows")
#	SET( WIN32 "true")
#ENDIF(CMAKE_BASE_NAME MATCHES "cl")

if(NOT CMAKE_BUILD_TYPE)
	set( CMAKE_BUILD_TYPE "Release")
endif(NOT CMAKE_BUILD_TYPE)

if(NOT CMAKE_INSTALL_PREFIX)
	set(CMAKE_INSTALL_PREFIX /usr/local)
endif(NOT CMAKE_INSTALL_PREFIX)


if( CMAKE_BUILD_TYPE MATCHES "Release")
	message("compiling as release version")
	add_definitions("-DQT_NO_DEBUG_OUTPUT")
else( CMAKE_BUILD_TYPE MATCHES "Release" )
	message("compiling as debug version")
endif( CMAKE_BUILD_TYPE MATCHES "Release" )



#SET(WIN32 "true")
#SET(MINGW "true")

#set(CMAKE_MODULE_PATH ${beads_SOURCE_DIR}/cmake_modules)

#IF( PTHREADS_FOUND )
#	INCLUDE_DIRECTORIES( ${PTHREADS_INCLUDE_DIR} )
#ELSE( PTHREADS_FOUND )
#	MESSAGE( FATAL_ERROR "No pthread installed" )
#ENDIF( PTHREADS_FOUND )



set( EXTRA_CIMG_LIBRARY "")

set( CIMG_OS 0)
if(WIN32)
	set( CIMG_OS 2)
	#-O2 -lgdi32
	#SET( EXTRA_CIMG_LIBRARY "gdi32")
	#SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
	#	FIND_PACKAGE(FindMagick REQUIRED)
else(WIN32)
	#FIND_PACKAGE(Pthreads REQUIRED)
	set(CMAKE_CXX_FLAGS_RELEASE "-s -O3 -DNDEBUG")
	set( CIMG_OS 1)
endif(WIN32)

#
#CMAKE_CXX_FLAGS
set(CMAKE_CXX_FLAGS_DEBUG "-g -s")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")

set(BEADS_VERSION "1.1.22")
set(VERSION 1.1.22)

set(CPACK_CMAKE_GENERATOR "Unix Makefiles")
set(CPACK_GENERATOR "STGZ;TGZ;TZ")
#SET(CPACK_INSTALL_CMAKE_PROJECTS "/tmp;beads;src;/src")
#SET(CPACK_NSIS_DISPLAY_NAME "CMake 2.5")
set(CPACK_OUTPUT_CONFIG_FILE "./CPackConfig.cmake")
set(CPACK_PACKAGE_DESCRIPTION_FILE ${beads_SOURCE_DIR}/COPYING)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "beads is a detection software")
set(CPACK_PACKAGE_EXECUTABLES "beads")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "beads-${BEADS_VERSION}")
set(CPACK_PACKAGE_FILE_NAME "beads-${BEADS_VERSION}-Linux-i686")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "beads ${BEADS_VERSION}")
set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "beads ${BEADS_VERSION}")
set(CPACK_PACKAGE_NAME "beads")
set(CPACK_PACKAGE_VENDOR "CNRS")

if( CMAKE_BUILD_TYPE MATCHES "Debug")
	set(BEADS_VERSION "${BEADS_VERSION}d")
endif( CMAKE_BUILD_TYPE MATCHES "Debug")
set(CPACK_PACKAGE_VERSION ${BEADS_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "1")
set(CPACK_PACKAGE_VERSION_PATCH "15")
set(CPACK_RESOURCE_FILE_LICENSE ${beads_SOURCE_DIR}/COPYING)
set(CPACK_RESOURCE_FILE_README ${beads_SOURCE_DIR}/README)
set(CPACK_RESOURCE_FILE_WELCOME ${beads_SOURCE_DIR}/INSTALL)
set(CPACK_SOURCE_GENERATOR "TGZ;TZ")
set(CPACK_SOURCE_OUTPUT_CONFIG_FILE "./CPackSourceConfig.cmake")
set(CPACK_SYSTEM_NAME "Linux-i686")
set(CPACK_TOPLEVEL_TAG "Linux-i686")

set(CPACK_SOURCE_IGNORE_FILES 
	"moc_.*cxx"
	"/devel_archives/"
	"/build/"
	"/buildw64/"
	"/cbuild/"
	"/figures/"
	".*\\\\.so"
	".*\\\\.a"
	"/Soumis/"
	"/samples/"
	"/win32/"
	"/tests/"
	"Makefile"
	"install_manifest.txt"
	"cmake_install.cmake"
	"cmake_install.cmake"
	"CMakeCache.txt"
	"CPackConfig.cmake"
	"CPackSourceConfig.cmake"
	"install_manifest.txt"
	".gitignore"
	"/CMakeFiles/"
	"/_CPack_Packages/"
	"/Debug/"
	"/Release/"
	"/\\\\.externalToolBuilders/"
	"/\\\\.git/"
	"/\\\\.settings/"
	"Makefile"
	"\\\\.cdtbuild"
	"\\\\.cdtproject"
	"\\\\.project"
	"\\\\.cproject"
	"beads$"
	".*\\\\.tar\\\\.gz"
	)
# cpack -G TGZ --config CPackSourceConfig.cmake
# dpkg-buildpackage -rfakeroot

#.dput.cf
#[olivier-langella]
#fqdn = ppa.launchpad.net
#method = ftp
#incoming = ~olivier-langella/ubuntu/
#login = olivier-langella
#allow_unsigned_uploads = 0
#
#  debuild -S -sa
# dput -f olivier-langella *changes





#dch -Djessie "message"
#cmake ..
#make deb
# scp beads* proteus.moulon.inra.fr:/var/www/apt/incoming
# reprepro -Vb /var/www/apt processincoming default


configure_file(${beads_SOURCE_DIR}/src/config.h.cmake ${beads_SOURCE_DIR}/src/config.h)


set(CPACK_PACKAGE_EXECUTABLES "beads" "beads")


include(CPack)


#INCLUDE(CPack)




# Recurse into the "src" subdirectories.  This does not actually
# cause another cmake executable to run.  The same process will walk through
# the project's entire directory structure.
#ADD_DEFINITIONS( -lpthread)
add_subdirectory(src)

#SET(CPACK_STRIP_FILES "src/beads;src/qtbeads/qtbeads")

install(PROGRAMS ${CMAKE_BINARY_DIR}/src/beads DESTINATION bin)
install(PROGRAMS ${CMAKE_BINARY_DIR}/src/qtbeads/qtbeads DESTINATION bin)
#INSTALL(DIRECTORY doc/man1 DESTINATION share/man/man1)
install(FILES doc/man1/beads.1 DESTINATION share/man/man1)
install(FILES share/applications/beads.desktop DESTINATION share/applications)
install(FILES share/beads/beads_blue.conf DESTINATION share/beads)
install(FILES share/beads/beads_silver.conf DESTINATION share/beads)
install(FILES share/beads/beads_silver_small.conf DESTINATION share/beads)
install(FILES share/beads/beads_icon.svg DESTINATION share/beads)

add_custom_target(targz
	cpack -G TGZ --config CPackSourceConfig.cmake && tar xvfz beads-${BEADS_VERSION}.tar.gz
	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
	COMMENT "Creating .tar.gz" VERBATIM
	)


add_custom_target(deb
	cd beads-${BEADS_VERSION} && dpkg-buildpackage -b
	DEPENDS targz
	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
	COMMENT "Creating Debian package" VERBATIM
	)
