File: RunCMakeTest.cmake

package info (click to toggle)
cmake 4.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 152,344 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (60 lines) | stat: -rw-r--r-- 2,428 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
include(RunCMake)

if(NOT "${MCR_ROOT}" STREQUAL "")
    if(NOT EXISTS "${MCR_ROOT}")
        message(FATAL_ERROR "MCR does not exist ${MCR_ROOT}")
    endif()
    set(RunCMake_TEST_OPTIONS "-Dmatlab_root=${MCR_ROOT}")
endif()
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")
  if(NOT "${MCR_ROOT}" STREQUAL "")
    set(RunCMake_TEST_OPTIONS ${RunCMake_TEST_OPTIONS} "-Dmatlab_root=${MCR_ROOT}")
  endif()
  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()