summaryrefslogtreecommitdiffstats
path: root/Tests/FindMatlab
diff options
context:
space:
mode:
authorSilvio <silvio@traversaro.it>2022-04-03 15:25:12 (GMT)
committerBrad King <brad.king@kitware.com>2022-04-05 12:27:09 (GMT)
commit178cf34bdc5234e07442d0007c39e2d184b4261f (patch)
tree19c93e758675df831ef5abafa9099da368258f7d /Tests/FindMatlab
parentfff8f3bee92d9f139c48cdc194ca826447fc402a (diff)
downloadCMake-178cf34bdc5234e07442d0007c39e2d184b4261f.zip
CMake-178cf34bdc5234e07442d0007c39e2d184b4261f.tar.gz
CMake-178cf34bdc5234e07442d0007c39e2d184b4261f.tar.bz2
FindMatlab: Add NO_IMPLICIT_LINK_TO_MATLAB_LIBRARIES option to matlab_add_mex
Diffstat (limited to 'Tests/FindMatlab')
-rw-r--r--Tests/FindMatlab/no_implicit_link_checks/CMakeLists.txt70
1 files changed, 70 insertions, 0 deletions
diff --git a/Tests/FindMatlab/no_implicit_link_checks/CMakeLists.txt b/Tests/FindMatlab/no_implicit_link_checks/CMakeLists.txt
new file mode 100644
index 0000000..bceeba1
--- /dev/null
+++ b/Tests/FindMatlab/no_implicit_link_checks/CMakeLists.txt
@@ -0,0 +1,70 @@
+
+cmake_minimum_required (VERSION 2.8.12)
+enable_testing()
+project(no_implicit_links_checks)
+
+set(MATLAB_FIND_DEBUG TRUE)
+
+if(IS_MCR)
+ set(RUN_UNIT_TESTS FALSE)
+else()
+ set(RUN_UNIT_TESTS TRUE)
+ set(components MAIN_PROGRAM)
+endif()
+
+if(NOT "${MCR_ROOT}" STREQUAL "")
+ set(Matlab_ROOT_DIR "${MCR_ROOT}")
+ if(NOT EXISTS "${MCR_ROOT}")
+ message(FATAL_ERROR "MCR does not exist ${MCR_ROOT}")
+ endif()
+endif()
+
+find_package(Matlab REQUIRED COMPONENTS ${components})
+
+
+matlab_add_mex(
+ # target name
+ NAME cmake_matlab_test_wrapper1
+ # output name
+ OUTPUT_NAME cmake_matlab_mex1
+ SRC ${CMAKE_CURRENT_SOURCE_DIR}/../matlab_wrapper1.cpp
+ DOCUMENTATION ${CMAKE_CURRENT_SOURCE_DIR}/../help_text1.m.txt
+ NO_IMPLICIT_LINK_TO_MATLAB_LIBRARIES
+ )
+
+# Inspect the LINK_LIBRARIES properties to check if mex or mx are present
+get_target_property(MATLAB_TEST_WRAPPER1_LINK_LIBRARIES
+ cmake_matlab_test_wrapper1 LINK_LIBRARIES)
+
+string(FIND "${MATLAB_TEST_WRAPPER1_LINK_LIBRARIES}" "mx" SEARCH_RESULT)
+if(NOT "${SEARCH_RESULT}" EQUAL "-1")
+ message(FATAL_ERROR "Matlab::mx linked even if NO_IMPLICIT_LINK_TO_MATLAB_LIBRARIES was passed")
+endif()
+
+string(FIND "${MATLAB_TEST_WRAPPER1_LINK_LIBRARIES}" "mex" SEARCH_RESULT)
+if(NOT "${SEARCH_RESULT}" EQUAL "-1")
+ message(FATAL_ERROR "Matlab::mex linked even if NO_IMPLICIT_LINK_TO_MATLAB_LIBRARIES was passed")
+endif()
+
+string(FIND "${MATLAB_TEST_WRAPPER1_LINK_LIBRARIES}" "MatlabEngine" SEARCH_RESULT)
+if(NOT "${SEARCH_RESULT}" EQUAL "-1")
+ message(FATAL_ERROR "Matlab::MatlabEngine linked even if NO_IMPLICIT_LINK_TO_MATLAB_LIBRARIES was passed")
+endif()
+
+string(FIND "${MATLAB_TEST_WRAPPER1_LINK_LIBRARIES}" "MatlabDataArray" SEARCH_RESULT)
+if(NOT "${SEARCH_RESULT}" EQUAL "-1")
+ message(FATAL_ERROR "Matlab::MatlabDataArray linked even if NO_IMPLICIT_LINK_TO_MATLAB_LIBRARIES was passed")
+endif()
+
+# Link separately with Matlab::mx and Matlab::mex to ensure that compilation
+# and run of the test is successful
+target_link_libraries(cmake_matlab_test_wrapper1 PRIVATE Matlab::mx Matlab::mex)
+
+if(RUN_UNIT_TESTS)
+ matlab_add_unit_test(
+ NAME ${PROJECT_NAME}_matlabtest-1
+ TIMEOUT 300
+ UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests1.m
+ ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
+ )
+endif()