summaryrefslogtreecommitdiff
path: root/Modules/FindMatlab.cmake
diff options
context:
space:
mode:
authorSilvio Traversaro <pegua1@gmail.com>2020-01-11 10:35:46 -0500
committerBrad King <brad.king@kitware.com>2020-01-13 10:52:57 -0500
commitb704d58f41def99de41485af364d9c7ea46ed475 (patch)
tree31f0689ce3ebc90a60003d9731083e5fbc308845 /Modules/FindMatlab.cmake
parent512ab500f06d6c645985cc8014c5e6291b9a059f (diff)
downloadcmake-b704d58f41def99de41485af364d9c7ea46ed475.tar.gz
FindMatlab: in matlab_add_mex use the correct version file
Before this modification, the c_mexapi_version.c file was added to all mex libraries. However, if the C language was not enabled in the CMake project configuration, the c_mexapi_version.c file was ignored, creating linking errors in Windows and macOS. This commit ensures that in the case only the CXX languages is enabled, the correct version is passed. Fixes: #19382
Diffstat (limited to 'Modules/FindMatlab.cmake')
-rw-r--r--Modules/FindMatlab.cmake17
1 files changed, 13 insertions, 4 deletions
diff --git a/Modules/FindMatlab.cmake b/Modules/FindMatlab.cmake
index c8cae2e131..ca56dd51ee 100644
--- a/Modules/FindMatlab.cmake
+++ b/Modules/FindMatlab.cmake
@@ -974,10 +974,19 @@ function(matlab_add_mex)
endif()
if(NOT Matlab_VERSION_STRING VERSION_LESS "9.1") # For 9.1 (R2016b) and newer, add version source file
- # TODO: check the file extensions in ${${prefix}_SRC} to see if they're C or C++ files
- # Currently, the C and C++ versions of the version files are identical, so this doesn't matter.
- set(MEX_VERSION_FILE "${Matlab_ROOT_DIR}/extern/version/c_mexapi_version.c")
- #set(MEX_VERSION_FILE "${Matlab_ROOT_DIR}/extern/version/cpp_mexapi_version.cpp")
+ # Add the correct version file depending on which languages are enabled in the project
+ if(CMAKE_C_COMPILER_LOADED)
+ # If C is enabled, use the .c file as it will work fine also with C++
+ set(MEX_VERSION_FILE "${Matlab_ROOT_DIR}/extern/version/c_mexapi_version.c")
+ elseif(CMAKE_CXX_COMPILER_LOADED)
+ # If C is not enabled, check if CXX is enabled and use the .cpp file
+ # to avoid that the .c file is silently ignored
+ set(MEX_VERSION_FILE "${Matlab_ROOT_DIR}/extern/version/cpp_mexapi_version.cpp")
+ else()
+ # If neither C or CXX is enabled, warn because we cannot add the source.
+ # TODO: add support for fortran mex files
+ message(WARNING "[MATLAB] matlab_add_mex requires that at least C or CXX are enabled languages")
+ endif()
endif()
if(NOT Matlab_VERSION_STRING VERSION_LESS "9.4") # For 9.4 (R2018a) and newer, add API macro