Skip to content

Commit

Permalink
added cmake compilation of MEX
Browse files Browse the repository at this point in the history
  • Loading branch information
ebertolazzi committed Apr 6, 2022
1 parent 2374e98 commit 721a051
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
3 changes: 3 additions & 0 deletions toolbox/bin/BaseHermiteMexWrapper.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function varargout = BaseHermitMexeWrapper( varargin )
error(sprintf('\n\n\nBaseHermitMexeWrapper undefined:\ncompile MEX file using CompileSplineLib\n\n\n'));
end
3 changes: 0 additions & 3 deletions toolbox/bin/BaseHermiteWrapper.m

This file was deleted.

40 changes: 40 additions & 0 deletions toolbox/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
cmake_minimum_required( VERSION 3.14 )

project( Splines_Mex )

find_package( Matlab REQUIRED )

message( STATUS "Matlab_ROOT_DIR = ${Matlab_ROOT_DIR}" )
message( STATUS "PROJECT_NAME = ${PROJECT_NAME}" )

## COMPONENTS MX_LIBRARY ENG_LIBRARY MEX_COMPILER )

# set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING INTERNAL FORCE)
set( CMAKE_CXX_STANDARD 11 )

set( SOURCES )
file( GLOB S ${CMAKE_CURRENT_SOURCE_DIR}/../src/*.cc )
foreach(F ${S})
file( RELATIVE_PATH RF ${CMAKE_CURRENT_SOURCE_DIR} "${F}" )
list( APPEND SOURCES ${RF} )
endforeach()

include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../src ${CMAKE_CURRENT_SOURCE_DIR}/../src/Utils )

if ( (UNIX OR LINUX) AND NOT APPLE )
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
set(CMAKE_SHARED_LINKER_FLAGS "-static-libgcc -static-libstdc++")
endif()

set( MEX_LIST BaseHermite Spline1D Spline2D SplineSet SplineVec )

foreach( BASE ${MEX_LIST})
matlab_add_mex( NAME ${BASE}MexWrapper SRC ${CMAKE_CURRENT_SOURCE_DIR}/../src_mex/mex_${BASE}MexWrapper.cc ${SOURCES} )

add_custom_command(
TARGET ${BASE}MexWrapper
POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
"$<TARGET_FILE:${BASE}MexWrapper>"
"${CMAKE_CURRENT_SOURCE_DIR}/../bin"
)
endforeach()
2 changes: 1 addition & 1 deletion toolbox/lib/CompileSplinesLib.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

NAMES = {
'SplineSetMexWrapper', ...
'BaseHermiteWrapper', ...
'BaseHermiteMexWrapper', ...
'SplineVecMexWrapper', ...
'Spline1DMexWrapper', ...
'Spline2DMexWrapper' ...
Expand Down
21 changes: 21 additions & 0 deletions toolbox/lib/CompileSplinesLib_cmake.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
clear all;
clear functions;
clear mex;
clc;

if ismac
oldPath = getenv('PATH');
newPath = strcat(oldPath, pathsep, '/usr/local/bin'); % on MAC
setenv('PATH', newPath);
elseif isunix
elseif ispc
oldPath = getenv('PATH');
newPath = strcat(oldPath, pathsep, 'C:\Program Files\CMake\bin'); % on Windows
setenv('PATH', newPath);
end

old_dir = cd(fileparts(which(mfilename)));
system('cmake -Bbuild .');
system('cmake --build build --parallel 8');
cd(old_dir);

File renamed without changes.

0 comments on commit 721a051

Please sign in to comment.