cmake_minimum_required(VERSION 3.10.0)
project(direct_volume_rendering_framework LANGUAGES C CXX)


set_directory_properties( PROPERTIES COMPILE_DEFINITIONS "" )



#set the build type if its not set
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()

if (UNIX)
  find_package(PkgConfig)
endif(UNIX)

# Location where cmake first looks for modules.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
set(GLOBAL_EXT_DIR ${CMAKE_SOURCE_DIR}/external)

#find_package (Threads REQUIRED)

################################
# glm
################################
set(GLM_DIRECTORY glm)
set(GLM_INCLUDE_DIR /external/${GLM_DIRECTORY})
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/${GLM_DIRECTORY})
################################

################################
# CLI11
################################
set(CLI11_DIRECTORY CLI11)
set(CLI11_INCLUDE_DIR /external/${CLI11_DIRECTORY})
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/external/${CLI11_DIRECTORY})
################################


# Add output directory
if(MSVC)
  set(BINARY_DIRECTORY build)
endif()
# MSVC & Xcode automatically create the build-type folders
if(MSVC OR CMAKE_GENERATOR STREQUAL Xcode)
  SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
  SET(LIBRARY_OUTPUT_PATH  ${PROJECT_BINARY_DIR})
else()
  SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
  SET(LIBRARY_OUTPUT_PATH  ${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE})
endif()

set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/bin")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)


# gl3w is used for loading GL extensions such as the NV task-mesh-shader ones
set(GL3W_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/gl3w/include)
set(GL3W_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/external/gl3w/src/GL/gl3w.c)

# hack for rapid prototyping - replace by several target_include_directories commands later
include_directories(${CMAKE_CURRENT_SOURCE_DIR/external})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/glfw)
set(GLFW_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/glfw/include)

# meshoptimizer by Arseny Kapoulkine (https://github.com/zeux/meshoptimizer)
# is used for creating a basis for a highly optimized reference mesh 
add_subdirectory(external/meshoptimizer EXCLUDE_FROM_ALL)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/meshoptimizer/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/)

################################
# activate C++ 17
if(MSVC)
    # build in parallel, show warnings
    message([STATUS] "building for MSCV")
    add_definitions(/MP /W3 /openmp)
else()
    add_definitions(-std=c++17 -fopenmp)
    # show warnings
    add_definitions(-Wall -Wextra)
    # force linking  with c++17 lib
    if(APPLE)
        set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0y")
        set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
        add_definitions(-stdlib=libc++)
    endif()
endif()

# the folder 'framework' contains the framework code for loading and using the different visualization modes
add_subdirectory(framework)

# actual app directory containing the code for compiling 'direct_volume_renderer_app'
add_subdirectory(apps)

################################
#if user didnt set install dir, override it and write it to the cache -> Type and description necessary,
#overwrite variable, not just write it to cache
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install" CACHE STRING "Install path prefix, prepended onto install directories." FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)


