Browse Source

FindMatlab: Search mex and mx libraries for MCR

Further changes:
- Better documentation of library availabilities
- Log each library location in debug mode

Fixes: #26306
Hermann von Kleist 1 year ago
parent
commit
9ceca05e6b
1 changed files with 78 additions and 42 deletions
  1. 78 42
      Modules/FindMatlab.cmake

+ 78 - 42
Modules/FindMatlab.cmake

@@ -117,10 +117,12 @@ Imported targets
 This module defines the following :prop_tgt:`IMPORTED` targets:
 
 ``Matlab::mex``
-  The ``mex`` library, always available.
+  The ``mex`` library, always available for MATLAB installations. Available for
+  MCR installations if provided by MCR.
 
 ``Matlab::mx``
-  The mx library of Matlab (arrays), always available.
+  The mx library of Matlab (arrays), always available for MATLAB installations.
+  Available for MCR installations if provided by MCR.
 
 ``Matlab::eng``
   Matlab engine library. Available only if the ``ENG_LIBRARY`` component
@@ -131,10 +133,12 @@ This module defines the following :prop_tgt:`IMPORTED` targets:
   is requested.
 
 ``Matlab::MatlabEngine``
-  Matlab C++ engine library, always available for R2018a and newer.
+  Matlab C++ engine library, always available for MATLAB R2018a and newer.
+  Available for MCR installations if provided by MCR.
 
 ``Matlab::MatlabDataArray``
-  Matlab C++ data array library, always available for R2018a and newer.
+  Matlab C++ data array library, always available for MATLAB R2018a and newer.
+  Available for MCR installations if provided by MCR.
 
 Variables defined by the module
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -160,9 +164,11 @@ Result variables
 ``Matlab_INCLUDE_DIRS``
  the path of the Matlab libraries headers
 ``Matlab_MEX_LIBRARY``
-  library for mex, always available.
+  library for mex, always available for MATLAB installations. Available for MCR
+  installations if provided by MCR.
 ``Matlab_MX_LIBRARY``
-  mx library of Matlab (arrays), always available.
+  mx library of Matlab (arrays), always available for MATLAB installations.
+  Available for MCR installations if provided by MCR.
 ``Matlab_ENG_LIBRARY``
   Matlab engine library. Available only if the component ``ENG_LIBRARY``
   is requested.
@@ -172,11 +178,13 @@ Result variables
 ``Matlab_ENGINE_LIBRARY``
   .. versionadded:: 3.13
 
-  Matlab C++ engine library, always available for R2018a and newer.
+  Matlab C++ engine library, always available for MATLAB R2018a and newer.
+  Available for MCR installations if provided by MCR.
 ``Matlab_DATAARRAY_LIBRARY``
   .. versionadded:: 3.13
 
-  Matlab C++ data array library, always available for R2018a and newer.
+  Matlab C++ data array library, always available for MATLAB R2018a and newer.
+  Available for MCR installations if provided by MCR.
 ``Matlab_LIBRARIES``
   the whole set of libraries of Matlab
 ``Matlab_MEX_COMPILER``
@@ -1835,7 +1843,9 @@ function(_Matlab_find_library _matlab_library_prefix)
 endfunction()
 
 
-set(_matlab_required_variables)
+# the matlab root is required
+set(_matlab_required_variables Matlab_ROOT_DIR)
+set(Matlab_LIBRARIES)
 
 # Order is as follow:
 # - unconditionally required libraries/headers first
@@ -1851,34 +1861,44 @@ find_path(
   )
 list(APPEND _matlab_required_variables Matlab_INCLUDE_DIRS)
 
+_Matlab_find_library(
+  ${_matlab_lib_prefix_for_search}
+  Matlab_MEX_LIBRARY
+  NAMES mex
+  PATHS ${_matlab_lib_dir_for_search}
+  NO_DEFAULT_PATH
+)
+if(Matlab_MEX_LIBRARY)
+  set(Matlab_MEX_LIBRARY_FOUND TRUE)
+  list(APPEND Matlab_LIBRARIES ${Matlab_MEX_LIBRARY})
+endif()
+if(MATLAB_FIND_DEBUG)
+  message(STATUS "[MATLAB] mex C library: ${Matlab_MEX_LIBRARY}")
+endif()
+
+# The MX library is required
+_Matlab_find_library(
+  ${_matlab_lib_prefix_for_search}
+  Matlab_MX_LIBRARY
+  NAMES mx
+  PATHS ${_matlab_lib_dir_for_search}
+  NO_DEFAULT_PATH
+)
+if(Matlab_MX_LIBRARY)
+  set(Matlab_MX_LIBRARY_FOUND TRUE)
+  list(APPEND Matlab_LIBRARIES ${Matlab_MX_LIBRARY})
+endif()
+if(MATLAB_FIND_DEBUG)
+  message(STATUS "[MATLAB] mx C library: ${Matlab_MX_LIBRARY}")
+endif()
+
 if(Matlab_Or_MCR STREQUAL "MATLAB" OR Matlab_Or_MCR STREQUAL "UNKNOWN")
-  _Matlab_find_library(
-    ${_matlab_lib_prefix_for_search}
-    Matlab_MEX_LIBRARY
-    NAMES mex
-    PATHS ${_matlab_lib_dir_for_search}
-    NO_DEFAULT_PATH
-  )
   list(APPEND _matlab_required_variables Matlab_MEX_LIBRARY)
 
   # the MEX extension is required
   list(APPEND _matlab_required_variables Matlab_MEX_EXTENSION)
 
-  # the matlab root is required
-  list(APPEND _matlab_required_variables Matlab_ROOT_DIR)
-
-  # The MX library is required
-  _Matlab_find_library(
-    ${_matlab_lib_prefix_for_search}
-    Matlab_MX_LIBRARY
-    NAMES mx
-    PATHS ${_matlab_lib_dir_for_search}
-    NO_DEFAULT_PATH
-  )
   list(APPEND _matlab_required_variables Matlab_MX_LIBRARY)
-  if(Matlab_MX_LIBRARY)
-    set(Matlab_MX_LIBRARY_FOUND TRUE)
-  endif()
 endif()
 
 if(Matlab_HAS_CPP_API)
@@ -1894,6 +1914,10 @@ if(Matlab_HAS_CPP_API)
   )
   if(Matlab_ENGINE_LIBRARY)
     set(Matlab_ENGINE_LIBRARY_FOUND TRUE)
+    list(APPEND Matlab_LIBRARIES ${Matlab_ENGINE_LIBRARY})
+  endif()
+  if(MATLAB_FIND_DEBUG)
+    message(STATUS "[MATLAB] Engine C++ library: ${Matlab_ENGINE_LIBRARY}")
   endif()
 
   # The MatlabDataArray library is required for R2018a+
@@ -1907,6 +1931,10 @@ if(Matlab_HAS_CPP_API)
   )
   if(Matlab_DATAARRAY_LIBRARY)
     set(Matlab_DATAARRAY_LIBRARY_FOUND TRUE)
+    list(APPEND Matlab_LIBRARIES ${Matlab_DATAARRAY_LIBRARY})
+  endif()
+  if(MATLAB_FIND_DEBUG)
+    message(STATUS "[MATLAB] Data array C++ library: ${Matlab_DATAARRAY_LIBRARY}")
   endif()
 
 endif()
@@ -1922,6 +1950,10 @@ if("ENG_LIBRARY" IN_LIST Matlab_FIND_COMPONENTS)
   )
   if(Matlab_ENG_LIBRARY)
     set(Matlab_ENG_LIBRARY_FOUND TRUE)
+    list(APPEND Matlab_LIBRARIES ${Matlab_ENG_LIBRARY})
+  endif()
+  if(MATLAB_FIND_DEBUG)
+    message(STATUS "[MATLAB] eng C library: ${Matlab_ENG_LIBRARY}")
   endif()
 endif()
 
@@ -1936,6 +1968,10 @@ if("MAT_LIBRARY" IN_LIST Matlab_FIND_COMPONENTS)
   )
   if(Matlab_MAT_LIBRARY)
     set(Matlab_MAT_LIBRARY_FOUND TRUE)
+    list(APPEND Matlab_LIBRARIES ${Matlab_MAT_LIBRARY})
+  endif()
+  if(MATLAB_FIND_DEBUG)
+    message(STATUS "[MATLAB] mat C library: ${Matlab_MAT_LIBRARY}")
   endif()
 endif()
 
@@ -1951,6 +1987,9 @@ if("SIMULINK" IN_LIST Matlab_FIND_COMPONENTS)
     set(Matlab_SIMULINK_FOUND TRUE)
     list(APPEND Matlab_INCLUDE_DIRS "${Matlab_SIMULINK_INCLUDE_DIR}")
   endif()
+  if(MATLAB_FIND_DEBUG)
+    message(STATUS "[MATLAB] Simulink include dir: ${Matlab_SIMULINK_INCLUDE_DIR}")
+  endif()
 endif()
 
 # component Matlab program
@@ -1965,6 +2004,9 @@ if("MAIN_PROGRAM" IN_LIST Matlab_FIND_COMPONENTS)
   if(Matlab_MAIN_PROGRAM)
     set(Matlab_MAIN_PROGRAM_FOUND TRUE)
   endif()
+  if(MATLAB_FIND_DEBUG)
+    message(STATUS "[MATLAB] Main program: ${Matlab_MAIN_PROGRAM}")
+  endif()
 endif()
 
 # component Mex Compiler
@@ -1979,6 +2021,9 @@ if("MEX_COMPILER" IN_LIST Matlab_FIND_COMPONENTS)
   if(Matlab_MEX_COMPILER)
     set(Matlab_MEX_COMPILER_FOUND TRUE)
   endif()
+  if(MATLAB_FIND_DEBUG)
+    message(STATUS "[MATLAB] MEX compiler: ${Matlab_MEX_COMPILER}")
+  endif()
 endif()
 
 # component MCC Compiler
@@ -1993,18 +2038,9 @@ if("MCC_COMPILER" IN_LIST Matlab_FIND_COMPONENTS)
   if(Matlab_MCC_COMPILER)
     set(Matlab_MCC_COMPILER_FOUND TRUE)
   endif()
-endif()
-
-set(Matlab_LIBRARIES
-  ${Matlab_MEX_LIBRARY} ${Matlab_MX_LIBRARY}
-  ${Matlab_ENG_LIBRARY} ${Matlab_MAT_LIBRARY})
-
-if(Matlab_ENGINE_LIBRARY)
-  list(APPEND Matlab_LIBRARIES ${Matlab_ENGINE_LIBRARY})
-endif()
-
-if(Matlab_DATAARRAY_LIBRARY)
-  list(APPEND Matlab_LIBRARIES ${Matlab_DATAARRAY_LIBRARY})
+  if(MATLAB_FIND_DEBUG)
+    message(STATUS "[MATLAB] MCC compiler: ${Matlab_MCC_COMPILER}")
+  endif()
 endif()
 
 # internal