cmake_minimum_required(VERSION 3.0)

# If you choose option 1 (so use your own cpp files in lab1/)
# you should set this to ON
option(USE_OWN_SRC_FILES_LAB1 "Use the cpp files in lab1/" ON)

# name the project/executable (also ${PROJECT_NAME})
project(raytracing)

# define the location of the current directory as '${ROOT}'
set(ROOT "${CMAKE_CURRENT_LIST_DIR}")

# define the paths to the cpp files
file(GLOB SRCFILES ${ROOT}/src/*.cpp)
list(APPEND SRCFILES ${ROOT}/main.cpp)

# the 'include' folder contains files that also need to be included in the project
include_directories(${ROOT}/include ${ROOT}/eigen)

# We need the code from lab 1. There are 2 options:

# OPTION 1: You copy-paste your code from lab 1 into the "lab1" folder
if(USE_OWN_SRC_FILES_LAB1)
	# add the files in "lab1" to ${SRCFILES}
	file(GLOB LAB1SRCFILES ${ROOT}/lab1/*.cpp)
	list (APPEND SRCFILES ${LAB1SRCFILES})

# OPTION 2: You use one of the static libraries in the "lib" folder
else()
    # define ${LIB_PATH} as the path to the static library, e.g. lib/Debug/win/
	
	if(NOT CMAKE_BUILD_TYPE)
	    # Only matters for Linux and Mac (and WSL)
        set(CMAKE_BUILD_TYPE "Debug")
    endif()

    if (MSVC)
	    set(LIB_PATH lib/Release/win/)
	elseif (APPLE)
	    set(LIB_PATH lib/${CMAKE_BUILD_TYPE}/mac/)
	elseif (UNIX)
	    set(LIB_PATH lib/${CMAKE_BUILD_TYPE}/linux/)
	else()
	    message("No static lib found for your platform. See OPTION 2 in CMakeLists.txt" )
	endif()
	
	# Tell the compiler that the ${LIB_PATH} folder is a "library directory"
	link_directories(${LIB_PATH})
endif()

# pass the SRCFILES files to be included during compilation
add_executable(${PROJECT_NAME} ${SRCFILES})

if(NOT USE_OWN_SRC_FILES_LAB1) # part of OPTION 2
    # Tell the compiler that it needs to link the hw2 library. The compiler will
	# look in the library directories, such as the ${LIB_PATH} folder from earlier
    target_link_libraries(${PROJECT_NAME} hw2)
endif()

# if using Visual Studio, set the startup project
if(MSVC)
	set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
endif()
