# Setup
set(PROJECT_INCLUDES_DESTINATION include)
set(PROJECT_LIBRARIES_DESTINATION lib)
set(PROJECT_RUNTIME_DESTINATION bin)
set(PROJECT_CMAKE_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cmake/${CMAKE_PROJECT_NAME})
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

function(install_project)
	install(
		TARGETS ${PROJECT_NAME}
		EXPORT ${PROJECT_NAME}
		LIBRARY   DESTINATION ${PROJECT_LIBRARIES_DESTINATION}
		ARCHIVE   DESTINATION ${PROJECT_LIBRARIES_DESTINATION}
		RUNTIME   DESTINATION ${PROJECT_RUNTIME_DESTINATION}
		INCLUDES  DESTINATION ${PROJECT_INCLUDES_DESTINATION}
	)
	file(GLOB HEADERS ${PROJECT_SOURCE_DIR}/include/*.hpp)
	install(
		FILES ${HEADERS}
		DESTINATION ${PROJECT_INCLUDES_DESTINATION}
	)
	install(
		EXPORT ${PROJECT_NAME} DESTINATION ${PROJECT_CMAKE_DESTINATION}
	)
endfunction()

# CMake Package Config Files
include(CMakePackageConfigHelpers)
# Config-file package
set(PACKAGE_CONFIG_FILE ${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake)
configure_package_config_file(
	${CMAKE_SOURCE_DIR}/pkg/${CMAKE_PROJECT_NAME}Config.cmake.in
	${PACKAGE_CONFIG_FILE}
	INSTALL_DESTINATION ${PROJECT_CMAKE_DESTINATION}
)
install(
	FILES ${PACKAGE_CONFIG_FILE}
	DESTINATION ${PROJECT_CMAKE_DESTINATION}
)

# Version-config-file package
set(PACKAGE_VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake)
write_basic_package_version_file(
	${PACKAGE_VERSION_FILE}
	VERSION ${CMAKE_PROJECT_VERSION}
	COMPATIBILITY SameMajorVersion
)
install(
	FILES ${PACKAGE_VERSION_FILE}
	DESTINATION ${PROJECT_CMAKE_DESTINATION}
)

# Version Module Mode
set(MODULE_VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/version.cmake)
configure_package_config_file(
	${CMAKE_SOURCE_DIR}/pkg/${CMAKE_PROJECT_NAME}-simple_version.cmake.in
	${MODULE_VERSION_FILE}
	INSTALL_DESTINATION ${PROJECT_CMAKE_DESTINATION}
)
install(
	FILES ${MODULE_VERSION_FILE}
	DESTINATION ${PROJECT_CMAKE_DESTINATION}
)
