cmake_minimum_required (VERSION 3.4)

if (${CMAKE_BINARY_DIR} MATCHES "^${CMAKE_SOURCE_DIR}")
  if (NOT ${CMAKE_BINARY_DIR} MATCHES "^${CMAKE_SOURCE_DIR}/build")
    message("")
    message("##############################################")
    message("     In-source building is not allowed!       ")
    message("##############################################")
    message("")
    message(" Run cmake outside from source directory ")
    message(" or from ${CMAKE_SOURCE_DIR}/build")
    message("")
    message("----------------------------------------------")
    message(" warning: remaining generated files!")
    message("   ${CMAKE_BINARY_DIR}/CMakeCache.txt")
    message("   ${CMAKE_BINARY_DIR}/CMakeFiles")
    message("----------------------------------------------")
    message("")
    message(" Please remove remaining generated files ")
    message(" and run cmake from an appropriate location")
    message("")

    message(FATAL_ERROR  "\n** CMake aborted **")
  endif()
endif()

project (Pastis)

list(APPEND CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -O3)

add_subdirectory(${CMAKE_SOURCE_DIR}/packages/kokkos)
include_directories(${Kokkos_INCLUDE_DIRS_RET})

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-modules")
include(GetGitRevisionDescription)

get_git_head_revision(GITREV GITHASH)
git_local_changes(GITHASLOCALCHANGES)
message("git rev ${GITREV} : ${GITHASH} (${GITHASLOCALCHANGES})")

file(WRITE  "${CMAKE_BINARY_DIR}/git_revision.hpp" "#define GITREV \"${GITREV}\"\n")
file(APPEND "${CMAKE_BINARY_DIR}/git_revision.hpp" "#define GITHASH \"${GITHASH}\"\n")
file(APPEND "${CMAKE_BINARY_DIR}/git_revision.hpp" "#define GITHASLOCALCHANGES \"${GITHASLOCALCHANGES}\"\n")

include_directories(${CMAKE_BINARY_DIR})

add_executable(pastis main.cpp)
target_link_libraries(pastis kokkos)