Commit 81c20bf0 authored by Jussi Lindgren's avatar Jussi Lindgren

build: Fixed build bug with Linuxes having Matlab

Addresses Mantis #143. As usual, this may not work with
all Matlab versions. Tested Win7 64bit with 32bit Matlab
r2011b, and Linux Mint 13 with 64bit Matlab r2013a.

Additionally, made the build a bit less noisy.
parent 5203d26a
# ---------------------------------
# Finds Matlab toolkit
# ---------------------------------
# Clear cached variables, otherwise repeated builds lead to trouble
SET(Matlab_EXECUTABLE "Matlab_EXECUTABLE-NOTFOUND")
SET(Matlab_INCLUDE "Matlab_INCLUDE-NOTFOUND")
SET(Matlab_ROOT "Matlab_ROOT-NOTFOUND")
# See if we can locate the matlab executable
IF (WIN32)
FIND_PROGRAM(Matlab_EXECUTABLE MATLAB)
ENDIF(WIN32)
IF (UNIX)
FIND_PROGRAM(Matlab_EXECUTABLE matlab)
ENDIF(UNIX)
IF(UNIX OR WIN32)
IF(UNIX AND NOT Matlab_EXECUTABLE)
IF(NOT Matlab_EXECUTABLE)
# Alternative way to try to find matlab
FILE(GLOB_RECURSE Executable_Candidates "/usr/local/matlab*/matlab")
FILE(GLOB_RECURSE Executable_Candidates1 "/usr/local/matlab*/matlab")
FILE(GLOB_RECURSE Executable_Candidates2 "/usr/local/MATLAB*/matlab")
SET(Executable_Candidates ${Executable_Candidates1} ${Executable_Candidates2})
IF(Executable_Candidates)
LIST(GET Executable_Candidates 0 Matlab_EXECUTABLE)
ENDIF(Executable_Candidates)
ENDIF(UNIX AND NOT Matlab_EXECUTABLE)
IF(UNIX AND NOT Matlab_EXECUTABLE)
# Alternative way 2 to try to find matlab
ENDIF(NOT Matlab_EXECUTABLE)
ENDIF(UNIX)
FILE(GLOB_RECURSE Executable_Candidates "/usr/local/MATLAB*/matlab")
IF(Executable_Candidates)
LIST(GET Executable_Candidates 0 Matlab_EXECUTABLE)
ENDIF(Executable_Candidates)
ENDIF(UNIX AND NOT Matlab_EXECUTABLE)
IF(Matlab_EXECUTABLE)
GET_FILENAME_COMPONENT(Matlab_ROOT ${Matlab_EXECUTABLE} PATH)
SET(Matlab_ROOT ${Matlab_ROOT}/..)
# Figure out the paths to libs and includes
IF(Matlab_EXECUTABLE)
# Try relative to the executable path
GET_FILENAME_COMPONENT(Matlab_ROOT ${Matlab_EXECUTABLE} PATH)
FIND_PATH(Matlab_INCLUDE "mex.h" PATHS ${Matlab_ROOT}/../extern/include ${Matlab_ROOT}/../extern/include/extern)
# matlab executable path might have been pointing to a symbolic link elsewhere, try something else
IF((NOT Matlab_INCLUDE) AND UNIX)
EXECUTE_PROCESS(COMMAND matlab -e COMMAND grep "^MATLAB=" COMMAND sed "s/^MATLAB=//g" COMMAND tr "\n" "/"
OUTPUT_VARIABLE Matlab_ROOT)
FIND_PATH(Matlab_INCLUDE "mex.h" PATHS ${Matlab_ROOT}/extern/include ${Matlab_ROOT}/extern/include/extern)
IF(Matlab_INCLUDE)
IF(UNIX)
SET(Matlab_LIBRARIES mex mx eng)
IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
SET(Matlab_LIB_DIRECTORIES ${Matlab_ROOT}/bin/glnx86)
ELSE(CMAKE_SIZEOF_VOID_P EQUAL 4)
SET(Matlab_LIB_DIRECTORIES ${Matlab_ROOT}/bin/glnxa64)
ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)
ENDIF(UNIX)
IF(WIN32)
SET(Matlab_LIBRARIES libmex libmx libeng) #mclmcrrt
SET(Matlab_LIB_DIRECTORIES ${Matlab_ROOT}/extern/lib/win32/microsoft)
# for delayed importation on windows
TARGET_LINK_LIBRARIES(${PROJECT_NAME} Delayimp )
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/DELAYLOAD:libeng.dll /DELAYLOAD:libmx.dll")
# /DELAYLOAD:libmex.dll /DELAYLOAD:mclmcrrt.dll --> useless, no import
ENDIF(WIN32)
SET(Matlab_FOUND TRUE)
ELSE(Matlab_INCLUDE)
ENDIF(Matlab_INCLUDE)
ENDIF(Matlab_EXECUTABLE)
ENDIF(UNIX OR WIN32)
ENDIF((NOT Matlab_INCLUDE) AND UNIX)
IF(Matlab_INCLUDE)
IF(UNIX)
SET(Matlab_LIBRARIES mex mx eng)
IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
SET(Matlab_LIB_DIRECTORIES ${Matlab_ROOT}/bin/glnx86)
ELSE(CMAKE_SIZEOF_VOID_P EQUAL 4)
SET(Matlab_LIB_DIRECTORIES ${Matlab_ROOT}/bin/glnxa64)
ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)
ENDIF(UNIX)
IF(WIN32)
SET(Matlab_LIBRARIES libmex libmx libeng) #mclmcrrt
SET(Matlab_LIB_DIRECTORIES ${Matlab_ROOT}/../extern/lib/win32/microsoft)
# for delayed importation on windows
TARGET_LINK_LIBRARIES(${PROJECT_NAME} Delayimp )
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/DELAYLOAD:libeng.dll /DELAYLOAD:libmx.dll")
# /DELAYLOAD:libmex.dll /DELAYLOAD:mclmcrrt.dll --> useless, no import
ENDIF(WIN32)
SET(Matlab_FOUND TRUE)
ENDIF(Matlab_INCLUDE)
ENDIF(Matlab_EXECUTABLE)
IF(Matlab_FOUND)
MESSAGE(STATUS " Found Matlab [${Matlab_EXECUTABLE}]")
MESSAGE(STATUS " Found Matlab in [${Matlab_ROOT}]")
SET(Matlab_LIB_FOUND TRUE)
INCLUDE_DIRECTORIES(${Matlab_INCLUDE})
FOREACH(Matlab_LIB ${Matlab_LIBRARIES})
SET(Matlab_LIB1 "Matlab_LIB1-NOTFOUND")
FIND_LIBRARY(Matlab_LIB1 NAMES ${Matlab_LIB} PATHS ${Matlab_LIB_DIRECTORIES} NO_DEFAULT_PATH)
......@@ -81,3 +87,4 @@ IF(Matlab_FOUND)
ELSE(Matlab_FOUND)
MESSAGE(STATUS " FAILED to find Matlab...")
ENDIF(Matlab_FOUND)
# Adds the current project to the global properties
FUNCTION(OV_ADD_THIS_TO_PROJECT_LIST)
MESSAGE(STATUS "ADDING: ${CMAKE_CURRENT_SOURCE_DIR}")
# MESSAGE(STATUS "ADDING: ${CMAKE_CURRENT_SOURCE_DIR}")
# Add the dir to be parsed for documentation later. We need to do this before adding subdir, in case the subdir is the actual docs dir
GET_PROPERTY(OV_TMP GLOBAL PROPERTY OV_PROP_CURRENT_PROJECTS)
......
......@@ -6,6 +6,15 @@
#export OV_PATH_LIB="$OV_PATH_ROOT/lib"
#export OV_PATH_DATA="$OV_PATH_ROOT/share/openvibe"
# Tries to locate matlab executable from $PATH, and set the library path to the corresponding matlab libs.
if [ "`which matlab`" != "" ] ; then
MATLAB_ROOT=`matlab -e | grep "^MATLAB=" | sed -e "s/^MATLAB=//"`
MATLAB_ARCH=`matlab -e | grep "^ARCH=" | sed -e "s/^ARCH=//"`
MATLAB_LIBPATH="$MATLAB_ROOT/bin/$MATLAB_ARCH"
# echo Matlab libs expected at $MATLAB_LIBPATH
export LD_LIBRARY_PATH="$MATLAB_LIBPATH:$LD_LIBRARY_PATH"
fi
LOCAL_BIN_PATH="@CMAKE_INSTALL_FULL_BINDIR@"
if [ "$OV_PATH_BIN" != "" ]; then
LOCAL_BIN_PATH="$OV_PATH_BIN"
......
......@@ -13,9 +13,9 @@ FUNCTION(OV_ADD_CONTRIB_DRIVER DRIVER_PATH)
FILE(GLOB_RECURSE additional_source_files ${ADDITIONAL_PATH}/src/*.cpp ${ADDITIONAL_PATH}/src/*.h)
SET(source_files "${source_files};${additional_source_files}" PARENT_SCOPE)
MESSAGE(STATUS "DO I EXIST: ${ADDITIONAL_PATH}/share/")
#MESSAGE(STATUS "DO I EXIST: ${ADDITIONAL_PATH}/share/")
IF(EXISTS "${ADDITIONAL_PATH}/share/")
MESSAGE(STATUS "I EXIST: ${ADDITIONAL_PATH}/share/")
#MESSAGE(STATUS "I EXIST: ${ADDITIONAL_PATH}/share/")
INSTALL(DIRECTORY "${ADDITIONAL_PATH}/share/" DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/openvibe/applications/acquisition-server/" PATTERN ".svn" EXCLUDE)
ENDIF(EXISTS "${ADDITIONAL_PATH}/share/")
......
#!/bin/bash
if [ "$MATLABROOT" == "" ]; then
if [ "`which matlab`" != "" ] ; then
export MATLABROOT=`matlab -e | grep "^MATLAB=" | sed "s/^MATLAB=//g"`
export MATLABARCH=`matlab -e | grep "^ARCH=" | sed "s/^ARCH=//g"`
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MATLABROOT/bin/$MATLABARCH
fi
fi
ov_build_type=Release
if [ "$1" == "--debug" ]; then
ov_build_type=Debug
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment