FindMatlab: fix reconfiguration of Matlab_ROOT_DIR

This commit is contained in:
Raffi Enficiaud 2015-05-29 17:44:19 +02:00 committed by Brad King
parent 5752e55805
commit 8444809c47
5 changed files with 62 additions and 2 deletions

View File

@ -134,7 +134,8 @@
# returns the suffix to be used for the mex files
# (platform/architecture dependant)
# :command:`matlab_get_version_from_matlab_run`
# returns the version of Matlab, given the full directory of the Matlab program.
# returns the version of Matlab, given the full directory of the Matlab
# program.
#
#
# Known issues
@ -1064,7 +1065,7 @@ if(Matlab_ROOT_DIR)
endif()
else()
# NOTFOUND indicates the code below to search for the version automatically
if(NOT DEFINED Matlab_VERSION_STRING_INTERNAL)
if("${Matlab_VERSION_STRING_INTERNAL}" STREQUAL "")
list(APPEND _matlab_possible_roots "NOTFOUND" ${Matlab_ROOT_DIR}) # empty version
else()
list(APPEND _matlab_possible_roots ${Matlab_VERSION_STRING_INTERNAL} ${Matlab_ROOT_DIR}) # cached version

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
.*

View File

@ -0,0 +1,9 @@
cmake_minimum_required (VERSION 2.8.12)
enable_testing()
project(findmatlab_runcmake_test2)
if(NOT DEFINED matlab_required)
set(matlab_required REQUIRED)
endif()
find_package(Matlab ${matlab_required} COMPONENTS MX_LIBRARY)

View File

@ -1,3 +1,51 @@
include(RunCMake)
run_cmake(MatlabTest1)
if(RunCMake_GENERATOR MATCHES "Make" AND UNIX)
# Use a single build tree for a few tests without cleaning.
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/RerunFindMatlab-build-init)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
message(STATUS "RerunFindMatlab: first configuration to extract real Matlab_ROOT_DIR")
set(RunCMake_TEST_OPTIONS "-Dmatlab_required=REQUIRED")
run_cmake(MatlabTest2)
message(STATUS "RerunFindMatlab: flushing the variables")
execute_process(COMMAND
${CMAKE_COMMAND} -L ${RunCMake_TEST_BINARY_DIR}
RESULT_VARIABLE _MatlabTest2_error
OUTPUT_VARIABLE _MatlabTest2_output)
if(NOT _MatlabTest2_error EQUAL 0)
message(FATAL_ERROR "RerunFindMatlab: cannot list the variables ...")
endif()
string(REGEX MATCH "Matlab_ROOT_DIR.+=([^\r\n]+)" _matched ${_MatlabTest2_output})
set(Matlab_ROOT_DIR_correct "${CMAKE_MATCH_1}")
if(Matlab_ROOT_DIR_correct STREQUAL "")
message(FATAL_ERROR "RerunFindMatlab: cannot extract Matlab_ROOT_DIR")
endif()
message(STATUS "RerunFindMatlab: detected correct Matlab_ROOT_DIR=${Matlab_ROOT_DIR_correct}")
message(STATUS "RerunFindMatlab: change configuration, incorrect Matlab_ROOT_DIR setting")
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/RerunFindMatlab-build-second)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
set(RunCMake_TEST_OPTIONS "-DMatlab_ROOT_DIR=/" "-Dmatlab_required=")
run_cmake(MatlabTest2)
message(STATUS "RerunFindMatlab: fixing configuration with correct Matlab_ROOT_DIR setting")
set(RunCMake_TEST_OPTIONS "-DMatlab_ROOT_DIR=${Matlab_ROOT_DIR_correct}") # required this time?
run_cmake(MatlabTest2)
# no target on this test
run_cmake_command(MatlabTest2 ${CMAKE_COMMAND} --build .)
unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN)
endif()