Commit 19c69c5e authored by Patrik Huber's avatar Patrik Huber

Set up simple CMake infrastructure to build Matlab mex files

parent 32624ba4
......@@ -180,3 +180,7 @@ endif()
if(BUILD_DOCUMENTATION)
add_subdirectory(doc)
endif()
if(GENERATE_MATLAB_BINDINGS)
add_subdirectory(matlab)
endif()
project(matlab-bindings)
cmake_minimum_required(VERSION 3.7.0)
# If Matlab_ROOT_DIR is set, the Matlab at that location is used.
find_package(Matlab COMPONENTS MX_LIBRARY REQUIRED)
# See: https://cmake.org/cmake/help/v3.7/module/FindMatlab.html?highlight=findmatlab#command:matlab_add_mex
matlab_add_mex(
NAME eos_matlab
#[EXECUTABLE | MODULE | SHARED] # SHARED is the default.
SRC private/test.cpp
#[OUTPUT_NAME output_name]
#[DOCUMENTATION file.txt]
#[LINK_TO target1 target2 ...] # OpenCV etc?
#[...]
)
target_include_directories(eos_matlab PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/mexplus/include)
# Todo: Look at opencv mex... eg Rect, the .c file. Do they do all the dispatching in mexFunc()?
# Also this may have wrapping for std::vector<T>: https://github.com/kyamagu/mexopencv/blob/master/include/MxArray.hpp
/*
* eos - A 3D Morphable Model fitting library written in modern C++11/14.
*
* File: matlab/private/test.cpp
*
* Copyright 2016 Patrik Huber
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mexplus.h"
#include "mex.h"
//#include "matrix.h"
#include <iostream>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
// Check for proper number of input and output arguments:
mexPrintf("nlhs: %d, nrhs: %d\n", nlhs, nrhs);
if (nrhs != 2) {
mexErrMsgIdAndTxt("eos:example:nargin", "example requires two input arguments.");
}
else if (nlhs >= 1) {
mexErrMsgIdAndTxt("eos:example:nargout", "example requires no output argument.");
}
double *vin1, *vin2;
vin1 = (double*)mxGetPr(prhs[0]);
vin2 = (double*)mxGetPr(prhs[1]);
mexPrintf("%f, %f\n", *vin1, *vin2);
};
void func()
{
int x = 4;
};
int func1()
{
return 5;
};
class MyClass
{
public:
MyClass() = default;
int test() {
return 6;
};
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment