cmake_minimum_required (VERSION 3.14)

# Project simpleView
project(simpleView VERSION 0.1.0 LANGUAGES CXX)

# Ensure a build type is set properly
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type (Release, Debug, etc.)" FORCE)
endif()

# Check if we are on Windows
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  set(IS_WINDOWS TRUE)
endif()

# Use special CMake Find Modules to locate and use the OpenGl we are dependent on Windows.
# Irrelevant for Linux.
#
# GLEW -> external\GLEW
# GLUT -> external\freeglut
if(IS_WINDOWS)
  list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
endif()

# Locate and collect dependencies
find_package(GLEW   REQUIRED)
find_package(GLUT   REQUIRED)
find_package(OpenGL REQUIRED)
find_package(otcsdk REQUIRED)


# Create an executable named simpleView
add_executable(simpleView)

# Specify the source files
target_sources(
  simpleView
    PRIVATE
      src/main.cpp
      src/IRImagerShow.cpp
      src/display/opengl/Obvious2D.cpp
)

# Specifies the include directories
target_include_directories(
  simpleView
    PRIVATE
      src
)

# Specifies the libraries to link against
target_link_libraries( 
  simpleView
    PRIVATE
      GLEW::GLEW
      GLUT::GLUT
      OpenGL::GL
      otcsdk::otcsdk
)

# Adjust the target output directories
set_target_properties(simpleView
   PROPERTIES
    ARCHIVE_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_BINARY_DIR}>"
    LIBRARY_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_BINARY_DIR}>"
    RUNTIME_OUTPUT_DIRECTORY "$<1:${CMAKE_CURRENT_BINARY_DIR}>"
    PDB_OUTPUT_DIRECTORY     "$<1:${CMAKE_CURRENT_BINARY_DIR}>"
)

# On Windows we have to copy the runtime libraries (DLLs) to the working
# directory of our executable
if(IS_WINDOWS)
  add_custom_command(
    TARGET simpleView POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
            ${GLEW_RUNTIME_LIBRARY}
            ${CMAKE_CURRENT_BINARY_DIR}
  )

  add_custom_command(
    TARGET simpleView POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
            ${GLUT_RUNTIME_LIBRARY}
            ${CMAKE_CURRENT_BINARY_DIR}
  )
endif()