#------------------------------------------------------------------------
#
# Cross platform CMake configure script for 'surface fitting' project
#
# authors: Vladimir Ulman
#          MPI-CBG @ Dresden (c) 2016
#
#------------------------------------------------------------------------

project(surfaceFitting)

cmake_minimum_required(VERSION 3.0) 

set(CMAKE_VERBOSE_MAKEFILE ON CACHE STRING
		  "Tracing the compilation process" FORCE)

#
# set the debug/release version
#
option(DEBUG_VERSION "Shall I add debug information?" OFF)

if (DEBUG_VERSION)
		  add_definitions(-DTRAGEN_DEBUG)
		  set(CMAKE_BUILD_TYPE "DEBUG" CACHE STATIC "" FORCE)
		  if (WIN32)
					 set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE)
		  endif (WIN32)
else (DEBUG_VERSION)
		  set(CMAKE_BUILD_TYPE "RELEASE" CACHE STATIC "" FORCE)
		  if (WIN32)
					 set(CMAKE_CONFIGURATION_TYPES "Release" CACHE STRING "" FORCE)
		  endif (WIN32)
endif (DEBUG_VERSION)

#----------------
# COMPILER FLAGS
#----------------

#
# enable warnings
#
if (WIN32)	
		  add_definitions(-DGSL_DLL -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE)
		  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /nologo /wd4251 /wd4275")
else (WIN32)
		  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wconversion")
endif (WIN32)

#
# enable OpenMP architecure
#
if (WIN32)
		  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
else (WIN32)
if (NOT APPLE)
		  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif (NOT APPLE)
endif (WIN32)

#
# due to Lapack+i3dalgo
#

if (NOT APPLE)
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -defsym -Xlinker MAIN__=main")
endif (NOT APPLE)

#
# user defined options
#


#---------------
# REQUIRED LIBS
#---------------

# OpenGL...
find_path(INC_GLUT "GL/glut.h")
include_directories(${INC_GLUT})

# OpenGL library
if (WIN32)
	set (LIB_OPENGL opengl32.lib)
else (WIN32)
	find_library(LIB_OPENGL GL)
endif (WIN32)

find_library(LIB_GLU  "GLU")
find_library(LIB_GLUT "glut")
set(LIBS ${LIBS} ${LIB_OPENGL} ${LIB_GLU} ${LIB_GLUT})

# GSL library
find_path(INC_GSL "gsl/gsl_randist.h")
include_directories(${INC_GSL})
find_library(LIB_GSL gsl)
find_library(LIB_GSLCBLAS gslcblas)
set(LIBS ${LIBS} ${LIB_GSL} ${LIB_GSLCBLAS})

#  # LAPACKE library
#  find_path(INC_LAPACKE "lapacke.h")
#  include_directories(${INC_LAPACKE})
#  #find_library(LIB_LAPACKE lapack)
#  find_library(LIB_LAPACKE liblapack.so.3)
#  set(LIBS ${LIBS} ${LIB_LAPACKE})

# i3dlibs libraries
find_path(INC_I3D "i3d/image3d.h")
include_directories(${INC_I3D})
find_library(LIB_I3DCORE i3dcore)
find_library(LIB_I3DALGO i3dalgo)
set(LIBS ${LIBS} ${LIB_I3DCORE} ${LIB_I3DALGO})

# fftw libraries
find_library(LIB_FFTW_SINGLE_THREADS fftw3f_threads)
find_library(LIB_FFTW_SINGLE fftw3f)

#--------------
# SOURCE FILES
#--------------

set(SOURCES 
		  src/graphics.cpp  
		  src/rnd_generators.cpp
		  src/texture/perlin.cc
		  src/texture/texture.cc
		  src/texture/myrandom.cc
		  src/texture/myround.cc
		  src/TriangleMesh.cpp)

#---------
# TARGETS
#---------
add_executable(textureModule ${SOURCES} src/main_Generator.cpp)
target_link_libraries(textureModule ${LIBS})

#add_executable(ISBI_Compactor ${SOURCES} src/main_Compactor.cpp)
#target_link_libraries(ISBI_Compactor ${LIBS})

#add_executable(ISBI_Vizualizator ${SOURCES} src/main_Vizualizator.cpp)
#target_link_libraries(ISBI_Vizualizator ${LIBS})

#add_executable(ISBI_Pressurator ${SOURCES} src/main_Pressurator.cpp)
#target_link_libraries(ISBI_Pressurator ${LIBS} ${LIB_FFTW_SINGLE_THREADS} ${LIB_FFTW_SINGLE})
