diff options
author | Brad King <brad.king@kitware.com> | 2019-07-16 11:23:11 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-07-16 11:23:20 (GMT) |
commit | e0d45ddab55ac73bad80a95bdd80df711c0255d8 (patch) | |
tree | 04e11e79e9a51fd1f5ed2149617cbb0bfd038a5f /Modules | |
parent | e653938b391d331c1df21bcf83ce5a771bf7a81f (diff) | |
parent | cd6bd8391a4198a1ac9dc3146603d095e8a01d0d (diff) | |
download | CMake-e0d45ddab55ac73bad80a95bdd80df711c0255d8.zip CMake-e0d45ddab55ac73bad80a95bdd80df711c0255d8.tar.gz CMake-e0d45ddab55ac73bad80a95bdd80df711c0255d8.tar.bz2 |
Merge topic 'FindMatlab/pre-2018-fixes'
cd6bd8391a FindMatlab: code comment and ordering of the finders
9e6206c59b FindMatlab: fixing extension bat file invocation error
a9b36ea69f FindMatlab: Fixing compilation issues on Windows
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3554
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindMatlab.cmake | 162 |
1 files changed, 81 insertions, 81 deletions
diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 03f1500..c8cae2e 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -609,14 +609,23 @@ function(matlab_get_mex_suffix matlab_root mex_suffix) set(devnull INPUT_FILE NUL) endif() + if(WIN32) + # this environment variable is used to determine the arch on Windows + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(ENV{MATLAB_ARCH} "win64") + else() + set(ENV{MATLAB_ARCH} "win32") + endif() + endif() + # this is the preferred way. If this does not work properly (eg. MCR on Windows), then we use our own knowledge execute_process( COMMAND ${Matlab_MEXEXTENSIONS_PROG} OUTPUT_VARIABLE _matlab_mex_extension - #RESULT_VARIABLE _matlab_mex_extension_call ERROR_VARIABLE _matlab_mex_extension_error OUTPUT_STRIP_TRAILING_WHITESPACE ${devnull}) + unset(ENV{MATLAB_ARCH}) if(_matlab_mex_extension_error) if(WIN32) @@ -631,7 +640,7 @@ function(matlab_get_mex_suffix matlab_root mex_suffix) string(STRIP "${_matlab_mex_extension}" _matlab_mex_extension) if(MATLAB_FIND_DEBUG) - message(STATUS "[MATLAB] '${Matlab_MEXEXTENSIONS_PROG}' : returned '${_matlab_mex_extension_call}', determined extension '${_matlab_mex_extension}' and error string is '${_matlab_mex_extension_error}'") + message(STATUS "[MATLAB] '${Matlab_MEXEXTENSIONS_PROG}' : determined extension '${_matlab_mex_extension}' and error string is '${_matlab_mex_extension_error}'") endif() unset(Matlab_MEXEXTENSIONS_PROG CACHE) @@ -1043,14 +1052,9 @@ function(matlab_add_mex) set(_link_flags "${_link_flags} /EXPORT:mexfilerequiredapiversion") endif() - if(Matlab_HAS_CPP_API) - set(_link_flags "${_link_flags} /EXPORT:mexCreateMexFunction /EXPORT:mexDestroyMexFunction /EXPORT:mexFunctionAdapter") - #TODO: Is this necessary? - endif() - set_property(TARGET ${${prefix}_NAME} APPEND PROPERTY LINK_FLAGS ${_link_flags}) - endif() # TODO: what if there's a different compiler on Windows? + endif() # No other compiler currently supported on Windows. set_target_properties(${${prefix}_NAME} PROPERTIES @@ -1533,7 +1537,9 @@ if(MATLAB_FIND_DEBUG) message(STATUS "[MATLAB] Current version is ${Matlab_VERSION_STRING} located ${Matlab_ROOT_DIR}") endif() -if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.4") # MATLAB 9.4 (R2018a) and newer have a new C++ API +# MATLAB 9.4 (R2018a) and newer have a new C++ API +# This API pulls additional required libraries. +if(NOT ${Matlab_VERSION_STRING} VERSION_LESS "9.4") set(Matlab_HAS_CPP_API 1) endif() @@ -1619,6 +1625,10 @@ endfunction() set(_matlab_required_variables) +# Order is as follow: +# - unconditionally required libraries/headers first +# - then library components +# - then program components # the MEX library/header are required find_path( @@ -1644,34 +1654,6 @@ list(APPEND _matlab_required_variables Matlab_MEX_EXTENSION) # the matlab root is required list(APPEND _matlab_required_variables Matlab_ROOT_DIR) -# component Mex Compiler -if("MEX_COMPILER" IN_LIST Matlab_FIND_COMPONENTS) - 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() - -# component Matlab program -if("MAIN_PROGRAM" IN_LIST Matlab_FIND_COMPONENTS) - 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() - # The MX library is required _Matlab_find_library( ${_matlab_lib_prefix_for_search} @@ -1685,9 +1667,40 @@ if(Matlab_MX_LIBRARY) set(Matlab_MX_LIBRARY_FOUND TRUE) endif() +if(Matlab_HAS_CPP_API) + + # The MatlabEngine library is required for R2018a+ + _Matlab_find_library( + ${_matlab_lib_prefix_for_search} + Matlab_ENGINE_LIBRARY + MatlabEngine + PATHS ${_matlab_lib_dir_for_search} + DOC "MatlabEngine Library" + NO_DEFAULT_PATH + ) + list(APPEND _matlab_required_variables Matlab_ENGINE_LIBRARY) + if(Matlab_ENGINE_LIBRARY) + set(Matlab_ENGINE_LIBRARY_FOUND TRUE) + endif() + + # The MatlabDataArray library is required for R2018a+ + _Matlab_find_library( + ${_matlab_lib_prefix_for_search} + Matlab_DATAARRAY_LIBRARY + MatlabDataArray + PATHS ${_matlab_lib_dir_for_search} + DOC "MatlabDataArray Library" + NO_DEFAULT_PATH + ) + list(APPEND _matlab_required_variables Matlab_DATAARRAY_LIBRARY) + if(Matlab_DATAARRAY_LIBRARY) + set(Matlab_DATAARRAY_LIBRARY_FOUND TRUE) + endif() + +endif() + # Component ENG library -list(FIND Matlab_FIND_COMPONENTS ENG_LIBRARY _matlab_find_eng) -if(_matlab_find_eng GREATER -1) +if("ENG_LIBRARY" IN_LIST Matlab_FIND_COMPONENTS) _Matlab_find_library( ${_matlab_lib_prefix_for_search} Matlab_ENG_LIBRARY @@ -1699,11 +1712,9 @@ if(_matlab_find_eng GREATER -1) set(Matlab_ENG_LIBRARY_FOUND TRUE) endif() endif() -unset(_matlab_find_eng) # Component MAT library -list(FIND Matlab_FIND_COMPONENTS MAT_LIBRARY _matlab_find_mat) -if(_matlab_find_mat GREATER -1) +if("MAT_LIBRARY" IN_LIST Matlab_FIND_COMPONENTS) _Matlab_find_library( ${_matlab_lib_prefix_for_search} Matlab_MAT_LIBRARY @@ -1715,11 +1726,9 @@ if(_matlab_find_mat GREATER -1) set(Matlab_MAT_LIBRARY_FOUND TRUE) endif() endif() -unset(_matlab_find_mat) # Component Simulink -list(FIND Matlab_FIND_COMPONENTS SIMULINK _matlab_find_simulink) -if(_matlab_find_simulink GREATER -1) +if("SIMULINK" IN_LIST Matlab_FIND_COMPONENTS) find_path( Matlab_SIMULINK_INCLUDE_DIR simstruc.h @@ -1731,58 +1740,49 @@ if(_matlab_find_simulink GREATER -1) list(APPEND Matlab_INCLUDE_DIRS "${Matlab_SIMULINK_INCLUDE_DIR}") endif() endif() -unset(_matlab_find_simulink) -# component MCC Compiler -list(FIND Matlab_FIND_COMPONENTS MCC_COMPILER _matlab_find_mcc_compiler) -if(_matlab_find_mcc_compiler GREATER -1) +# component Matlab program +if("MAIN_PROGRAM" IN_LIST Matlab_FIND_COMPONENTS) find_program( - Matlab_MCC_COMPILER - "mcc" - PATHS ${Matlab_BINARIES_DIR} - DOC "Matlab MCC compiler" + Matlab_MAIN_PROGRAM + matlab + PATHS ${Matlab_ROOT_DIR} ${Matlab_ROOT_DIR}/bin + DOC "Matlab main program" NO_DEFAULT_PATH ) - if(Matlab_MCC_COMPILER) - set(Matlab_MCC_COMPILER_FOUND TRUE) + if(Matlab_MAIN_PROGRAM) + set(Matlab_MAIN_PROGRAM_FOUND TRUE) endif() endif() -unset(_matlab_find_mcc_compiler) -if(Matlab_HAS_CPP_API) - - # The MatlabEngine library is required for R2018a+ - _Matlab_find_library( - ${_matlab_lib_prefix_for_search} - Matlab_ENGINE_LIBRARY - MatlabEngine - PATHS ${_matlab_lib_dir_for_search} - DOC "MatlabEngine Library" +# component Mex Compiler +if("MEX_COMPILER" IN_LIST Matlab_FIND_COMPONENTS) + find_program( + Matlab_MEX_COMPILER + "mex" + PATHS ${Matlab_BINARIES_DIR} + DOC "Matlab MEX compiler" NO_DEFAULT_PATH ) - list(APPEND _matlab_required_variables Matlab_ENGINE_LIBRARY) - if(Matlab_ENGINE_LIBRARY) - set(Matlab_ENGINE_LIBRARY_FOUND TRUE) + if(Matlab_MEX_COMPILER) + set(Matlab_MEX_COMPILER_FOUND TRUE) endif() +endif() - # The MatlabDataArray library is required for R2018a+ - _Matlab_find_library( - ${_matlab_lib_prefix_for_search} - Matlab_DATAARRAY_LIBRARY - MatlabDataArray - PATHS ${_matlab_lib_dir_for_search} - DOC "MatlabDataArray Library" +# component MCC Compiler +if("MCC_COMPILER" IN_LIST Matlab_FIND_COMPONENTS) + find_program( + Matlab_MCC_COMPILER + "mcc" + PATHS ${Matlab_BINARIES_DIR} + DOC "Matlab MCC compiler" NO_DEFAULT_PATH ) - list(APPEND _matlab_required_variables Matlab_DATAARRAY_LIBRARY) - if(Matlab_DATAARRAY_LIBRARY) - set(Matlab_DATAARRAY_LIBRARY_FOUND TRUE) + if(Matlab_MCC_COMPILER) + set(Matlab_MCC_COMPILER_FOUND TRUE) endif() - endif() -unset(_matlab_lib_dir_for_search) - set(Matlab_LIBRARIES ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY} ${Matlab_ENG_LIBRARY} ${Matlab_MAT_LIBRARY} |