From 6c57f6b347f2acf19ef043e38463ac03919594f3 Mon Sep 17 00:00:00 2001 From: Sean Warren Date: Wed, 26 Sep 2018 15:15:37 +1000 Subject: FindMatlab: Optionally allow linking to MatlabEngine and MatlabDataArray Fixes: #17971 --- Help/release/dev/FindMatlab-2018b.rst | 6 ++++ Modules/FindMatlab.cmake | 62 +++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Help/release/dev/FindMatlab-2018b.rst diff --git a/Help/release/dev/FindMatlab-2018b.rst b/Help/release/dev/FindMatlab-2018b.rst new file mode 100644 index 0000000..7e17966 --- /dev/null +++ b/Help/release/dev/FindMatlab-2018b.rst @@ -0,0 +1,6 @@ +FindMatlab-2018b +---------------- + +* The :module:`FindMatlab` module gained new components ``ENGINE_LIBRARY`` and + ``DATAARRAY_LIBRARY`` to request finding the Matlab C++ Engine and DataArray + libraries respectively. diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 12a2f75..4565076 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -21,6 +21,8 @@ # # * ``MX_LIBRARY``, ``ENG_LIBRARY`` and ``MAT_LIBRARY``: respectively the ``MX``, # ``ENG`` and ``MAT`` libraries of Matlab +# * ``ENGINE_LIBRARY``, ``DATAARRAY_LIBRARY``: respectively the ``MatlabEngine`` +# and ``MatlabDataArray`` libraries of Matlab (Matlab 2018a and later) # * ``MAIN_PROGRAM`` the Matlab binary program. Note that this component is not # available on the MCR version, and will yield an error if the MCR is found # instead of the regular Matlab installation. @@ -107,6 +109,12 @@ # ``Matlab_MAT_LIBRARY`` # Matlab matrix library. Available only if the component ``MAT_LIBRARY`` # is requested. +# ``Matlab_ENGINE_LIBRARY`` +# Matlab C++ engine library. Available only if the component ``ENGINE_LIBRARY`` +# is requested. +# ``Matlab_DATAARRAY_LIBRARY`` +# Matlab C++ data array library. Available only if the component ``DATAARRAY_LIBRARY`` +# is requested. # ``Matlab_LIBRARIES`` # the whole set of libraries of Matlab # ``Matlab_MEX_COMPILER`` @@ -960,6 +968,14 @@ function(matlab_add_mex) target_link_libraries(${${prefix}_NAME} ${Matlab_MX_LIBRARY}) endif() + if(DEFINED Matlab_ENGINE_LIBRARY) + target_link_libraries(${${prefix}_NAME} ${Matlab_ENGINE_LIBRARY}) + endif() + + if(DEFINED Matlab_DATAARRAY_LIBRARY) + target_link_libraries(${${prefix}_NAME} ${Matlab_DATAARRAY_LIBRARY}) + endif() + target_link_libraries(${${prefix}_NAME} ${Matlab_MEX_LIBRARY} ${${prefix}_LINK_TO}) set_target_properties(${${prefix}_NAME} PROPERTIES @@ -1416,6 +1432,8 @@ if(DEFINED Matlab_ROOT_DIR_LAST_CACHED) Matlab_MX_LIBRARY Matlab_ENG_LIBRARY Matlab_MAT_LIBRARY + Matlab_ENGINE_LIBRARY + Matlab_DATAARRAY_LIBRARY Matlab_MEX_EXTENSION Matlab_SIMULINK_INCLUDE_DIR @@ -1668,10 +1686,52 @@ if(_matlab_find_mcc_compiler GREATER -1) endif() unset(_matlab_find_mcc_compiler) +# component MatlabEngine +list(FIND Matlab_FIND_COMPONENTS ENGINE_LIBRARY _matlab_find_matlab_engine) +if(_matlab_find_matlab_engine GREATER -1) + _Matlab_find_library( + ${_matlab_lib_prefix_for_search} + Matlab_ENGINE_LIBRARY + MatlabEngine + PATHS ${_matlab_lib_dir_for_search} + DOC "MatlabEngine Library" + NO_DEFAULT_PATH + ) + if(Matlab_ENGINE_LIBRARY) + set(Matlab_ENGINE_LIBRARY_FOUND TRUE) + endif() +endif() +unset(_matlab_find_matlab_engine) + +# component MatlabDataArray +list(FIND Matlab_FIND_COMPONENTS DATAARRAY_LIBRARY _matlab_find_matlab_dataarray) +if(_matlab_find_matlab_dataarray GREATER -1) + _Matlab_find_library( + ${_matlab_lib_prefix_for_search} + Matlab_DATAARRAY_LIBRARY + MatlabDataArray + PATHS ${_matlab_lib_dir_for_search} + DOC "MatlabDataArray Library" + NO_DEFAULT_PATH + ) + if(Matlab_DATAARRAY_LIBRARY) + set(Matlab_DATAARRAY_LIBRARY_FOUND TRUE) + endif() +endif() +unset(_matlab_find_matlab_dataarray) + unset(_matlab_lib_dir_for_search) set(Matlab_LIBRARIES ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY} ${Matlab_ENG_LIBRARY} ${Matlab_MAT_LIBRARY}) +if(Matlab_DATAARRAY_LIBRARY_FOUND) + set(Matlab_LIBRARIES ${Matlab_LIBRARIES} ${Matlab_DATAARRAY_LIBRARY}) +endif() + +if(Matlab_ENGINE_LIBRARY_FOUND) + set(Matlab_LIBRARIES ${Matlab_LIBRARIES} ${Matlab_ENGINE_LIBRARY}) +endif() + find_package_handle_standard_args( Matlab FOUND_VAR Matlab_FOUND @@ -1692,6 +1752,8 @@ if(Matlab_INCLUDE_DIRS AND Matlab_LIBRARIES) Matlab_MEX_LIBRARY Matlab_MX_LIBRARY Matlab_ENG_LIBRARY + Matlab_ENGINE_LIBRARY + Matlab_DATAARRAY_LIBRARY Matlab_MAT_LIBRARY Matlab_INCLUDE_DIRS Matlab_FOUND -- cgit v0.12 From 9a56ed3438f652ec526afabeab87e04f330e4724 Mon Sep 17 00:00:00 2001 From: Sean Warren Date: Wed, 26 Sep 2018 15:17:40 +1000 Subject: FindMatlab: Explicitly export mexFunction in MSVC Fixes: #18391 --- Help/release/dev/FindMatlab-2018b.rst | 3 +++ Modules/FindMatlab.cmake | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Help/release/dev/FindMatlab-2018b.rst b/Help/release/dev/FindMatlab-2018b.rst index 7e17966..28758f1 100644 --- a/Help/release/dev/FindMatlab-2018b.rst +++ b/Help/release/dev/FindMatlab-2018b.rst @@ -4,3 +4,6 @@ FindMatlab-2018b * The :module:`FindMatlab` module gained new components ``ENGINE_LIBRARY`` and ``DATAARRAY_LIBRARY`` to request finding the Matlab C++ Engine and DataArray libraries respectively. + +* The :module:`FindMatlab` module now explicitly exports mexFunction in Visual + Studio. diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index 4565076..da832ce 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -996,6 +996,20 @@ function(matlab_add_mex) endif() # documentation # entry point in the mex file + taking care of visibility and symbol clashes. + if (MSVC) + get_target_property( + _previous_link_flags + ${${prefix}_NAME} + LINK_FLAGS) + if(NOT _previous_link_flags) + set(_previous_link_flags) + endif() + + set_target_properties(${${prefix}_NAME} + PROPERTIES + LINK_FLAGS "${_previous_link_flags} /EXPORT:mexFunction") + endif() + if(WIN32) set_target_properties(${${prefix}_NAME} PROPERTIES -- cgit v0.12 From 62709beff8e9bf786b9c3ec5fbd791ce2d452232 Mon Sep 17 00:00:00 2001 From: Sean Warren Date: Wed, 26 Sep 2018 15:18:24 +1000 Subject: FindMatlab: Add Matlab 2018a,b to version list --- Help/release/dev/FindMatlab-2018b.rst | 3 +++ Modules/FindMatlab.cmake | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Help/release/dev/FindMatlab-2018b.rst b/Help/release/dev/FindMatlab-2018b.rst index 28758f1..c698b9d 100644 --- a/Help/release/dev/FindMatlab-2018b.rst +++ b/Help/release/dev/FindMatlab-2018b.rst @@ -7,3 +7,6 @@ FindMatlab-2018b * The :module:`FindMatlab` module now explicitly exports mexFunction in Visual Studio. + +* The :module:`FindMatlab` module gained the ability to discover Matlab R2018a + and R2018b. diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake index da832ce..547a330 100644 --- a/Modules/FindMatlab.cmake +++ b/Modules/FindMatlab.cmake @@ -242,6 +242,8 @@ if(NOT MATLAB_ADDITIONAL_VERSIONS) endif() set(MATLAB_VERSIONS_MAPPING + "R2018b=9.5" + "R2018a=9.4" "R2017b=9.3" "R2017a=9.2" "R2016b=9.1" -- cgit v0.12