# Compulsory line
cmake_minimum_required(VERSION 2.6)

# The name of our project is "BDM".  CMakeLists files in this project can
# refer to the root source directory of the project as ${BDM_SOURCE_DIR} and
# to the root binary directory of the project as ${BDM_BINARY_DIR}.
project (BDM)

# In order to be able to use the newly written FindXXX package, the 
# location of the FindXXX.cmake file must be added to the cmake modules 
# list from within a CMakeLists.txt file as follows:
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}\\system\\")

######################
#Platform specific
IF(WIN32)
# IF YOU WANT TO USE YOUR OWN INSTALLATION OF THE NEXT EXTERNAL LIBRARIES,
# THEN IT IS NECESSARY TO CREATE TEXT FILE "\system\WIN32\LOCAL_PATHS.TXT" WITH 
# COPIES OF THE TWO FOLLOWING LINES AND THEN CORECT ALL THE INVOLVED PATHS
	SET(ITPP_DIR "${BDM_SOURCE_DIR}\\system\\win32\\itpp-4.0.6")
	SET(ACML_DIR "${BDM_SOURCE_DIR}\\system\\win32\\acml3.6.0")

	INCLUDE(\\system\\win32\\local_paths.txt OPTIONAL)	
	ADD_DEFINITIONS(-DHAVE_ACML)
ENDIF(WIN32)
IF(APPLE)
	SET(ITPP_DIR "${BDM_SOURCE_DIR}\\macosx\\itpp-4.0.6")
	FIND_LIBRARY(FRAMEWORK_VECLIB vecLib)
	ADD_DEFINITIONS(-DHAVE_XLOCALE_H)
ENDIF(APPLE)
IF(UNIX)
	#This is for UNIX makefile which does only one release at a time.
	SET(CMAKE_BUILD_TYPE Debug)
	SET(CMAKE_CXX_FLAGS "-Wall -pipe  -Wno-unknown-pragmas -fPIC")
	SET(CMAKE_C_FLAGS "-Wall -pipe  -Wno-unknown-pragmas -fPIC")
	SET(CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG -O2")
	SET(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
	#ADD_DEFINITIONS(-DNDEBUG)
	
	SET(MATLAB_ROOT ~/bin/matlab2008a)
	# MATLAB_ROOT can be setup in Local
ENDIF(UNIX)

# Local ettings should be written to file called CMakeLists.local
# Use this option for machine-specific options, such as prallel architectures
INCLUDE(CMakeLists.local OPTIONAL)	

FIND_PACKAGE(ITPP REQUIRED)
FIND_PACKAGE(ACML COMPONENTS)
FIND_PACKAGE(Matlab COMPONENTS)
FIND_PROGRAM(MEX_COMPILER mex)

IF(ITPP_FOUND)
	INCLUDE_DIRECTORIES(${ITPP_INCLUDE_DIR})
	LINK_DIRECTORIES(${NATIVE_ITPP_LIB_PATH})
ENDIF(ITPP_FOUND)

IF(ACML_FOUND)
	INCLUDE_DIRECTORIES(${ACML_INCLUDE_DIR})
	LINK_DIRECTORIES(${NATIVE_ACML_LIB_PATH})
ENDIF(ACML_FOUND)

##
## PREPARE MACROS for building executables
##

MACRO(EXEC FN)
	add_executable (${FN} ${FN}.cpp)
	IF(WIN32)
		target_link_libraries (${FN} debug itpp_debug)
		target_link_libraries (${FN} optimized itpp)
		target_link_libraries (${FN} libacml_dll)
 	ELSE(WIN32)
 		IF(APPLE)
 			target_link_libraries (${FN} ${FRAMEWORK_VECLIB})
 		ENDIF(APPLE)
#		target_link_libraries (${FN} itpp)	
		target_link_libraries (${FN} debug itpp_debug)
		target_link_libraries (${FN} optimized itpp)
 	ENDIF(WIN32)
	target_link_libraries (${FN} bdm)
	target_link_libraries (${FN} ${ARGN}) ## Additional libraries can be added to a macro
ENDMACRO(EXEC)
	


# Recurse into the "dbm" and "tests" subdirectories.  This does not actually
# cause another cmake executable to run.  The same process will walk through
# the project's entire directory structure.
add_subdirectory (bdm)
add_subdirectory (tests)
