123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539 |
- set(_FindMatlab_SELF_DIR "${CMAKE_CURRENT_LIST_DIR}")
- include(FindPackageHandleStandardArgs)
- include(CheckCXXCompilerFlag)
- include(CheckCCompilerFlag)
- if(NOT MATLAB_ADDITIONAL_VERSIONS)
- set(MATLAB_ADDITIONAL_VERSIONS)
- endif()
- set(MATLAB_VERSIONS_MAPPING
- "R2017b=9.3"
- "R2017a=9.2"
- "R2016b=9.1"
- "R2016a=9.0"
- "R2015b=8.6"
- "R2015a=8.5"
- "R2014b=8.4"
- "R2014a=8.3"
- "R2013b=8.2"
- "R2013a=8.1"
- "R2012b=8.0"
- "R2012a=7.14"
- "R2011b=7.13"
- "R2011a=7.12"
- "R2010b=7.11"
- ${MATLAB_ADDITIONAL_VERSIONS}
- )
- set(_matlab_temporary_folder ${CMAKE_BINARY_DIR}/Matlab)
- if(NOT EXISTS "${_matlab_temporary_folder}")
- file(MAKE_DIRECTORY "${_matlab_temporary_folder}")
- endif()
- macro (matlab_get_version_from_release_name release_name version_name)
- string(REGEX MATCHALL "${release_name}=([0-9]+\\.?[0-9]*)" _matched ${MATLAB_VERSIONS_MAPPING})
- set(${version_name} "")
- if(NOT _matched STREQUAL "")
- set(${version_name} ${CMAKE_MATCH_1})
- else()
- message(WARNING "The release name ${release_name} is not registered")
- endif()
- unset(_matched)
- endmacro()
- macro (matlab_get_release_name_from_version version release_name)
- set(${release_name} "")
- foreach(_var IN LISTS MATLAB_VERSIONS_MAPPING)
- string(REGEX MATCHALL "(.+)=${version}" _matched ${_var})
- if(NOT _matched STREQUAL "")
- set(${release_name} ${CMAKE_MATCH_1})
- break()
- endif()
- endforeach(_var)
- unset(_var)
- unset(_matched)
- if(${release_name} STREQUAL "")
- message(WARNING "The version ${version} is not registered")
- endif()
- endmacro()
- macro(matlab_get_supported_releases list_releases)
- set(${list_releases})
- foreach(_var IN LISTS MATLAB_VERSIONS_MAPPING)
- string(REGEX MATCHALL "(.+)=([0-9]+\\.?[0-9]*)" _matched ${_var})
- if(NOT _matched STREQUAL "")
- list(APPEND ${list_releases} ${CMAKE_MATCH_1})
- endif()
- unset(_matched)
- unset(CMAKE_MATCH_1)
- endforeach(_var)
- unset(_var)
- endmacro()
- macro(matlab_get_supported_versions list_versions)
- set(${list_versions})
- foreach(_var IN LISTS MATLAB_VERSIONS_MAPPING)
- string(REGEX MATCHALL "(.+)=([0-9]+\\.?[0-9]*)" _matched ${_var})
- if(NOT _matched STREQUAL "")
- list(APPEND ${list_versions} ${CMAKE_MATCH_2})
- endif()
- unset(_matched)
- unset(CMAKE_MATCH_1)
- endforeach(_var)
- unset(_var)
- endmacro()
- function(matlab_extract_all_installed_versions_from_registry win64 matlab_versions)
- if(NOT CMAKE_HOST_WIN32)
- message(FATAL_ERROR "This macro can only be called by a windows host (call to reg.exe")
- endif()
- if(${win64} AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "64")
- set(APPEND_REG "/reg:64")
- else()
- set(APPEND_REG "/reg:32")
- endif()
-
-
- execute_process(
- COMMAND reg query HKEY_LOCAL_MACHINE\\SOFTWARE\\Mathworks\\MATLAB /f * /k ${APPEND_REG}
- RESULT_VARIABLE resultMatlab
- OUTPUT_VARIABLE varMatlab
- ERROR_VARIABLE errMatlab
- INPUT_FILE NUL
- )
- set(matlabs_from_registry)
- if(${resultMatlab} EQUAL 0)
- string(
- REGEX MATCHALL "MATLAB\\\\([0-9]+(\\.[0-9]+)?)"
- matlab_versions_regex ${varMatlab})
- foreach(match IN LISTS matlab_versions_regex)
- string(
- REGEX MATCH "MATLAB\\\\(([0-9]+)(\\.([0-9]+))?)"
- current_match ${match})
- set(_matlab_current_version ${CMAKE_MATCH_1})
- set(current_matlab_version_major ${CMAKE_MATCH_2})
- set(current_matlab_version_minor ${CMAKE_MATCH_4})
- if(NOT current_matlab_version_minor)
- set(current_matlab_version_minor "0")
- endif()
- list(APPEND matlabs_from_registry ${_matlab_current_version})
- unset(_matlab_current_version)
- endforeach(match)
- endif()
- if(matlabs_from_registry)
- list(REMOVE_DUPLICATES matlabs_from_registry)
- list(SORT matlabs_from_registry)
- list(REVERSE matlabs_from_registry)
- endif()
- set(${matlab_versions} ${matlabs_from_registry} PARENT_SCOPE)
- endfunction()
- macro(extract_matlab_versions_from_registry_brute_force matlab_versions)
-
- set(matlab_supported_versions)
- matlab_get_supported_versions(matlab_supported_versions)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if(matlab_supported_versions)
- list(REMOVE_DUPLICATES matlab_supported_versions)
- list(SORT matlab_supported_versions)
- list(REVERSE matlab_supported_versions)
- endif()
- set(${matlab_versions} ${matlab_supported_versions})
- endmacro()
- function(matlab_get_all_valid_matlab_roots_from_registry matlab_versions matlab_roots)
-
-
-
- set(_matlab_roots_list )
- foreach(_matlab_current_version ${matlab_versions})
- get_filename_component(
- current_MATLAB_ROOT
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\${_matlab_current_version};MATLABROOT]"
- ABSOLUTE)
- if(EXISTS ${current_MATLAB_ROOT})
- list(APPEND _matlab_roots_list ${_matlab_current_version} ${current_MATLAB_ROOT})
- endif()
- endforeach(_matlab_current_version)
- unset(_matlab_current_version)
- set(${matlab_roots} ${_matlab_roots_list} PARENT_SCOPE)
- unset(_matlab_roots_list)
- endfunction()
- function(matlab_get_mex_suffix matlab_root mex_suffix)
-
-
-
- set(mexext_suffix "")
- if(WIN32)
- list(APPEND mexext_suffix ".bat")
- endif()
-
-
- find_program(
- Matlab_MEXEXTENSIONS_PROG
- NAMES mexext
- PATHS ${matlab_root}/bin
- DOC "Matlab MEX extension provider"
- NO_DEFAULT_PATH
- )
- foreach(current_mexext_suffix IN LISTS mexext_suffix)
- if(NOT DEFINED Matlab_MEXEXTENSIONS_PROG OR NOT Matlab_MEXEXTENSIONS_PROG)
-
- find_program(
- Matlab_MEXEXTENSIONS_PROG
- "mexext${current_mexext_suffix}"
- PATHS ${matlab_root}/bin
- DOC "Matlab MEX extension provider"
- NO_DEFAULT_PATH
- )
- endif()
- endforeach(current_mexext_suffix)
-
- if((NOT Matlab_MEXEXTENSIONS_PROG) OR (NOT EXISTS ${Matlab_MEXEXTENSIONS_PROG}))
- if(MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] Cannot found mexext program. Matlab root is ${matlab_root}")
- endif()
- unset(Matlab_MEXEXTENSIONS_PROG CACHE)
- return()
- endif()
- set(_matlab_mex_extension)
- set(devnull)
- if(UNIX)
- set(devnull INPUT_FILE /dev/null)
- elseif(WIN32)
- set(devnull INPUT_FILE NUL)
- endif()
- execute_process(
- COMMAND ${Matlab_MEXEXTENSIONS_PROG}
- OUTPUT_VARIABLE _matlab_mex_extension
- ERROR_VARIABLE _matlab_mex_extension_error
- ${devnull})
- string(STRIP ${_matlab_mex_extension} _matlab_mex_extension)
- unset(Matlab_MEXEXTENSIONS_PROG CACHE)
- set(${mex_suffix} ${_matlab_mex_extension} PARENT_SCOPE)
- endfunction()
- function(matlab_get_version_from_matlab_run matlab_binary_program matlab_list_versions)
- set(${matlab_list_versions} "" PARENT_SCOPE)
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] Determining the version of Matlab from ${matlab_binary_program}")
- endif()
- if(EXISTS "${_matlab_temporary_folder}/matlabVersionLog.cmaketmp")
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] Removing previous ${_matlab_temporary_folder}/matlabVersionLog.cmaketmp file")
- endif()
- file(REMOVE "${_matlab_temporary_folder}/matlabVersionLog.cmaketmp")
- endif()
-
-
-
-
- if(WIN32)
- set(_matlab_additional_commands "-wait")
- endif()
- set(devnull)
- if(UNIX)
- set(devnull INPUT_FILE /dev/null)
- elseif(WIN32)
- set(devnull INPUT_FILE NUL)
- endif()
-
-
-
-
- execute_process(
- COMMAND "${matlab_binary_program}" -nosplash -nojvm ${_matlab_additional_commands} -logfile "matlabVersionLog.cmaketmp" -nodesktop -nodisplay -r "version, exit"
- OUTPUT_VARIABLE _matlab_version_from_cmd_dummy
- RESULT_VARIABLE _matlab_result_version_call
- ERROR_VARIABLE _matlab_result_version_call_error
- TIMEOUT 120
- WORKING_DIRECTORY "${_matlab_temporary_folder}"
- ${devnull}
- )
- if("${_matlab_result_version_call}" MATCHES "timeout")
- if(MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] Unable to determine the version of Matlab."
- " Matlab call timed out after 120 seconds.")
- endif()
- return()
- endif()
- if(${_matlab_result_version_call})
- if(MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] Unable to determine the version of Matlab. Matlab call returned with error ${_matlab_result_version_call}.")
- endif()
- return()
- elseif(NOT EXISTS "${_matlab_temporary_folder}/matlabVersionLog.cmaketmp")
- if(MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] Unable to determine the version of Matlab. The log file does not exist.")
- endif()
- return()
- endif()
-
- file(READ "${_matlab_temporary_folder}/matlabVersionLog.cmaketmp" _matlab_version_from_cmd)
- file(REMOVE "${_matlab_temporary_folder}/matlabVersionLog.cmaketmp")
- set(index -1)
- string(FIND ${_matlab_version_from_cmd} "ans" index)
- if(index EQUAL -1)
- if(MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] Cannot find the version of Matlab returned by the run.")
- endif()
- else()
- set(matlab_list_of_all_versions_tmp)
- string(SUBSTRING ${_matlab_version_from_cmd} ${index} -1 substring_ans)
- string(
- REGEX MATCHALL "ans[\r\n\t ]*=[\r\n\t ]*'?([0-9]+(\\.[0-9]+)?)"
- matlab_versions_regex
- ${substring_ans})
- foreach(match IN LISTS matlab_versions_regex)
- string(
- REGEX MATCH "ans[\r\n\t ]*=[\r\n\t ]*'?(([0-9]+)(\\.([0-9]+))?)"
- current_match ${match})
- list(APPEND matlab_list_of_all_versions_tmp ${CMAKE_MATCH_1})
- endforeach()
- if(matlab_list_of_all_versions_tmp)
- list(REMOVE_DUPLICATES matlab_list_of_all_versions_tmp)
- endif()
- set(${matlab_list_versions} ${matlab_list_of_all_versions_tmp} PARENT_SCOPE)
- endif()
- endfunction()
- function(matlab_add_unit_test)
- if(NOT Matlab_MAIN_PROGRAM)
- message(FATAL_ERROR "[MATLAB] This functionality needs the MAIN_PROGRAM component (not default)")
- endif()
- set(options NO_UNITTEST_FRAMEWORK)
- set(oneValueArgs NAME UNITTEST_FILE TIMEOUT WORKING_DIRECTORY
- UNITTEST_PRECOMMAND CUSTOM_TEST_COMMAND)
- set(multiValueArgs ADDITIONAL_PATH MATLAB_ADDITIONAL_STARTUP_OPTIONS TEST_ARGS)
- set(prefix _matlab_unittest_prefix)
- cmake_parse_arguments(PARSE_ARGV 0 ${prefix} "${options}" "${oneValueArgs}" "${multiValueArgs}" )
- if(NOT ${prefix}_NAME)
- message(FATAL_ERROR "[MATLAB] The Matlab test name cannot be empty")
- endif()
- add_test(NAME ${${prefix}_NAME}
- COMMAND ${CMAKE_COMMAND}
- "-Dtest_name=${${prefix}_NAME}"
- "-Dadditional_paths=${${prefix}_ADDITIONAL_PATH}"
- "-Dtest_timeout=${${prefix}_TIMEOUT}"
- "-Doutput_directory=${_matlab_temporary_folder}"
- "-Dworking_directory=${${prefix}_WORKING_DIRECTORY}"
- "-DMatlab_PROGRAM=${Matlab_MAIN_PROGRAM}"
- "-Dno_unittest_framework=${${prefix}_NO_UNITTEST_FRAMEWORK}"
- "-DMatlab_ADDITIONAL_STARTUP_OPTIONS=${${prefix}_MATLAB_ADDITIONAL_STARTUP_OPTIONS}"
- "-Dunittest_file_to_run=${${prefix}_UNITTEST_FILE}"
- "-Dcustom_Matlab_test_command=${${prefix}_CUSTOM_TEST_COMMAND}"
- "-Dcmd_to_run_before_test=${${prefix}_UNITTEST_PRECOMMAND}"
- -P ${_FindMatlab_SELF_DIR}/MatlabTestsRedirect.cmake
- ${${prefix}_TEST_ARGS}
- ${${prefix}_UNPARSED_ARGUMENTS}
- )
- endfunction()
- function(matlab_add_mex)
- if(NOT WIN32)
-
-
- if(CMAKE_CXX_COMPILER_LOADED)
- check_cxx_compiler_flag(-pthread HAS_MINUS_PTHREAD)
- elseif(CMAKE_C_COMPILER_LOADED)
- check_c_compiler_flag(-pthread HAS_MINUS_PTHREAD)
- endif()
-
-
-
- endif()
- set(options EXECUTABLE MODULE SHARED)
- set(oneValueArgs NAME DOCUMENTATION OUTPUT_NAME)
- set(multiValueArgs LINK_TO SRC)
- set(prefix _matlab_addmex_prefix)
- cmake_parse_arguments(${prefix} "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
- if(NOT ${prefix}_NAME)
- message(FATAL_ERROR "[MATLAB] The MEX target name cannot be empty")
- endif()
- if(NOT ${prefix}_OUTPUT_NAME)
- set(${prefix}_OUTPUT_NAME ${${prefix}_NAME})
- endif()
- if(${prefix}_EXECUTABLE)
- add_executable(${${prefix}_NAME}
- ${${prefix}_SRC}
- ${${prefix}_DOCUMENTATION}
- ${${prefix}_UNPARSED_ARGUMENTS})
- else()
- if(${prefix}_MODULE)
- set(type MODULE)
- else()
- set(type SHARED)
- endif()
- add_library(${${prefix}_NAME}
- ${type}
- ${${prefix}_SRC}
- ${${prefix}_DOCUMENTATION}
- ${${prefix}_UNPARSED_ARGUMENTS})
- endif()
- target_include_directories(${${prefix}_NAME} PRIVATE ${Matlab_INCLUDE_DIRS})
- if(DEFINED Matlab_MX_LIBRARY)
- target_link_libraries(${${prefix}_NAME} ${Matlab_MX_LIBRARY})
- endif()
- target_link_libraries(${${prefix}_NAME} ${Matlab_MEX_LIBRARY} ${${prefix}_LINK_TO})
- set_target_properties(${${prefix}_NAME}
- PROPERTIES
- PREFIX ""
- OUTPUT_NAME ${${prefix}_OUTPUT_NAME}
- SUFFIX ".${Matlab_MEX_EXTENSION}")
-
- if(NOT ${${prefix}_DOCUMENTATION} STREQUAL "")
- get_target_property(output_name ${${prefix}_NAME} OUTPUT_NAME)
- add_custom_command(
- TARGET ${${prefix}_NAME}
- PRE_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy_if_different ${${prefix}_DOCUMENTATION} $<TARGET_FILE_DIR:${${prefix}_NAME}>/${output_name}.m
- COMMENT "Copy ${${prefix}_NAME} documentation file into the output folder"
- )
- endif()
-
- if(WIN32)
- set_target_properties(${${prefix}_NAME}
- PROPERTIES
- DEFINE_SYMBOL "DLL_EXPORT_SYM=__declspec(dllexport)")
- else()
- if(HAS_MINUS_PTHREAD AND NOT APPLE)
-
-
- target_compile_options(${${prefix}_NAME} PRIVATE "-pthread")
- endif()
-
-
-
-
-
-
-
-
-
-
-
- set_target_properties(${${prefix}_NAME}
- PROPERTIES
- CXX_VISIBILITY_PRESET "hidden"
- C_VISIBILITY_PRESET "hidden"
- VISIBILITY_INLINES_HIDDEN ON
- )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- set_target_properties(${${prefix}_NAME}
- PROPERTIES
- DEFINE_SYMBOL "DLL_EXPORT_SYM=__attribute__ ((visibility (\"default\")))"
- )
- endif()
- endfunction()
- function(_Matlab_get_version_from_root matlab_root matlab_known_version matlab_final_version)
-
-
-
-
-
- if(NOT ${matlab_known_version} STREQUAL "NOTFOUND")
-
- set(${matlab_final_version} ${matlab_known_version} PARENT_SCOPE)
- set(Matlab_VERSION_STRING_INTERNAL ${matlab_known_version} CACHE INTERNAL "Matlab version (automatically determined)" FORCE)
- return()
- endif()
-
- set(_matlab_current_program ${Matlab_MAIN_PROGRAM})
-
- if(NOT _matlab_current_program)
- set(_find_matlab_options)
- if(matlab_root AND EXISTS ${matlab_root})
- set(_find_matlab_options PATHS ${matlab_root} ${matlab_root}/bin NO_DEFAULT_PATH)
- endif()
- find_program(
- _matlab_current_program
- matlab
- ${_find_matlab_options}
- DOC "Matlab main program"
- )
- endif()
- if(NOT _matlab_current_program OR NOT EXISTS ${_matlab_current_program})
-
- if(MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] Cannot find the main matlab program under ${matlab_root}")
- endif()
- set(Matlab_PROG_VERSION_STRING_AUTO_DETECT "" CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
- set(Matlab_VERSION_STRING_INTERNAL "" CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
- unset(_matlab_current_program)
- unset(_matlab_current_program CACHE)
- return()
- endif()
-
- get_filename_component(_matlab_main_real_path_tmp "${_matlab_current_program}" REALPATH)
- unset(_matlab_current_program)
- unset(_matlab_current_program CACHE)
-
- if(_matlab_main_real_path_tmp STREQUAL Matlab_PROG_VERSION_STRING_AUTO_DETECT)
- set(${matlab_final_version} ${Matlab_VERSION_STRING_INTERNAL} PARENT_SCOPE)
- return()
- endif()
-
- set(Matlab_PROG_VERSION_STRING_AUTO_DETECT ${_matlab_main_real_path_tmp} CACHE INTERNAL "internal matlab location for the discovered version" FORCE)
- set(matlab_list_of_all_versions)
- matlab_get_version_from_matlab_run("${Matlab_PROG_VERSION_STRING_AUTO_DETECT}" matlab_list_of_all_versions)
- list(LENGTH matlab_list_of_all_versions list_of_all_versions_length)
- if(${list_of_all_versions_length} GREATER 0)
- list(GET matlab_list_of_all_versions 0 _matlab_version_tmp)
- else()
- set(_matlab_version_tmp "unknown")
- endif()
-
- set(Matlab_VERSION_STRING_INTERNAL ${_matlab_version_tmp} CACHE INTERNAL "Matlab version (automatically determined)" FORCE)
-
- if((${list_of_all_versions_length} GREATER 1) AND MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] Found several versions, taking the first one (versions found ${matlab_list_of_all_versions})")
- endif()
-
- set(${matlab_final_version} ${Matlab_VERSION_STRING_INTERNAL} PARENT_SCOPE)
- endfunction()
- set(_matlab_possible_roots)
- if(Matlab_ROOT_DIR)
-
- if(NOT EXISTS ${Matlab_ROOT_DIR})
-
- if(MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] the specified path for Matlab_ROOT_DIR does not exist (${Matlab_ROOT_DIR})")
- endif()
- else()
-
- if("${Matlab_VERSION_STRING_INTERNAL}" STREQUAL "")
- list(APPEND _matlab_possible_roots "NOTFOUND" ${Matlab_ROOT_DIR})
- else()
- list(APPEND _matlab_possible_roots ${Matlab_VERSION_STRING_INTERNAL} ${Matlab_ROOT_DIR})
- endif()
- endif()
- else()
-
-
- if(WIN32)
-
-
-
-
- set(_matlab_versions_from_registry)
- if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- set(_matlab_win64 ON)
- else()
- set(_matlab_win64 OFF)
- endif()
- matlab_extract_all_installed_versions_from_registry(_matlab_win64 _matlab_versions_from_registry)
-
- if(NOT _matlab_versions_from_registry)
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] Search for Matlab from the registry unsuccessful, testing all supported versions")
- endif()
- extract_matlab_versions_from_registry_brute_force(_matlab_versions_from_registry)
- endif()
-
- matlab_get_all_valid_matlab_roots_from_registry("${_matlab_versions_from_registry}" _matlab_possible_roots)
- unset(_matlab_versions_from_registry)
- elseif(APPLE)
-
-
-
- matlab_get_supported_releases(_matlab_releases)
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] Matlab supported versions ${_matlab_releases}. If more version should be supported "
- "the variable MATLAB_ADDITIONAL_VERSIONS can be set according to the documentation")
- endif()
- foreach(_matlab_current_release IN LISTS _matlab_releases)
- set(_matlab_full_string "/Applications/MATLAB_${_matlab_current_release}.app")
- if(EXISTS ${_matlab_full_string})
- set(_matlab_current_version)
- matlab_get_version_from_release_name("${_matlab_current_release}" _matlab_current_version)
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] Found version ${_matlab_current_release} (${_matlab_current_version}) in ${_matlab_full_string}")
- endif()
- list(APPEND _matlab_possible_roots ${_matlab_current_version} ${_matlab_full_string})
- unset(_matlab_current_version)
- endif()
- unset(_matlab_full_string)
- endforeach(_matlab_current_release)
- unset(_matlab_current_release)
- unset(_matlab_releases)
- endif()
- endif()
- list(LENGTH _matlab_possible_roots _numbers_of_matlab_roots)
- if(_numbers_of_matlab_roots EQUAL 0)
-
-
-
- find_program(
- _matlab_main_tmp
- NAMES matlab)
- if(_matlab_main_tmp)
-
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] matlab found from PATH: ${_matlab_main_tmp}")
- endif()
-
- get_filename_component(_matlab_current_location "${_matlab_main_tmp}" REALPATH)
-
-
- get_filename_component(_matlab_current_location "${_matlab_current_location}" DIRECTORY)
- get_filename_component(_matlab_current_location "${_matlab_current_location}" DIRECTORY)
- list(APPEND _matlab_possible_roots "NOTFOUND" ${_matlab_current_location})
- unset(_matlab_current_location)
- endif()
- unset(_matlab_main_tmp CACHE)
- endif()
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] Matlab root folders are ${_matlab_possible_roots}")
- endif()
- list(LENGTH _matlab_possible_roots _numbers_of_matlab_roots)
- set(Matlab_VERSION_STRING "NOTFOUND")
- if(_numbers_of_matlab_roots GREATER 0)
- list(GET _matlab_possible_roots 0 Matlab_VERSION_STRING)
- list(GET _matlab_possible_roots 1 Matlab_ROOT_DIR)
-
- if(_numbers_of_matlab_roots GREATER 2 AND MATLAB_FIND_DEBUG)
- message(WARNING "[MATLAB] Found several distributions of Matlab. Setting the current version to ${Matlab_VERSION_STRING} (located ${Matlab_ROOT_DIR})."
- " If this is not the desired behaviour, provide the -DMatlab_ROOT_DIR=... on the command line")
- endif()
- endif()
- if(DEFINED Matlab_ROOT_DIR_LAST_CACHED)
- if(NOT Matlab_ROOT_DIR_LAST_CACHED STREQUAL Matlab_ROOT_DIR)
- set(_Matlab_cached_vars
- Matlab_INCLUDE_DIRS
- Matlab_MEX_LIBRARY
- Matlab_MEX_COMPILER
- Matlab_MAIN_PROGRAM
- Matlab_MX_LIBRARY
- Matlab_ENG_LIBRARY
- Matlab_MAT_LIBRARY
- Matlab_MEX_EXTENSION
- Matlab_SIMULINK_INCLUDE_DIR
-
- Matlab_MEXEXTENSIONS_PROG
- Matlab_ROOT_DIR_LAST_CACHED
-
- Matlab_VERSION_STRING_INTERNAL
- )
- foreach(_var IN LISTS _Matlab_cached_vars)
- if(DEFINED ${_var})
- unset(${_var} CACHE)
- endif()
- endforeach()
- endif()
- endif()
- set(Matlab_ROOT_DIR_LAST_CACHED ${Matlab_ROOT_DIR} CACHE INTERNAL "last Matlab root dir location")
- set(Matlab_ROOT_DIR ${Matlab_ROOT_DIR} CACHE PATH "Matlab installation root path" FORCE)
- _Matlab_get_version_from_root(
- "${Matlab_ROOT_DIR}"
- ${Matlab_VERSION_STRING}
- Matlab_VERSION_STRING
- )
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] Current version is ${Matlab_VERSION_STRING} located ${Matlab_ROOT_DIR}")
- endif()
- if(Matlab_ROOT_DIR)
- file(TO_CMAKE_PATH ${Matlab_ROOT_DIR} Matlab_ROOT_DIR)
- endif()
- if(CMAKE_SIZEOF_VOID_P EQUAL 4)
- set(_matlab_64Build FALSE)
- else()
- set(_matlab_64Build TRUE)
- endif()
- if(APPLE)
- set(_matlab_bin_prefix "mac")
- set(_matlab_bin_suffix_32bits "i")
- set(_matlab_bin_suffix_64bits "i64")
- elseif(UNIX)
- set(_matlab_bin_prefix "gln")
- set(_matlab_bin_suffix_32bits "x86")
- set(_matlab_bin_suffix_64bits "xa64")
- else()
- set(_matlab_bin_prefix "win")
- set(_matlab_bin_suffix_32bits "32")
- set(_matlab_bin_suffix_64bits "64")
- endif()
- set(MATLAB_INCLUDE_DIR_TO_LOOK ${Matlab_ROOT_DIR}/extern/include)
- if(_matlab_64Build)
- set(_matlab_current_suffix ${_matlab_bin_suffix_64bits})
- else()
- set(_matlab_current_suffix ${_matlab_bin_suffix_32bits})
- endif()
- set(Matlab_BINARIES_DIR
- ${Matlab_ROOT_DIR}/bin/${_matlab_bin_prefix}${_matlab_current_suffix})
- set(Matlab_EXTERN_LIBRARY_DIR
- ${Matlab_ROOT_DIR}/extern/lib/${_matlab_bin_prefix}${_matlab_current_suffix})
- if(WIN32)
- if(MINGW)
- set(_matlab_lib_dir_for_search ${Matlab_EXTERN_LIBRARY_DIR}/mingw64)
- else()
- set(_matlab_lib_dir_for_search ${Matlab_EXTERN_LIBRARY_DIR}/microsoft)
- endif()
- set(_matlab_lib_prefix_for_search "lib")
- else()
- set(_matlab_lib_dir_for_search ${Matlab_BINARIES_DIR})
- set(_matlab_lib_prefix_for_search "lib")
- endif()
- unset(_matlab_64Build)
- if(NOT DEFINED Matlab_MEX_EXTENSION)
- set(_matlab_mex_extension "")
- matlab_get_mex_suffix("${Matlab_ROOT_DIR}" _matlab_mex_extension)
-
- set(Matlab_MEX_EXTENSION ${_matlab_mex_extension} CACHE STRING "Extensions for the mex targets (automatically given by Matlab)")
- unset(_matlab_mex_extension)
- endif()
- if(MATLAB_FIND_DEBUG)
- message(STATUS "[MATLAB] [DEBUG]_matlab_lib_prefix_for_search = ${_matlab_lib_prefix_for_search} | _matlab_lib_dir_for_search = ${_matlab_lib_dir_for_search}")
- endif()
- function(_Matlab_find_library _matlab_library_prefix)
- set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} ${_matlab_library_prefix})
- find_library(${ARGN})
- endfunction()
- set(_matlab_required_variables)
- find_path(
- Matlab_INCLUDE_DIRS
- mex.h
- PATHS ${MATLAB_INCLUDE_DIR_TO_LOOK}
- NO_DEFAULT_PATH
- )
- list(APPEND _matlab_required_variables Matlab_INCLUDE_DIRS)
- _Matlab_find_library(
- ${_matlab_lib_prefix_for_search}
- Matlab_MEX_LIBRARY
- mex
- PATHS ${_matlab_lib_dir_for_search}
- NO_DEFAULT_PATH
- )
- list(APPEND _matlab_required_variables Matlab_MEX_LIBRARY)
- list(APPEND _matlab_required_variables Matlab_MEX_EXTENSION)
- list(APPEND _matlab_required_variables Matlab_ROOT_DIR)
- list(FIND Matlab_FIND_COMPONENTS MEX_COMPILER _matlab_find_mex_compiler)
- if(_matlab_find_mex_compiler GREATER -1)
- find_program(
- Matlab_MEX_COMPILER
- "mex"
- PATHS ${Matlab_BINARIES_DIR}
- DOC "Matlab MEX compiler"
- NO_DEFAULT_PATH
- )
- if(Matlab_MEX_COMPILER)
- set(Matlab_MEX_COMPILER_FOUND TRUE)
- endif()
- endif()
- unset(_matlab_find_mex_compiler)
- list(FIND Matlab_FIND_COMPONENTS MAIN_PROGRAM _matlab_find_matlab_program)
- if(_matlab_find_matlab_program GREATER -1)
- find_program(
- Matlab_MAIN_PROGRAM
- matlab
- PATHS ${Matlab_ROOT_DIR} ${Matlab_ROOT_DIR}/bin
- DOC "Matlab main program"
- NO_DEFAULT_PATH
- )
- if(Matlab_MAIN_PROGRAM)
- set(Matlab_MAIN_PROGRAM_FOUND TRUE)
- endif()
- endif()
- unset(_matlab_find_matlab_program)
- list(FIND Matlab_FIND_COMPONENTS MX_LIBRARY _matlab_find_mx)
- if(_matlab_find_mx GREATER -1)
- _Matlab_find_library(
- ${_matlab_lib_prefix_for_search}
- Matlab_MX_LIBRARY
- mx
- PATHS ${_matlab_lib_dir_for_search}
- NO_DEFAULT_PATH
- )
- if(Matlab_MX_LIBRARY)
- set(Matlab_MX_LIBRARY_FOUND TRUE)
- endif()
- endif()
- unset(_matlab_find_mx)
- list(FIND Matlab_FIND_COMPONENTS ENG_LIBRARY _matlab_find_eng)
- if(_matlab_find_eng GREATER -1)
- _Matlab_find_library(
- ${_matlab_lib_prefix_for_search}
- Matlab_ENG_LIBRARY
- eng
- PATHS ${_matlab_lib_dir_for_search}
- NO_DEFAULT_PATH
- )
- if(Matlab_ENG_LIBRARY)
- set(Matlab_ENG_LIBRARY_FOUND TRUE)
- endif()
- endif()
- unset(_matlab_find_eng)
- list(FIND Matlab_FIND_COMPONENTS MAT_LIBRARY _matlab_find_mat)
- if(_matlab_find_mat GREATER -1)
- _Matlab_find_library(
- ${_matlab_lib_prefix_for_search}
- Matlab_MAT_LIBRARY
- mat
- PATHS ${_matlab_lib_dir_for_search}
- NO_DEFAULT_PATH
- )
- if(Matlab_MAT_LIBRARY)
- set(Matlab_MAT_LIBRARY_FOUND TRUE)
- endif()
- endif()
- unset(_matlab_find_mat)
- list(FIND Matlab_FIND_COMPONENTS SIMULINK _matlab_find_simulink)
- if(_matlab_find_simulink GREATER -1)
- find_path(
- Matlab_SIMULINK_INCLUDE_DIR
- simstruc.h
- PATHS "${Matlab_ROOT_DIR}/simulink/include"
- NO_DEFAULT_PATH
- )
- if(Matlab_SIMULINK_INCLUDE_DIR)
- set(Matlab_SIMULINK_FOUND TRUE)
- list(APPEND Matlab_INCLUDE_DIRS "${Matlab_SIMULINK_INCLUDE_DIR}")
- endif()
- endif()
- unset(_matlab_find_simulink)
- unset(_matlab_lib_dir_for_search)
- set(Matlab_LIBRARIES ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY} ${Matlab_ENG_LIBRARY} ${Matlab_MAT_LIBRARY})
- find_package_handle_standard_args(
- Matlab
- FOUND_VAR Matlab_FOUND
- REQUIRED_VARS ${_matlab_required_variables}
- VERSION_VAR Matlab_VERSION_STRING
- HANDLE_COMPONENTS)
- unset(_matlab_required_variables)
- unset(_matlab_bin_prefix)
- unset(_matlab_bin_suffix_32bits)
- unset(_matlab_bin_suffix_64bits)
- unset(_matlab_current_suffix)
- unset(_matlab_lib_dir_for_search)
- unset(_matlab_lib_prefix_for_search)
- if(Matlab_INCLUDE_DIRS AND Matlab_LIBRARIES)
- mark_as_advanced(
- Matlab_MEX_LIBRARY
- Matlab_MX_LIBRARY
- Matlab_ENG_LIBRARY
- Matlab_MAT_LIBRARY
- Matlab_INCLUDE_DIRS
- Matlab_FOUND
- Matlab_MAIN_PROGRAM
- Matlab_MEXEXTENSIONS_PROG
- Matlab_MEX_EXTENSION
- )
- endif()
|