Skip to content

Commit

Permalink
Set Java compile flags globally
Browse files Browse the repository at this point in the history
Move the logic to set the Java compile flags so that Java will target
the matlab JVM version from drake itself to the superbuild, and
propagate Java options to all externals. This should address mismatches
in the targeted Java version between drake itself, and externals such as
LCM.
  • Loading branch information
mwoehlke-kitware committed Jul 11, 2016
1 parent 6a9d144 commit 787840c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 28 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ drake_add_external(drake LOCAL PUBLIC CMAKE ALWAYS
BINARY_DIR ${PROJECT_BINARY_DIR}/drake
${DRAKE_BUILD_COMMANDS}
CMAKE_ARGS
-DJava_JAVA_EXECUTABLE=${Java_JAVA_EXECUTABLE}
-DJava_JAVAC_EXECUTABLE=${Java_JAVAC_EXECUTABLE}
-DJava_JAVAH_EXECUTABLE=${Java_JAVAH_EXECUTABLE}
-DJava_VERSION_STRING=${Java_VERSION_STRING}
-DWITH_PYTHON_3=${WITH_PYTHON_3}
-DDISABLE_MATLAB=${DISABLE_MATLAB}
DEPENDS
Expand Down
5 changes: 5 additions & 0 deletions cmake/DrakeExternals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ macro(drake_add_cmake_external PROJECT)
-DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS}
-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS}
-DCMAKE_STATIC_LINKER_FLAGS:STRING=${CMAKE_STATIC_LINKER_FLAGS}
-DJava_JAVA_EXECUTABLE:FILEPATH=${Java_JAVA_EXECUTABLE}
-DJava_JAVAC_EXECUTABLE:FILEPATH=${Java_JAVAC_EXECUTABLE}
-DJava_JAVAH_EXECUTABLE:FILEPATH=${Java_JAVAH_EXECUTABLE}
-DJava_VERSION_STRING:STRING=${Java_VERSION_STRING}
-DCMAKE_JAVA_COMPILE_FLAGS:STRING=${CMAKE_JAVA_COMPILE_FLAGS}
${_ext_VERBOSE}
${_ext_CMAKE_ARGS})
endmacro()
Expand Down
57 changes: 56 additions & 1 deletion cmake/DrakePlatform.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
#------------------------------------------------------------------------------
function(drake_get_matlab_jvm_version)
# Find matlab
find_program(MATLAB_EXECUTABLE matlab)

if(MATLAB_EXECUTABLE AND NOT MATLAB_JVM_VERSION)
# Set arguments for running matlab
set(_args -nodesktop -nodisplay -nosplash)
if(WIN32)
set(_args ${_args} -wait)
endif()

# Ask matlab for its JVM version
execute_process(
COMMAND ${MATLAB_EXECUTABLE} ${_args} -r "version -java,quit"
RESULT_VARIABLE _result
ERROR_VARIABLE _output
OUTPUT_VARIABLE _output
TIMEOUT 180)

# Test for a valid result
if(NOT _result AND _output MATCHES "Java ([0-9]+\\.[0-9]+)\\.[0-9_.]+")
set(MATLAB_JVM_VERSION ${CMAKE_MATCH_1} CACHE INTERNAL "")
set(_jsdk_version "${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}")

# Compare against JSDK version
if(NOT _matlab_jvm_version VERSION_EQUAL _jsdk_version)
message(WARNING
"MATLAB JVM version (${MATLAB_JVM_VERSION}) does not match "
"installed Java SDK version (${_jsdk_version})")

# If JSDK is newer, set build options to build Java code compatible
# with the matlab JVM
if(MATLAB_JVM_VERSION VERSION_LESS _jsdk_version)
set(CMAKE_JAVA_COMPILE_FLAGS
-source ${MATLAB_JVM_VERSION}
-target ${MATLAB_JVM_VERSION}
CACHE INTERNAL "")
endif()
endif()
else()
message(WARNING "Could not determine MATLAB JVM version")
endif()
endif()
endfunction()

###############################################################################

# Check minimum compiler requirements
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
message(FATAL_ERROR "GCC version must be at least 4.9")
Expand All @@ -16,9 +64,16 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif()
message(STATUS CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})

# Require Java at the super-build level since libbot cannot configure without finding Java
# Require Java at the super-build level since libbot cannot configure without
# finding Java
find_package(Java 1.6 REQUIRED)
include(UseJava)

# If matlab is in use, try to determine its JVM version, as we need to build
# all externals to the same version
if(NOT DISABLE_MATLAB)
drake_get_matlab_jvm_version()
endif()

# Choose your python (major) version
option(WITH_PYTHON_3 "Force Drake to use python 3 instead of python 2" OFF)
23 changes: 0 additions & 23 deletions drake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,6 @@ else()
# along with what is needed to use matlab_add_unit_test
if(MATLAB_FOUND)
find_package(Matlab COMPONENTS MAIN_PROGRAM REQUIRED)

set(Matlab_Java_MAIN_PROGRAM_ARGS -nodesktop -nodisplay -nosplash)
if(WIN32)
set(Matlab_Java_MAIN_PROGRAM_ARGS ${Matlab_Java_MAIN_PROGRAM_ARGS} -wait)
endif()
execute_process(
COMMAND ${Matlab_MAIN_PROGRAM} ${Matlab_Java_MAIN_PROGRAM_ARGS} -r "version -java,quit"
RESULT_VARIABLE Matlab_Java_RESULT_VARIABLE
ERROR_VARIABLE Matlab_Java_OUTPUT_VARIABLE
OUTPUT_VARIABLE Matlab_Java_OUTPUT_VARIABLE
TIMEOUT 180)
if(NOT Matlab_Java_RESULT_VARIABLE AND Matlab_Java_OUTPUT_VARIABLE MATCHES "Java ([0-9]+\\.[0-9]+)\\.[0-9_.]+")
set(Matlab_Java_VERSION_MAJOR_MINOR ${CMAKE_MATCH_1})
set(Java_VERSION_MAJOR_MINOR "${Java_VERSION_MAJOR}.${Java_VERSION_MINOR}")
if(NOT Matlab_Java_VERSION_MAJOR_MINOR VERSION_EQUAL Java_VERSION_MAJOR_MINOR)
message(WARNING "MATLAB JVM version (${Matlab_Java_VERSION_MAJOR_MINOR}) does not match installed Java SDK version (${Java_VERSION_MAJOR_MINOR})")
if(Matlab_Java_VERSION_MAJOR_MINOR VERSION_LESS Java_VERSION_MAJOR_MINOR)
set(CMAKE_JAVA_COMPILE_FLAGS -source ${Matlab_Java_VERSION_MAJOR_MINOR} -target ${Matlab_Java_VERSION_MAJOR_MINOR})
endif()
endif()
else()
message(WARNING "Could not determine MATLAB JVM version")
endif()
endif()
endif()

Expand Down

0 comments on commit 787840c

Please sign in to comment.