Skip to content

Commit

Permalink
Use FindMatlab in drake_setup_matlab
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Oct 21, 2016
1 parent f46833b commit c716c67
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ drake_add_external(nlopt PUBLIC CMAKE

# sedumi
drake_add_external(sedumi CMAKE
CMAKE_ARGS -DMatlab_ROOT_DIR=${MATLAB_ROOT_DIR})
CMAKE_ARGS -DMatlab_ROOT_DIR=${Matlab_ROOT_DIR})

# snopt
if(MATLAB_EXECUTABLE)
if(Matlab_FOUND)
set(SNOPT_EXTRA_CMAKE_ARGS
-DBUILD_SNOPT_C_MEX=ON
-DMatlab_ROOT_DIR=${MATLAB_ROOT_DIR})
-DMatlab_ROOT_DIR=${Matlab_ROOT_DIR})
else()
set(SNOPT_EXTRA_CMAKE_ARGS
-DBUILD_SNOPT_C_MEX=OFF)
Expand All @@ -154,7 +154,7 @@ drake_add_external(snopt CMAKE

# spotless
drake_add_external(spotless PUBLIC CMAKE
CMAKE_ARGS -DMatlab_ROOT_DIR=${MATLAB_ROOT_DIR})
CMAKE_ARGS -DMatlab_ROOT_DIR=${Matlab_ROOT_DIR})

# octomap
drake_add_external(octomap PUBLIC CMAKE
Expand Down Expand Up @@ -185,10 +185,10 @@ drake_add_external(swig_matlab PUBLIC
${MAKE_COMMAND} install)

# textbook
if(MATLAB_EXECUTABLE)
if(Matlab_FOUND)
set(TEXTBOOK_CMAKE_ARGS
-DBUILD_TESTING=ON
-DMatlab_ROOT_DIR=${MATLAB_ROOT_DIR})
-DMatlab_ROOT_DIR=${Matlab_ROOT_DIR})
else()
set(TEXTBOOK_CMAKE_ARGS -DBUILD_TESTING=OFF)
endif()
Expand All @@ -214,7 +214,7 @@ drake_add_external(iris PUBLIC CMAKE
-DIRIS_WITH_CDD=ON
-DIRIS_WITH_EIGEN=OFF
-DIRIS_WITH_MOSEK=OFF
-DMatlab_ROOT_DIR=${MATLAB_ROOT_DIR}
-DMatlab_ROOT_DIR=${Matlab_ROOT_DIR}
DEPENDS eigen mosek)


Expand Down
22 changes: 14 additions & 8 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,29 @@ function(drake_setup_matlab)

if(DISABLE_MATLAB)
message(STATUS "MATLAB is disabled.")
unset(MATLAB_EXECUTABLE CACHE) # TODO unset MATLAB_FOUND instead (see below)
unset(MATLAB_EXECUTABLE CACHE)
unset(Matlab_FOUND CACHE)
else()
# Look for the MATLAB executable. This does not use find_package(Matlab)
# because that is "really good at finding MATLAB", and we only want to
# enable matlab support if the matlab executable is in the user's PATH.
find_program(MATLAB_EXECUTABLE matlab)
if(MATLAB_EXECUTABLE)
message(STATUS "Found MATLAB: ${MATLAB_EXECUTABLE}")

# Determine the MATLAB root.
get_filename_component(_matlab_realpath "${MATLAB_EXECUTABLE}" REALPATH)
get_filename_component(_matlab_bindir "${_matlab_realpath}" DIRECTORY)
get_filename_component(MATLAB_ROOT_DIR
get_filename_component(Matlab_ROOT_DIR
"${_matlab_bindir}" DIRECTORY CACHE)

# TODO find_package(Matlab) and delete mex_setup
# TODO change MATLAB_EXECUTABLE in options.cmake to MATLAB_FOUND
if(MATLAB_EXECUTABLE)
# MATLAB 7.12 (R2011a) introduced the rng() function
find_package(Matlab 7.12 MODULE
COMPONENTS
MAIN_PROGRAM
MEX_COMPILER
MX_LIBRARY
SIMULINK)
endif()
else()
message(STATUS "MATLAB was not found.")
endif()
Expand All @@ -69,7 +75,7 @@ function(drake_setup_java_for_matlab)

# Ask matlab for its JVM version
execute_process(
COMMAND "${MATLAB_EXECUTABLE}" ${_args} -logfile "${_logfile}" -r "version -java,quit"
COMMAND "${Matlab_MAIN_PROGRAM}" ${_args} -logfile "${_logfile}" -r "version -java,quit"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
TIMEOUT 450
RESULT_VARIABLE _result
Expand Down Expand Up @@ -149,7 +155,7 @@ macro(drake_setup_java)
# If matlab is in use, try to determine its JVM version, as we need to build
# all externals to the same version (on success, this will set the Java
# compile flags)
if(MATLAB_EXECUTABLE AND NOT DISABLE_MATLAB)
if(Matlab_FOUND AND NOT DISABLE_MATLAB)
drake_setup_java_for_matlab()
else()
unset(CMAKE_JAVA_COMPILE_FLAGS CACHE)
Expand Down
10 changes: 5 additions & 5 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ macro(drake_setup_options)
# compatibility issues:
# https://github.com/RobotLocomotion/drake/issues/2578
drake_optional_external(IPOPT ON
DEPENDS "NOT APPLE OR NOT MATLAB_EXECUTABLE"
DEPENDS "NOT APPLE OR NOT Matlab_FOUND"
"Interior Point Optimizer, for solving non-linear optimizations")

drake_optional_external(OCTOMAP ON
Expand All @@ -250,22 +250,22 @@ macro(drake_setup_options)
# The following projects are default ON when MATLAB is present and enabled.
# Otherwise, they are hidden and default OFF.
drake_optional_external(SPOTLESS ON
DEPENDS "NOT DISABLE_MATLAB\;MATLAB_EXECUTABLE"
DEPENDS "NOT DISABLE_MATLAB\;Matlab_FOUND"
"polynomial optimization front-end for MATLAB")

# The following projects are default OFF when MATLAB is present and enabled.
# Otherwise, they are hidden and default OFF. Some of them may also be hidden
# on Windows regardless of the status of MATLAB.
drake_optional_external(IRIS OFF
DEPENDS "NOT DISABLE_MATLAB\;MATLAB_EXECUTABLE\;NOT WIN32\;WITH_MOSEK"
DEPENDS "NOT DISABLE_MATLAB\;Matlab_FOUND\;WITH_MOSEK"
"fast approximate convex segmentation")

drake_optional_external(SEDUMI OFF
DEPENDS "NOT DISABLE_MATLAB\;MATLAB_EXECUTABLE\;NOT WIN32"
DEPENDS "NOT DISABLE_MATLAB\;Matlab_FOUND"
"semi-definite programming solver")

drake_optional_external(YALMIP OFF
DEPENDS "NOT DISABLE_MATLAB\;MATLAB_EXECUTABLE\;NOT WIN32"
DEPENDS "NOT DISABLE_MATLAB\;Matlab_FOUND"
"free optimization front-end for MATLAB")

# END external projects that are only needed when MATLAB is in use
Expand Down
17 changes: 4 additions & 13 deletions drake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,10 @@ endif()

# set up matlab build
include(../cmake/mex.cmake)
if(MATLAB_EXECUTABLE) # Set by drake_setup_platform
if(DISABLE_MATLAB)
message(STATUS "MATLAB is disabled because the CMake option DISABLE_MATLAB is set to ON.")
else()
# Use find_package to find "all of matlab" along with what is needed to use
# matlab_add_unit_test and matlab_add_mex
find_package(Matlab MODULE REQUIRED
COMPONENTS
MAIN_PROGRAM
MEX_COMPILER
MX_LIBRARY
SIMULINK)
endif()
if(DISABLE_MATLAB AND Matlab_FOUND) # Set by drake_setup_platform
message(STATUS "MATLAB is disabled because the CMake option DISABLE_MATLAB is set to ON.")
unset(MATLAB_EXECUTABLE CACHE)
unset(Matlab_FOUND CACHE)
endif()

enable_testing()
Expand Down

0 comments on commit c716c67

Please sign in to comment.