#
#   Universite catholique de Louvain
#   CEREM : Centre for research in mechatronics
#   http://www.robotran.be
#   Contact : info@robotran.be
#
# Authors: Nicolas Docquier, Nicolas Van der Noot, Timothee Habra, Olivier Lantsoght
#
# CMake for the COMAN project
#


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                        PROJECT SPECIFIC OPTIONS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# possibilities: init_feet ; long_feet ; flex_feet ; short_feet ; short_feet_simp
set( COMAN_VERSION "short_feet" )

# 0: normal run ; 1: evaluation run ; 2: test opti ; 3: BioRob opti ; 4: MPI opti
set( MAIN_RUN 0 )

# speed reference [m/s]
if (NOT CMAKE_V_REF)
	set (CMAKE_V_REF 0.65)
endif ( )

# height reference [m]
if(NOT CMAKE_H_REF)
	set (CMAKE_H_REF 0.065)
endif ( )

# length reference [m]
if(NOT CMAKE_L_REF)
	set (CMAKE_L_REF 0.40)
endif ( )

# compile Salman controller if ON
set ( SALMAN_CTRL OFF )


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                       PROJECT MAIN CONFIGURATIONS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# CMake minimum version
if (UNIX)
	cmake_minimum_required(VERSION 2.8.7)
else()
	cmake_minimum_required(VERSION 3.4)
endif ()

# project name
project (projectRobotran)

# project configuration
set( CMAKE_C_FLAGS_RELEASE   "-O3" )
set( CMAKE_CXX_FLAGS_RELEASE "-O3" )

# Variable for storing the path to Robotran common files (should be adapted depending on the location of those source)
if(NOT DEFINED ROBOTRAN_SOURCE_DIR)
	set(TRIAL_PATHS_MBSYSC
		/home/nico/Documents/Robotran/Projects/robotran/mbsysc/MBsysC    # Nico ThinkPad Linux
		/data/nvander/Documents/Robotran/Projects/robotran/mbsysc/MBsysC # Nico BioRob Linux
		C:/Users/Nico/Documents/Robotran/Projects/mbsysc/MBsysC          # Nico ThinkPad Windows
		/Users/MarieSophie/Documents/Robotran/Projects/mbsysc/MBsysC     # Mary Mac OS
		${PROJECT_SOURCE_DIR}/../mbsysCopy # copy folder
		D:/Documents/Github/mbsysc/MBsysC      # phil asus
		/home/pgreiner/Documents/mbsysc/MBsysC # phil biorob linux
	)
	find_path(ROBOTRAN_SOURCE_DIR mbs_common ${TRIAL_PATHS_MBSYSC} DOC "Path to the Robotran-MBsysC common files")
endif ( )

# variable for storing the path to Salman controller project (if any)
set (TRIAL_PATHS_SALMAN_WBO
	"/home/nico/Documents/Webots/Projects/CoMan/salman_wbo"
	"/data/nvander/Documents/Webots/Projects/salman_wbo"
)
find_path(SALMAN_WBO algorithms ${TRIAL_PATHS_SALMAN_WBO} DOC "Path to Salman controller project")

# force mbsysCopy for optimization
if ( MAIN_RUN GREATER 1 )
	set (ROBOTRAN_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../mbsysCopy")
	message(STATUS "forcing to use mbsyscopy")
endif ( )

# message to display the project name and COMAN version
message(STATUS "Processing ${PROJECT_NAME}")
message(STATUS "MBsysC path: ${ROBOTRAN_SOURCE_DIR}")
message(STATUS "CoMan version: ${COMAN_VERSION}")
message(STATUS "Speed ref: ${CMAKE_V_REF}")
message(STATUS "Height ref: ${CMAKE_H_REF}")
message(STATUS "Length ref: ${CMAKE_L_REF}")

# for Unix: display all the warnings, except the ones related to /* -- */, to unused variables and to unknown warnings
if (UNIX)
	set( CMAKE_C_FLAGS "-g -Wall -Wno-unused-but-set-variable -Wno-unused-variable -Wno-comment -Wno-unknown-warning-option" )
endif ( )


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                         Windows libraries
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

if (WIN32)

	# avoid warnings
	if(COMMAND cmake_policy)
		cmake_policy(SET CMP0054 NEW)
	endif()

	# Visual studio version
	if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
		if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 18.0)
			message("Visual Studio version set to VS2012 (${CMAKE_CXX_COMPILER_VERSION})")
			set(MSVC_VERSION lib-vc2012)
		elseif (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 19.0)
			message("Visual Studio version set to VS2013 (${CMAKE_CXX_COMPILER_VERSION})")
			set(MSVC_VERSION lib-vc2013)
		else ( )
			message("Visual Studio version set to VS2015 (${CMAKE_CXX_COMPILER_VERSION})")
			set(MSVC_VERSION lib-vc2015)
		endif ( )
	else ( )
		message(FATAL_ERROR "CMake error: only Visual Studio projects can currently be used on Windows !")
	endif ( )

	## --- WIN32 or WIN64 DETECTION --- ##
	if( CMAKE_SIZEOF_VOID_P EQUAL 8 )   # 64bit Windows
		SET(WIN_LIB_DIRECTORY win64_include_lib)
	else( )  # 32bit Windows
		SET(WIN_LIB_DIRECTORY win32_include_lib)
	endif( )

	## ---- WINDOWS DLL FILES ---- ##

	# copy all the dll (except 'jvm.dll') used for Windows
	# these dll files are copied in the Executable directory (Debug or Release)
	
	# common dll
	file(COPY ${ROBOTRAN_SOURCE_DIR}/${WIN_LIB_DIRECTORY}/dll/ DESTINATION ${CMAKE_BINARY_DIR}/Debug)
	file(COPY ${ROBOTRAN_SOURCE_DIR}/${WIN_LIB_DIRECTORY}/dll/ DESTINATION ${CMAKE_BINARY_DIR}/Release)

	# GLPK dll
	file(COPY ${PROJECT_SOURCE_DIR}/../mbsysCopy/extra_win/glpk/${WIN_LIB_DIRECTORY}/dll/ DESTINATION ${CMAKE_BINARY_DIR}/Debug)
	file(COPY ${PROJECT_SOURCE_DIR}/../mbsysCopy/extra_win/glpk/${WIN_LIB_DIRECTORY}/dll/ DESTINATION ${CMAKE_BINARY_DIR}/Release)

	# GLFW dll
	file(COPY ${ROBOTRAN_SOURCE_DIR}/${WIN_LIB_DIRECTORY}/dll/GLFW/${MSVC_VERSION}/ DESTINATION ${CMAKE_BINARY_DIR}/Debug)
	file(COPY ${ROBOTRAN_SOURCE_DIR}/${WIN_LIB_DIRECTORY}/dll/GLFW/${MSVC_VERSION}/ DESTINATION ${CMAKE_BINARY_DIR}/Release)
endif ( )

# install prefix
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/Debug)

# find libraries paths
set(CMAKE_MODULE_PATH ${ROBOTRAN_SOURCE_DIR}/conf ${PROJECT_SOURCE_DIR}/../mbsysCopy/extra_conf)


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                         Additional CMakelists.txt
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# additional CMake functions
set(CMAKE_AUX ${ROBOTRAN_SOURCE_DIR}/cmake_aux)
set(CMAKE_AUX_BIN ${PROJECT_BINARY_DIR}/cmake_aux)

add_subdirectory ( ${CMAKE_AUX}/flags/     ${CMAKE_AUX_BIN}/flags/     )
add_subdirectory ( ${CMAKE_AUX}/listing/   ${CMAKE_AUX_BIN}/listing/   )
add_subdirectory ( ${CMAKE_AUX}/libraries/ ${CMAKE_AUX_BIN}/libraries/ )
add_subdirectory ( ${CMAKE_AUX}/make_opt/  ${CMAKE_AUX_BIN}/make_opt/  )


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                    PROJECT SPECIFIC OPTIONS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# symbolic path
set ( SYMBOLIC_PATH symbolicR/${COMAN_VERSION} )

find_package( SeparateLibs )

# link to MBSysC lib already compiled
if ( SEPARATE_MBS_COMMON_FOUND )

	message("\n   MBsysC libraries found, FLAG_SEPARATE_BUILD set to ON !")
	set (FLAG_SEPARATE_BUILD ON)

	# link to symbolic files already compiled
	if ( SEPARATE_SYMBOLIC_FOUND )
		message("   Symbolic library found, FLAG_SEPARATE_SYMBOLIC set to ON !\n")
		set (FLAG_SEPARATE_SYMBOLIC ON)
	else ( )
		message("   Symbolic library not found, FLAG_SEPARATE_SYMBOLIC set to OFF !\n")
		set (FLAG_SEPARATE_SYMBOLIC OFF)
	endif ( )

# compile the whole project
else ( )
	message("\n   Not all MBsysC libraries found, compiling the whole project !\n")
	set (FLAG_SEPARATE_BUILD OFF)
	set (FLAG_SEPARATE_SYMBOLIC OFF)
endif ( )

# link to user function files already compiled (always off)
set (FLAG_SEPARATE_USER_FCT OFF)

# real-time when not performing an optimization
if ( MAIN_RUN LESS 2 )
	option (FLAG_REAL_TIME "Real time" ON)
	option (FLAG_JAVA "Real time (Java 3D visualization)" OFF)
	option (FLAG_OPEN_GL "Real time (OpenGL 3D visualization)" ON)
	option (FLAG_PLOT "Plot and interact" ON)
	option (FLAG_VISU "Visualization" ON)
endif ( )

# CMake functions
release_debug()
make_options()

# MBsysC files to compile
if (NOT FLAG_SEPARATE_BUILD)
	add_subdirectory( ${ROBOTRAN_SOURCE_DIR}/mbs_common ${CMAKE_CURRENT_BINARY_DIR}/mbs_common )
	flags_check()
	definitions()
endif ( )


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                             EXTRA LIBRARIES
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# Biorob Cluster
if ( MAIN_RUN EQUAL 3 )
	find_package( BiorobOpti REQUIRED )
	if (BIOROB_OPTI_FOUND)
		include_directories (${BIOROB_OPTI_INCLUDE_PATH})
		message( "\n  >> main: BiorobOpti found")
	else ( )
		message( "\n  >> main: BiorobOpti not found, modify ${PROJECT_SOURCE_DIR}/../mbsysCopy/extra_conf/FindBiorobOpti.cmake")
	endif ( )

	message("      -> INC : ${BIOROB_OPTI_INCLUDE_PATH}")
	message("      -> LIB : ${BIOROB_OPTI_LIBRARIES}\n")
endif ( )

# MPI library
if ( MAIN_RUN EQUAL 4 )
	find_package(MPI REQUIRED)
	if (MPI_FOUND)
		include_directories (${MPI_INCLUDE_PATH})
		message( "\n  >> main: MPI found")
	else ( )
		message( "\n  >> main: MPI not found")
	endif ( )

	message("      -> INC : ${MPI_INCLUDE_PATH}")
	message("      -> LIB : ${MPI_LIBRARIES}\n")
endif ( )

# GLPK library
add_definitions( -D GLPK_LIB )
find_package( GLPK REQUIRED )
if (GLPK_FOUND)
	include_directories (${GLPK_INCLUDE_PATH})
	message( "\n  >> main: GLPK found")
else ( )
	message( "\n  >> main: GLPK not found, modify ${PROJECT_SOURCE_DIR}/../mbsysCopy/extra_conf/FindGLPK.cmake")
endif ( )

message("      -> INC : ${GLPK_INCLUDE_PATH}")
message("      -> LIB : ${GLPK_LIBRARIES}\n")

if ( SALMAN_CTRL )

	# add definition
	add_definitions( -D SALMAN_WBO )

	# Salman libraries
	find_package( SalmanWbo REQUIRED )
	if (SALMAN_LIBS_FOUND)
		message( "  >> main: Salman libraries found")
	else ( )
		message( "  >> main: Salman libraries not found, modify ${PROJECT_SOURCE_DIR}/../mbsysCopy/extra_conf/FindSalmanWbo.cmake")
	endif ( )

	message("      -> LIB : ${LIB_SALMAN_ODO};${LIB_SALMAN_ROBOT};${LIB_SALMAN_SDFAST};${LIB_SALMAN_WBO}\n")

	# Eigen library
	find_package (Eigen3 REQUIRED)
	if (EIGEN3_FOUND)
		include_directories (${EIGEN3_INCLUDE_DIR})
		message( "\n  >> main: Eigen3 found")
	else ( )
		message( "\n  >> main: Eigen3 not found")
	endif ( )

	message("      -> INC : ${EIGEN3_INCLUDE_DIR}\n")

	# Boost library
	find_package(Boost COMPONENTS system REQUIRED)
	if (Boost_FOUND)
		include_directories (${Boost_INCLUDE_DIR})
		message( "\n  >> main: system boost found")
	else ( )
		message( "\n  >> main: system boost not found")
	endif ( )

	message("      -> INC : ${Boost_INCLUDE_DIR}")
	message("      -> LIB : ${Boost_SYSTEM_LIBRARY}\n")
endif ( )


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                         FLAGS RELATED FUNCTIONS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


# debug or release
if( CMAKE_BUILD_TYPE MATCHES "Debug" )
	add_definitions( -D DEBUG_VERSION )
	message(STATUS "Debug version !")
endif( )

# evaluation run
if ( MAIN_RUN EQUAL 1 )
	add_definitions( -D EVAL_RUN )
	message(STATUS "Evaluation run !")
endif (  )

# optimization run
if ( MAIN_RUN GREATER 1 )
	add_definitions( -D OPTI_RUN )
	message(STATUS "Running optimization !")
endif (  )

# BioRob optimization
if ( MAIN_RUN EQUAL 3 )
	add_definitions( -D OPTI_BIOROB )
	message(STATUS "BioRob cluster !")
endif (  )

# MPI optimization
if ( MAIN_RUN EQUAL 4 )
	add_definitions( -D OPTI_MPI )
	message(STATUS "MPI computation !")
endif (  )

# Windows M_PI definitions
if (WIN32)
	add_definitions(-D _USE_MATH_DEFINES)
endif (WIN32)

# Robotran simulation flag
add_definitions ( -D ROBOTRAN_SIMU )


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                           USER ABSOLUTE PATHS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# name of the build folder (relative to main CMakelists.txt)
set(BUILD_PATH ${PROJECT_BINARY_DIR})
file(RELATIVE_PATH BUILD_PATH_REL ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})

# upper-case letters of COMAN version
string(TOUPPER ${COMAN_VERSION} COMAN_VERSION_UPPER)

# configure a header file to pass some of the CMake settings to the source code
configure_file (
	"${ROBOTRAN_SOURCE_DIR}/conf/cmake_config.h.in"
	"${PROJECT_BINARY_DIR}/conf/cmake_config.h"
)

configure_file (
	"${PROJECT_SOURCE_DIR}/src/conf/cmake_define.h.in"
	"${PROJECT_BINARY_DIR}/conf/cmake_define.h"
)

include_directories (${PROJECT_BINARY_DIR}/conf)


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                           LIST FILES
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
# list source files to compile
init_src()

increment_src( ${PROJECT_SOURCE_DIR}/src )

if ( SALMAN_CTRL )
	increment_src ( ${SALMAN_WBO}/algorithms/s_dynamic_walk/src )
endif ( )

# list include directories (to find headers)
init_include()

increment_include( ${PROJECT_SOURCE_DIR}/src )
increment_include( ${PROJECT_SOURCE_DIR}/../parallel_simu/src )
increment_include( ${PROJECT_SOURCE_DIR}/../userfctR )
increment_include( ${PROJECT_SOURCE_DIR}/../userFiles )
increment_include( ${PROJECT_SOURCE_DIR}/../${SYMBOLIC_PATH} )
increment_include( ${ROBOTRAN_SOURCE_DIR}/mbs_common )

if ( SALMAN_CTRL )
	increment_include ( ${SALMAN_WBO}/algorithms/s_dynamic_walk/include )
	increment_include ( ${SALMAN_WBO}/algorithms/robot/include )
endif ( )

# SDL.h header
if ( FLAG_PLOT )
	sdl_header_lib(project)
endif ( )


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                           EXTERNAL LIBRARIES
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

## ---- PYTHON SCRIPTS FOR OPTI ---- ##

# BioRob
if (MAIN_RUN EQUAL 3)
	file(COPY ${PROJECT_SOURCE_DIR}/../opti/python/xml_gen.py DESTINATION ${CMAKE_BINARY_DIR})
	file(COPY ${PROJECT_SOURCE_DIR}/../opti/python/biorob_res_gen.py DESTINATION ${CMAKE_BINARY_DIR})
	file(COPY ${PROJECT_SOURCE_DIR}/../opti/python/nb_opti_params.py DESTINATION ${CMAKE_BINARY_DIR})
	file(COPY ${PROJECT_SOURCE_DIR}/../opti/config/OptiParams.cc DESTINATION ${CMAKE_BINARY_DIR})
endif ( )

# MPI
if (MAIN_RUN EQUAL 4)
	file(COPY ${PROJECT_SOURCE_DIR}/../opti/python/mpi_res_gen.py DESTINATION ${CMAKE_BINARY_DIR})
endif ( )


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                         EXECUTABLE COMPILATION
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

# include these directories
include_directories (${INCLUDE_DIR})

# name of the executable
if ( MAIN_RUN GREATER 2 ) # opti cluster
	set (Executable dispatcher_opti)
else ( )
	set (Executable exe_${PROJECT_NAME})
endif ( )

# generate the executable
add_executable ( ${Executable} ${SOURCE_FILES} )


# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
#                         EXECUTABLE LINKING
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

flags_clean()

if ( FLAG_SEPARATE_BUILD ) # find MBSysC dynamic libraries

	find_path(LibRobotranC_DIR LibRobotranCConfig.cmake "${ROBOTRAN_SOURCE_DIR}/build")
	find_package( LibRobotranC REQUIRED )
	target_link_libraries( ${Executable} ${LIB_MBSYSC_MODULES} ${LIB_MBSYSC_LOAD} ${LIB_MBSYSC_UTILITIES} )
	add_definitions(${LIB_MBSYSC_DEFINITIONS})

	# user function and symbolic libraries
	target_link_libraries ( ${Executable} Project_userfct )

	if ( FLAG_SEPARATE_SYMBOLIC )
		target_link_libraries ( ${Executable} ${LIB_SYMBOLIC} )
	endif ( )

	if (WIN32)

		## ---- WINDOWS DLL FILES ---- ##

		# find dll directories (Debug or Release)
		get_filename_component(LIB_MBSYSC_MODULES_DIR ${LIB_MBSYSC_MODULES} DIRECTORY)
		get_filename_component(LIB_MBSYSC_LOAD_DIR ${LIB_MBSYSC_LOAD} DIRECTORY)
		get_filename_component(LIB_MBSYSC_UTILITIES_DIR ${LIB_MBSYSC_UTILITIES} DIRECTORY)
		get_filename_component(LIB_MBSYSC_REALTIME_DIR ${LIB_MBSYSC_REALTIME} DIRECTORY)

		# copy all the dll used for Windows
		# these dll files are copied in the Executable directory (Debug)
		file(COPY ${LIB_MBSYSC_MODULES_DIR}\\MBsysC_module.dll DESTINATION ${CMAKE_BINARY_DIR}\\Debug)
		file(COPY ${LIB_MBSYSC_LOAD_DIR}\\MBsysC_loadXML.dll DESTINATION ${CMAKE_BINARY_DIR}\\Debug)
		file(COPY ${LIB_MBSYSC_UTILITIES_DIR}\\MBsysC_utilities.dll DESTINATION ${CMAKE_BINARY_DIR}\\Debug)
		file(COPY ${LIB_MBSYSC_REALTIME_DIR}\\MBsysC_realtime.dll DESTINATION ${CMAKE_BINARY_DIR}\\Debug)

	endif ( )

else ( )

	target_link_libraries( ${Executable} MBsysC_loadXML MBsysC_module )

	if (NOT FLAG_SHARED_LIB)

		# find MBSysC static libraries
		target_link_libraries( ${Executable} MBsysC_numerics MBsysC_realtime MBsysC_utilities )

		#user functions library
		target_link_libraries ( ${Executable} Project_userfct )
		target_link_libraries ( ${Executable} Project_symbolic )

		#Libxml2 and GSL external libraries
		target_link_libraries ( ${Executable} ${LIBXML2_LIBRARIES} ${GSL_LIBRARIES} )

		# SDL external library
		if (FLAG_PLOT)
			target_link_libraries ( ${Executable} ${SDL2_LIBRARIES} ${SDL2TTF_LIBRARIES} )
		endif ( )

		# Java external library
		if (FLAG_JAVA)
			target_link_libraries ( ${Executable} ${JNI_LIBRARIES} )
		endif ( )

		# OpenGL external library
		if (FLAG_OPEN_GL)

		endif ( )
			   
	endif ( )

endif ( )

# include MBsysC directories
include_directories(${LIB_MBSYSC_INCLUDE_DIRS})

# symbolic files
if ( FLAG_SEPARATE_SYMBOLIC )
	if( UNIX )
		file(COPY ${PROJECT_SOURCE_DIR}/../${SYMBOLIC_PATH}/build/libProject_symbolic.so DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/symbolicR)
	else() # Windows (to be tested)
		file(COPY ${PROJECT_SOURCE_DIR}/../${SYMBOLIC_PATH}/build/Debug/libProject_symbolic.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
	endif()
else ( )
	add_subdirectory( ${PROJECT_SOURCE_DIR}/../${SYMBOLIC_PATH} ${CMAKE_CURRENT_BINARY_DIR}/symbolicR)
endif ( )

# user fonction files
if ( FLAG_SEPARATE_USER_FCT )
	if( UNIX )
		file(COPY ${PROJECT_SOURCE_DIR}/../userfctR/build/libProject_userfct.so DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/userfctR)
	else() # Windows (to be tested)
		file(COPY ${PROJECT_SOURCE_DIR}/../userfctR/build/Debug/libProject_userfct.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Debug)
	endif()
else ( )
	add_subdirectory( ${PROJECT_SOURCE_DIR}/../userfctR ${CMAKE_CURRENT_BINARY_DIR}/userfctR)
endif ( )

# dynamic linking library
if (UNIX)
	target_link_libraries ( ${Executable} dl )
endif ( )

# math external library (for Unix)
if (UNIX)
	target_link_libraries ( ${Executable} m )
endif ( )

# Biorob Cluster
if ( MAIN_RUN EQUAL 3 )
	target_link_libraries (${Executable} ${BIOROB_OPTI_LIBRARIES})
endif ( )

# MPI library
if ( MAIN_RUN EQUAL 4 )
	target_link_libraries (${Executable} ${MPI_LIBRARIES})
endif ( )

# GLPK library
target_link_libraries (${Executable} ${GLPK_LIBRARIES})

if ( SALMAN_CTRL )
	# Salman libraries
	target_link_libraries (${Executable} ${LIB_SALMAN_ROBOT} ${LIB_SALMAN_ODO} ${LIB_SALMAN_SDFAST} ${LIB_SALMAN_WBO})

	# Boost library
	target_link_libraries (${Executable} ${Boost_SYSTEM_LIBRARY})
endif ( )
