project(polonaise)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR} ${CMAKE_MODULE_PATH})
if(NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE Release)
endif()

# Build options
option(ENABLE_EXAMPLE_FUSE "Build client which uses libfuse" ON)
message(STATUS "Build options - begin")
message(STATUS "ENABLE_EXAMPLE_FUSE ${ENABLE_EXAMPLE_FUSE}")
message(STATUS "Build options - end")

# Option ENABLE_EXAMPLE_FUSE
if (ENABLE_EXAMPLE_FUSE)
	set(BUILD_EXAMPLE_FUSE ON)
endif()

# Version of the library
set(POLONAISE_MAJOR_VERSION 0)
set(POLONAISE_MINOR_VERSION 3)
set(POLONAISE_PATCH_VERSION 1)
set(POLONAISE_VERSION
	${POLONAISE_MAJOR_VERSION}.${POLONAISE_MINOR_VERSION}.${POLONAISE_PATCH_VERSION})

# Installation paths
include(GNUInstallDirs)
if(WIN32 AND NOT CYGWIN)
	set(CMAKE_INSTALL_CMAKEDIR CMake
		CACHE PATH "Installation directory for CMake files")
else()
	set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Polonaise"
		CACHE PATH "Installation directory for CMake files")
endif()

# Required library - Boost
find_package(Boost REQUIRED)
message(STATUS "BOOST_INCLUDE_DIRS  : ${Boost_INCLUDE_DIRS}")

# Required library - Thrift + Thrift compiler
find_package(Thrift COMPONENTS library compiler REQUIRED)
message(STATUS "THRIFT_INCLUDE_DIRS : ${THRIFT_INCLUDE_DIRS}")
message(STATUS "THRIFT_LIBRARIES    : ${THRIFT_LIBRARIES}")
message(STATUS "THRIFT_COMPILER     : ${THRIFT_COMPILER}")

# Make binaries in the build tree and in install tree use proper rpaths to shared libraries
set(CMAKE_BUILD_WITH_INSTALL_RPATH true)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH true)

# Path to code generated by Thrift
set(GENERATED_CODE ${PROJECT_BINARY_DIR}/generated-code)

# Subdirectories of the project
add_subdirectory(src)

# Install the CMake files for users of the library
configure_file(PolonaiseConfig.cmake.in
	"${PROJECT_BINARY_DIR}/PolonaiseConfig.cmake" @ONLY)
configure_file(PolonaiseConfigVersion.cmake.in
	"${PROJECT_BINARY_DIR}/PolonaiseConfigVersion.cmake" @ONLY)
install(FILES
	"${PROJECT_BINARY_DIR}/PolonaiseConfig.cmake"
	"${PROJECT_BINARY_DIR}/PolonaiseConfigVersion.cmake"
	DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
	CONFIGURATIONS Debug Release)
install(EXPORT PolonaiseTargets
	DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
	CONFIGURATIONS Debug Release)
