#------------------------------------------------------------------------------
# CMake config file for Reduze package
# top level
#------------------------------------------------------------------------------

# First, you need to configure the package with cmake:
# - typical invocation:
#   'cmake -DCMAKE_INSTALL_PREFIX=/home/mustermann/myprograms'
# - 'cmake [options] <path-to-source>' allows out of source build
# - switches to search in additional directories for headers and libraries:
#   -DCMAKE_INCLUDE_PATH=/home/mustermann/include
#   -DCMAKE_LIBRARY_PATH=/home/mustermann/lib
#   more: http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Variables
# - if automatic CLN detection fails, you might try
#   -DCLN_LIBRARIES=[full path of CLN library]
#   -DCLN_INCLUDE_PATH=[path to CLN header directory]
# - if automatic GiNaC detection fails, you might try
#   -DGINAC_LIBRARIES=[full path of GiNaC library]
#   -DGINAC_INCLUDE_PATH=[path to GiNaC header directory]
# - if automatic MPI environment detection fails, you might try
#   -DMPI_LIBRARY=[semicolon separated list of full paths of each MPI lib]
#   -DMPI_INCLUDE_PATH=[path to MPI header directory]

# After configuration you can compile, link and install the package etc.:
# - 'make -j 2'           builds everything, up to 2 compilations in parallel
# - 'make install'        installs the program and example files
# - 'make check'          runs various checks in serial mode
# - 'make check_mpi'      runs various checks in MPI mode
# - 'make package_source' creates the source tarball
# - 'make doc'            creates the source code documentation using Doxygen

message (STATUS "Configuring package Reduze")
cmake_minimum_required (VERSION 2.6)

project (Reduze)
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
include (GetGitRevisionDescription)
#git_describe_new (GIT_TAG)
git_describe(GIT_TAG)
if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
  message (STATUS "running from repo")
  file (WRITE "${CMAKE_BINARY_DIR}/extra/revision" "${GIT_TAG}")
else()
  message (STATUS "running from tarball")
  file (STRINGS "${CMAKE_SOURCE_DIR}/extra/revision" GIT_TAG)
endif()
message (STATUS "Reduze version is ${GIT_TAG}")

#set (CPACK_VERSION_MAJOR "2")
#set (CPACK_VERSION_MINOR "1")
#set (CPACK_VERSION_PATCH "x")

set (CPACK_SOURCE_GENERATOR "TGZ")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY
	"Reduze performs reductions of Feynman integrals to master integrals")
set (CPACK_PACKAGE_VERSION "${GIT_TAG}")
#set (CPACK_PACKAGE_VERSION
#	"${CPACK_VERSION_MAJOR}.${CPACK_VERSION_MINOR}.${CPACK_VERSION_PATCH}")
set (CPACK_SOURCE_PACKAGE_FILE_NAME "reduze-${CPACK_PACKAGE_VERSION}")
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
set (CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README")
set (CPACK_SOURCE_IGNORE_FILES ".*~;\\\\.git;\\\\..?project;\\\\.settings;/xcode/;/doc/concepts/;/tools/reduzemonitor/;/TODO")
set (TUTORIAL_PDF "${CMAKE_CURRENT_SOURCE_DIR}/doc/tutorial/reduze2-tutorial.pdf")
set (TUTORIAL_TEX "${CMAKE_CURRENT_SOURCE_DIR}/doc/tutorial/reduze2-tutorial.tex")
file (GLOB TUTORIAL_FILES "${CMAKE_CURRENT_SOURCE_DIR}/doc/tutorial/*")
set (HAVE_TUTORIAL_TEX "OFF")
set (HAVE_TUTORIAL_PDF "OFF")
foreach (f ${TUTORIAL_FILES})
  if (NOT "${f}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/doc/tutorial/reduze2-tutorial.pdf")
     set (CPACK_SOURCE_IGNORE_FILES "${f};${CPACK_SOURCE_IGNORE_FILES}")
  else (NOT "${f}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/doc/tutorial/reduze2-tutorial.pdf")
     set (HAVE_TUTORIAL_PDF "ON")
  endif (NOT "${f}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/doc/tutorial/reduze2-tutorial.pdf")
endforeach (f)
if (NOT HAVE_TUTORIAL_PDF)
   message (FATAL_ERROR "File ${TUTORIAL_PDF} not found")
endif (NOT HAVE_TUTORIAL_PDF)


# include configured file with git tag in source package
# NOTE1: make sure to build before pack (make; make package_source) !
# NOTE2: git describe --dirty would be nice to have, but I can't get
#        cmake to update anything based on another git describe result 
set (CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR};/;${CMAKE_BINARY_DIR}/extra;/extra")

# non-trivial build and install specs are in the respective subdirectories
add_subdirectory ("yaml")
add_subdirectory ("reduze")
add_subdirectory ("tools/reduze1to2")
add_subdirectory ("check")
add_subdirectory ("doc/code")
install (FILES "doc/tutorial/reduze2-tutorial.pdf" DESTINATION share/reduze/tutorial)
install (FILES "tools/reduze-mma.m" DESTINATION share/reduze/tools)
install (DIRECTORY "example" DESTINATION share/reduze PATTERN ".git" EXCLUDE)

include (CPack)

