#  minimum required cmake version: 3.1.0
cmake_minimum_required(VERSION 3.1.0)

project(3d-scanner)

# Save the command line compile commands in the build output
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

# Make project require C++11
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()

# commented all Windows related lines, might add later for Windows support

# Simple non robust way to find the librealsense library
# if(WIN32)
#     if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
#         set(LIBRARY_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\lib\\x64")          # TODO: Update this variable to correct path - folder where realsense2.lib is found
#         set(DLL_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\bin\\x64")              # TODO: Update this variable to correct path - folder where realsense2.dll is found
#     else()
#         set(LIBRARY_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\lib\\x86")          # TODO: Update this variable to correct path - folder where realsense2.lib is found
#         set(DLL_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\bin\\x86")              # TODO: Update this variable to correct path - folder where realsense2.dll is found
#     endif()
#     set(PROJECT_BINARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/\$\(Configuration\)")                # TODO: Update this variable to correct path - folder to which your project will compile
#     set(ADDITIONAL_INCLUDE_DIRS "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\include")   # TODO: Update this variable to correct path - folder where librealsense2 folder is found
# endif()


# find_library(REALSENSE2_FOUND realsense2 HINTS ${LIBRARY_DIR} REQUIRED)
# if(NOT REALSENSE2_FOUND)
#     SET(REALSENSE2_FOUND "realsense2")
#     message(WARN "Failed to find_library(realsense2)")
# endif()
find_package(realsense2 REQUIRED)
# find_package(GLFW3 REQUIRED)

# set(SOURCES 3d-scanner.cpp ${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/openglHelper.hpp)
add_executable(3d-scanner 3d-scanner.cpp)
include_directories(3d-scanner ${realsense2_INCLUDE_DIR})
# include_directories(${CMAKE_CURRENT_SOURCE_DIR}/thirdParty)
# include_directories(/opt/homebrew/include/)
# target_link_libraries(3d-scanner ${DEPENDENCIES})
target_link_libraries(3d-scanner ${realsense2_LIBRARY})
# target_link_libraries(3d-scanner glfw)
# set_target_properties (3d-scanner PROPERTIES FOLDER Examples)s

# Post Build script to copy realsense2.dll
# if(WIN32)
# message(STATUS "Adding Post build script to copy realsense2.dll to project's binary folder")
# message(STATUS "Will try to copy from ${DLL_DIR} to ${PROJECT_BINARY_OUTPUT_PATH}")
# add_custom_command(TARGET 3d-scanner POST_BUILD        # Adds a post-build event to 3d-scanner
#     COMMAND ${CMAKE_COMMAND} -E copy_if_different              # which executes "cmake - E copy_if_different..."
#         "${DLL_DIR}/realsense2.dll"                            # <--this is in-file
#         ${PROJECT_BINARY_OUTPUT_PATH})                 # <--this is out-file path
# endif()

install(
    TARGETS

    3d-scanner

    RUNTIME DESTINATION
    ${CMAKE_INSTALL_PREFIX}/bin
)