#-------------------------------------------------------------------
# This file is part of the CMake build system for Hydrax
#
# The contents of this file are placed in the public domain. Feel
# free to make use of it in any way you like.
#-------------------------------------------------------------------

######################################################################
# Hydrax BUILD SYSTEM
# Welcome to the CMake build system for Hydrax.
# Inspired from the Ogre build system (modules FindPkgMacros.cmake,
# This is the main file where we prepare the general build environment
# and provide build configuration options.
######################################################################

cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0003 NEW)

# Project name
project(HYDRAX)

# Include necessary submodules
set(CMAKE_MODULE_PATH
  ${CMAKE_MODULE_PATH}
  "${HYDRAX_SOURCE_DIR}/CMake"
  "${HYDRAX_SOURCE_DIR}/CMake/Utils"
)

include(CMakeDependentOption)
include(CheckCXXCompilerFlag)
include(HydraxMacroLogFeature)
include(HydraxConfigTargets)
set(HYDRAX_TEMPLATES_DIR "${HYDRAX_SOURCE_DIR}/CMake/Templates")
set(HYDRAX_WORK_DIR ${HYDRAX_BINARY_DIR})


#####################################################################
# Set up the basic build environment
#####################################################################

if (CMAKE_BUILD_TYPE STREQUAL "")
  # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
  # differentiation between debug and release builds.
  set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()

# determine Hydrax version numbers
include(HydraxGetVersion)
hydrax_get_version(${HYDRAX_SOURCE_DIR}/Hydrax/include/HydraxPrerequisites.h)
message(STATUS "Configuring HYDRAX ${HYDRAX_VERSION}")

# Create debug libraries with _d postfix
if (NOT APPLE)
  set(CMAKE_DEBUG_POSTFIX "_d")
endif ()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if (APPLE AND NOT ANDROID)
  if(CMAKE_VERSION VERSION_LESS 3.0.0)
    include(CMakeForceCompiler)
    CMAKE_FORCE_C_COMPILER(clang GNU)
    CMAKE_FORCE_CXX_COMPILER(clang++ GNU)
  endif()
  SET(CMAKE_SIZEOF_VOID_P 4)
  set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0")
  set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
  set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
endif ()

# Set compiler specific build flags
if (MSVC)
  add_definitions(/fp:fast)
endif ()

# Add Main include path
include_directories("${HYDRAX_SOURCE_DIR}/Hydrax/include")

# Find dependencies
include(HydraxDependencies)

# definitions for samples
set(HYDRAX_LIBRARIES hydrax)
if (NOT WIN32)
    set(HYDRAX_LIBRARIES ${HYDRAX_LIBRARIES} pthread)
endif(NOT WIN32)

# Specify build paths
# Scol edit: iOS build would be disrupted because of that
if (NOT IOS)
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${HYDRAX_BINARY_DIR}/lib")
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${HYDRAX_BINARY_DIR}/lib")
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${HYDRAX_BINARY_DIR}/bin")
endif()

if (WIN32 OR APPLE)
  if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    # We don't want to install in default system location, install is really for the SDK, so call it for that
    set(CMAKE_INSTALL_PREFIX "${HYDRAX_BINARY_DIR}/sdk" CACHE PATH "HYDRAX install prefix" FORCE)
  endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif(WIN32 OR APPLE)

######################################################################
# Provide user options to customise the build process
######################################################################

# Customise what to build
cmake_dependent_option(HYDRAX_STATIC "Static build" FALSE "OGRE_STATIC" TRUE)
option(HYDRAX_BUILD_SAMPLES "Build Hydrax demo" FALSE)

###################################################################
# configure global build settings based on selected build options
###################################################################
include(HydraxConfigureBuild)

##################################################################
# Now setup targets
##################################################################

# Setup Hydrax core project
add_subdirectory(Hydrax)

if(HYDRAX_BUILD_SAMPLES)
  # Setup samples
  add_subdirectory(Samples)
endif(HYDRAX_BUILD_SAMPLES)

# Install CMake modules
# add_subdirectory(CMake)