CMake matlab_add_mex() with CTest

The CMake FindMatlab module adds several helper CMake helper functions including matlab_add_mex. When running CTest on MEX targets, the test script needs to add the path of the MEX target to the Matlab path. The matlab-cmake-mex project demonstrates this.

The Matlab runtests optional Name= parameter is the name of the test function in the test script. It allows making a single Matlab test function correspond to a single CTest test.

TARGET_FILE_DIR CMake generator expression tells Matlab addpath where the compiled MEX target is located. The generator expression handles single and multi config generators that may place the target binary under additional subdirectories depending on the build configuration. That is, CMAKE_CURRENT_BINARY_DIR is in general NOT correct for this application. This technique of using a CMake generator expression applies in general whenever a target path is passed to another script or program by CMake add_test.