Index: library/system/FindMatlab.cmake
===================================================================
--- library/system/FindMatlab.cmake (revision 357)
+++ library/system/FindMatlab.cmake (revision 406)
@@ -1,88 +1,119 @@
-# - this module looks for Matlab
+# - This module looks for Matlab and associated development libraries
 # Defines:
 #  MATLAB_INCLUDE_DIR: include path for mex.h, engine.h
-#  MATLAB_LIBRARIES:   required libraries: libmex, etc
-#  MATLAB_MAT_LIBRARY: path to libmat.lib
-#  MATLAB_MEX_LIBRARY: path to libmex.lib
-#  MATLAB_MX_LIBRARY:  path to libmx.lib
-#  MATLAB_ENG_LIBRARY: path to libeng.lib
+#  MATLAB_LIBRARIES:        required libraries: libmex, etc
+#  MATLAB_MEX_LIBRARY:      path to libmex.lib
+#  MATLAB_MX_LIBRARY:       path to libmx.lib
+#  MATLAB_ENG_LIBRARY:      path to libeng.lib
+#  MATLAB_MEX_VERSION_FILE: path to mexversion.rc or mexversion.c
+#  MATLAB_MEX_SUFFIX:       filename suffix for mex-files (e.g. '.mexglx' or '.mexw64')
+
+# This version modified by RW Penney, November 2008
+# $Revision: 27 $, $Date: 2008-12-22 11:47:45 +0000 (Mon, 22 Dec 2008) $
 
 
 SET(MATLAB_FOUND 0)
+
 IF(WIN32)
-  IF(${CMAKE_GENERATOR} MATCHES "Visual Studio .*" OR ${CMAKE_GENERATOR} MATCHES "NMake Makefiles")
-    SET(MATLAB_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.0;MATLABROOT]/extern/lib/win32/microsoft/")
-  ELSE(${CMAKE_GENERATOR} MATCHES "Visual Studio .*" OR ${CMAKE_GENERATOR} MATCHES "NMake Makefiles")
-      IF(${CMAKE_GENERATOR} MATCHES "Borland")
-        # Same here, there are also: bcc50 and bcc51 directories
-        SET(MATLAB_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.0;MATLABROOT]/extern/lib/win32/microsoft/bcc54")
-      ELSE(${CMAKE_GENERATOR} MATCHES "Borland")
-        MESSAGE(FATAL_ERROR "Generator not compatible: ${CMAKE_GENERATOR}")
-      ENDIF(${CMAKE_GENERATOR} MATCHES "Borland")
-  ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio .*" OR ${CMAKE_GENERATOR} MATCHES "NMake Makefiles")
-  FIND_LIBRARY(MATLAB_MEX_LIBRARY
-    libmex
-    ${MATLAB_ROOT}
-    )
-  FIND_LIBRARY(MATLAB_MX_LIBRARY
-    libmx
-    ${MATLAB_ROOT}
-    )
-  FIND_LIBRARY(MATLAB_ENG_LIBRARY
-    libeng
-    ${MATLAB_ROOT}
-    )
-  FIND_LIBRARY(MATLAB_MAT_LIBRARY
-    libmat
-    ${MATLAB_ROOT}
-    )
 
-  FIND_PATH(MATLAB_INCLUDE_DIR
-    "mex.h"
-    "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\7.0;MATLABROOT]/extern/include"
-    )
-ELSE( WIN32 )
+  FILE(GLOB _auto_matlab_prefixes "C:/Program Files/MATLAB*/R20*")
+
+  IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
+    # Regular x86
+    SET(MATLAB_MEX_SUFFIX mexw32)
+    SET(_extern_arch "win32")
+  ELSE(CMAKE_SIZEOF_VOID_P EQUAL 4)
+    SET(MATLAB_MEX_SUFFIX mexw64)
+    SET(_extern_arch "win64")
+  ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)
+
+  # Search for available compilers:
+  # (This would be neater using 'ELSEIF', but that isn't available until cmake-2.4.4)
+  IF(${CMAKE_GENERATOR} MATCHES "Visual Studio 6")
+    SET(_matlab_path_suffixes "extern/lib/${_extern_arch}/microsoft/msvc60"
+        "extern/lib/${_extern_arch}/microsoft")
+  ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio 6")
+  IF(${CMAKE_GENERATOR} MATCHES "Visual Studio 7")
+    SET(_matlab_path_suffixes "extern/lib/${_extern_arch}/microsoft/msvc70"
+        "extern/lib/${_extern_arch}/microsoft")
+  ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio 7")
+  IF(${CMAKE_GENERATOR} MATCHES "Visual Studio [891]*")
+    SET(_matlab_path_suffixes "extern/lib/${_extern_arch}/microsoft/msvc71"
+        "extern/lib/${_extern_arch}/microsoft")
+  ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio [891]*")
+  IF(${CMAKE_GENERATOR} MATCHES "Borland")
+    SET(_matlab_path_suffixes "extern/lib/win32/microsoft/bcc54")
+  ENDIF(${CMAKE_GENERATOR} MATCHES "Borland")
+  IF(NOT _matlab_path_suffixes)
+    MESSAGE(FATAL_ERROR "Generator not compatible: ${CMAKE_GENERATOR}")
+  ENDIF(NOT _matlab_path_suffixes)
+
+  SET(_libmex_name "libmex")
+  SET(_libmx_name "libmx")
+  SET(_libeng_name "libeng")
+
+ELSE(WIN32)
+
   IF(NOT MATLAB_ROOT)
     IF($ENV{MATLAB_ROOT})
       SET(MATLAB_ROOT $ENV{MATLAB_ROOT})
     ELSE($ENV{MATLAB_ROOT})
-      SET(MATLAB_ROOT /opt/matlab)
+      SET(MATLAB_ROOT "$ENV{HOME}/bin/matlab*")
     ENDIF($ENV{MATLAB_ROOT})    
   ENDIF(NOT MATLAB_ROOT)
+
+  FILE(GLOB _auto_matlab_prefixes "/usr/local/matlab*" "/opt/matlab*" ${MATLAB_ROOT})
+
   IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
     # Regular x86
-    SET(MATLAB_SYS
-      ${MATLAB_ROOT}/bin/glnx86
-      )
+    SET(_matlab_path_suffixes "bin/glnx86")
+    SET(MATLAB_MEX_SUFFIX mexglx)
   ELSE(CMAKE_SIZEOF_VOID_P EQUAL 4)
-    # AMD64:
-    SET(MATLAB_SYS
-      ${MATLAB_ROOT}/bin/glnxa64
-      )
+    SET(_matlab_path_suffixes "bin/glnxa64")
+    SET(MATLAB_MEX_SUFFIX mexa64)
   ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)
-  FIND_LIBRARY(MATLAB_MEX_LIBRARY
-    mex
-    ${MATLAB_SYS}
-    )
-  FIND_LIBRARY(MATLAB_MX_LIBRARY
-    mx
-    ${MATLAB_SYS}
-    )
-  FIND_LIBRARY(MATLAB_MAT_LIBRARY
-    mat
-    ${MATLAB_SYS}
-    )
-  FIND_LIBRARY(MATLAB_ENG_LIBRARY
-    eng
-    ${MATLAB_SYS}
-    )
-  FIND_PATH(MATLAB_INCLUDE_DIR
-    "mex.h"
-    ${MATLAB_ROOT}/extern/include
-    )
+
+  SET(_libmex_name "mex")
+  SET(_libmx_name "mx")
+  SET(_libeng_name "eng")
 
 ENDIF(WIN32)
 
-# This is common to UNIX and Win32:
+
+SET(_matlab_path_prefixes
+  ${MATLAB_PATH_PREFIXES}
+  ${_auto_matlab_prefixes}
+  ${MATLAB_ROOT}
+)
+
+# Search for include-files & libraries using architecture-dependent paths:
+FOREACH(_matlab_prefix ${_matlab_path_prefixes})
+  MESSAGE("searching ${_matlab_prefix}")
+  IF(NOT MATLAB_INCLUDE_DIR)
+    FIND_PATH(MATLAB_INCLUDE_DIR "mex.h"
+      ${_matlab_prefix}/extern/include)
+
+    IF(MATLAB_INCLUDE_DIR)
+      SET(MATLAB_ROOT ${_matlab_prefix}
+        CACHE PATH "Matlab installation directory")
+      IF(WIN32)
+        SET(MATLAB_MEX_VERSIONFILE "${_matlab_prefix}/extern/include/mexversion.rc")
+      ELSE(WIN32)
+        SET(MATLAB_MEX_VERSIONFILE "${_matlab_prefix}/extern/src/mexversion.c")
+      ENDIF(WIN32)
+    ENDIF(MATLAB_INCLUDE_DIR)
+  ENDIF(NOT MATLAB_INCLUDE_DIR)
+
+  FOREACH(_matlab_path_suffix ${_matlab_path_suffixes})
+    SET(_matlab_libdir ${_matlab_prefix}/${_matlab_path_suffix})
+    MESSAGE("Searching ${_matlab_prefix} ... ${_matlab_libdir}")
+    IF(NOT MATLAB_MEX_LIBRARY)
+      FIND_LIBRARY(MATLAB_MEX_LIBRARY ${_libmex_name} ${_matlab_libdir})
+      FIND_LIBRARY(MATLAB_MX_LIBRARY ${_libmx_name} ${_matlab_libdir})
+      FIND_LIBRARY(MATLAB_ENG_LIBRARY ${_libeng_name} ${_matlab_libdir})
+    ENDIF(NOT MATLAB_MEX_LIBRARY)
+  ENDFOREACH(_matlab_path_suffix)
+ENDFOREACH(_matlab_prefix)
+
 SET(MATLAB_LIBRARIES
   ${MATLAB_MEX_LIBRARY}
@@ -91,30 +122,21 @@
 )
 
-IF(MATLAB_INCLUDE_DIR 
-    AND MATLAB_MEX_LIBRARY 
-    AND MATLAB_MAT_LIBRARY
-    AND MATLAB_ENG_LIBRARY
-    AND MATLAB_MX_LIBRARY)
-  SET(MATLAB_LIBRARIES ${MATLAB_MX_LIBRARY} ${MATLAB_MEX_LIBRARY} ${MATLAB_ENG_LIBRARY} ${MATLAB_MAT_LIBRARY})
-ENDIF(MATLAB_INCLUDE_DIR 
-    AND MATLAB_MEX_LIBRARY 
-    AND MATLAB_MAT_LIBRARY
-    AND MATLAB_ENG_LIBRARY
-    AND MATLAB_MX_LIBRARY)
+IF(MATLAB_INCLUDE_DIR AND MATLAB_LIBRARIES)
+  SET(MATLAB_FOUND 1)
+  MESSAGE(STATUS "Found Matlab arch ${MATLAB_MEX_SUFFIX} at ${MATLAB_INCLUDE_DIR}")
+ELSE(MATLAB_INCLUDE_DIR AND MATLAB_LIBRARIES)
+  MESSAGE(STATUS "Matlab not found")
+ENDIF(MATLAB_INCLUDE_DIR AND MATLAB_LIBRARIES)
 
 MARK_AS_ADVANCED(
+  MATLAB_LIBRARIES
   MATLAB_MEX_LIBRARY
   MATLAB_MX_LIBRARY
   MATLAB_ENG_LIBRARY
   MATLAB_INCLUDE_DIR
-  MATLAB_ROOT
+  MATLAB_MEX_SUFFIX
+  MATLAB_MEX_VERSIONFILE
+  MATLAB_FOUND
 )
 
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(Matlab 
-    MATLAB_INCLUDE_DIR 
-    MATLAB_MEX_LIBRARY 
-    MATLAB_MAT_LIBRARY
-    MATLAB_ENG_LIBRARY
-    MATLAB_MX_LIBRARY )
-
+# vim: set ts=2 sw=2 et:
Index: library/system/SetBdmEnv.cmake
===================================================================
--- library/system/SetBdmEnv.cmake (revision 406)
+++ library/system/SetBdmEnv.cmake (revision 406)
@@ -0,0 +1,108 @@
+# This Module Sets CMake variables for BDM
+# Variable BDM_SOURCE_DIR must be set
+#
+# Other respected variables are
+# ITPP_DIR, ACML_DIR, MATLAB_ROOT
+#
+
+IF(NOT BDM_SOURCE_DIR)
+      MESSAGE(FATAL_ERROR "BDM_SOURCE_DIR is not set!")
+ENDIF(NOT BDM_SOURCE_DIR)
+
+######################
+#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
+	IF(NOT ITPP_DIR)
+		SET(ITPP_DIR "${BDM_SOURCE_DIR}\\system\\win32\\itpp-4.0.6")
+	ENDIF(NOT ITPP_DIR)
+	IF(NOT ACML_DIR)
+		SET(ACML_DIR "${BDM_SOURCE_DIR}\\system\\win32\\acml3.6.0")
+	ENDIF(NOT ACML_DIR)
+	
+	INCLUDE(\\system\\win32\\local_paths.txt OPTIONAL)	
+	ADD_DEFINITIONS(-DHAVE_ACML)
+ENDIF(WIN32)
+IF(APPLE)
+	IF(NOT ITPP_DIR)
+		SET(ITPP_DIR "${BDM_SOURCE_DIR}/macosx/itpp-4.0.6")
+	ENDIF(NOT ITPP_DIR)
+	FIND_LIBRARY(FRAMEWORK_VECLIB vecLib)
+	ADD_DEFINITIONS(-DHAVE_XLOCALE_H)
+ENDIF(APPLE)
+IF(UNIX)
+	# Generally this directory should not exist!
+	# Use this location is you compile itpp from sources
+	IF(NOT ITPP_DIR)
+		SET(ITPP_DIR "${BDM_SOURCE_DIR}/system/linux/")
+	ENDIF(NOT ITPP_DIR)
+	#This is for UNIX makefile which does only one release at a time.
+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)
+
+IF(UNIX)
+	SET(CMAKE_BUILD_TYPE Debug)
+	IF(MATLAB_FOUND)
+		SET(CMAKE_CXX_FLAGS "-Wall -pipe  -Wno-unknown-pragmas -fPIC")
+		SET(CMAKE_C_FLAGS "-Wall -pipe  -Wno-unknown-pragmas -fPIC")
+	ELSE(MATLAB_FOUND)
+		SET(CMAKE_CXX_FLAGS "-Wall -Wno-unknown-pragmas ")
+		SET(CMAKE_C_FLAGS "-Wall -Wno-unknown-pragmas ")
+	ENDIF(MATLAB_FOUND)
+	
+	SET(CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG -O2")
+	SET(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
+ENDIF(UNIX)
+
+##
+## 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)
+	
+MACRO(MEX FN)
+	INCLUDE_DIRECTORIES(${MATLAB_INCLUDE_DIR} "${BDM_SOURCE_DIR}/bdm")
+	LINK_DIRECTORIES("${BDM_SOURCE_DIR}/bdm")
+	ADD_LIBRARY(${FN} MODULE ${FN}.cpp)
+	set_target_properties(${FN} PROPERTIES
+		PREFIX ""
+		SUFFIX  ${MATLAB_MEX_SUFFIX}
+	)
+	TARGET_LINK_LIBRARIES(${FN} ${MATLAB_LIBRARIES} bdm itpp)
+ENDMACRO(MEX)
Index: library/system/FindITPP.cmake
===================================================================
--- library/system/FindITPP.cmake (revision 362)
+++ library/system/FindITPP.cmake (revision 406)
@@ -44,5 +44,5 @@
 ELSE (ITPP_FOUND)
    IF (ITPP_FIND_REQUIRED)
-      MESSAGE(FATAL_ERROR "Could not find ITPP library")
+      MESSAGE(FATAL_ERROR "Could not find ITPP library, make sure ITPP_DIR is properly set")
    ENDIF (ITPP_FIND_REQUIRED)
 ENDIF (ITPP_FOUND)
