Skip to content

Commit

Permalink
fix matlab regexp parser issue (#135)
Browse files Browse the repository at this point in the history
* fix matlab regexp parser issue

Signed-off-by: Andrey Parfenov <[email protected]>
  • Loading branch information
Andrey1994 authored Mar 27, 2020
1 parent 6bc107e commit 4e246c1
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ add_library (
target_include_directories (
${BRAINFLOW_CPP_BINDING_NAME} PRIVATE
${CMAKE_HOME_DIRECTORY}/src/board_controller/inc
${CMAKE_HOME_DIRECTORY}/src/utils/inc
${CMAKE_HOME_DIRECTORY}/src/data_handler/inc
${CMAKE_HOME_DIRECTORY}/cpp-package/src/inc
${CMAKE_HOME_DIRECTORY}/third_party/json
Expand All @@ -261,6 +262,7 @@ if (MSVC)
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/board_controller.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/board_controller.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/board_info_getter.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/board_info_getter.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_constants.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/brainflow_constants.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/utils/inc/shared_export_matlab.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/shared_export.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/third_party/neurosdk/lib/${NEUROSDK_LIB_NAME}.dll" "${CMAKE_HOME_DIRECTORY}/csharp-package/brainflow/brainflow/lib/${NEUROSDK_LIB_NAME}.dll"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/third_party/neurosdk/lib/${NEUROSDK_LIB_NAME}.dll" "${CMAKE_HOME_DIRECTORY}/python-package/brainflow/lib/${NEUROSDK_LIB_NAME}.dll"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/third_party/neurosdk/lib/${NEUROSDK_LIB_NAME}.dll" "${CMAKE_HOME_DIRECTORY}/java-package/brainflow/src/main/resources/${NEUROSDK_LIB_NAME}.dll"
Expand All @@ -274,6 +276,7 @@ if (MSVC)
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/compiled/$<CONFIG>/${DATA_HANDLER_COMPILED_NAME}" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/lib/${DATA_HANDLER_COMPILED_NAME}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_constants.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/brainflow_constants.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/data_handler/inc/data_handler.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/data_handler.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/utils/inc/shared_export_matlab.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/shared_export.h"
)
endif (MSVC)
if (UNIX)
Expand All @@ -284,6 +287,7 @@ if (UNIX)
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/compiled/${BOARD_CONTROLLER_COMPILED_NAME}" "${CMAKE_HOME_DIRECTORY}/csharp-package/brainflow/brainflow/${BOARD_CONTROLLER_COMPILED_NAME}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/board_controller.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/board_controller.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/board_info_getter.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/board_info_getter.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/utils/inc/shared_export_matlab.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/shared_export.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_constants.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/brainflow_constants.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/compiled/${BOARD_CONTROLLER_COMPILED_NAME}" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/lib/${BOARD_CONTROLLER_COMPILED_NAME}"
)
Expand All @@ -294,6 +298,7 @@ if (UNIX)
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/compiled/${DATA_HANDLER_COMPILED_NAME}" "${CMAKE_HOME_DIRECTORY}/csharp-package/brainflow/brainflow/lib/${DATA_HANDLER_COMPILED_NAME}"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_constants.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/brainflow_constants.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/data_handler/inc/data_handler.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/data_handler.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/src/utils/inc/shared_export_matlab.h" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/inc/shared_export.h"
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${CMAKE_HOME_DIRECTORY}/compiled/${DATA_HANDLER_COMPILED_NAME}" "${CMAKE_HOME_DIRECTORY}/matlab-package/brainflow/lib/${DATA_HANDLER_COMPILED_NAME}"
)
endif (UNIX)
Expand Down Expand Up @@ -343,6 +348,7 @@ install (
${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_constants.h
${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/board_info_getter.h
${CMAKE_HOME_DIRECTORY}/src/board_controller/inc/brainflow_input_params.h
${CMAKE_HOME_DIRECTORY}/src/utils/inc/shared_export.h
${CMAKE_HOME_DIRECTORY}/src/data_handler/inc/data_handler.h
${CMAKE_HOME_DIRECTORY}/cpp-package/src/inc/data_filter.h
${CMAKE_HOME_DIRECTORY}/cpp-package/src/inc/board_shim.h
Expand Down
10 changes: 7 additions & 3 deletions docs/BuildBrainFlow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ You are able to download jar files directly from `release page <https://github.c
Matlab
--------

To use Matlab binding you HAVE to build core module first.
After compilation of core module you will be able to open brainflow/matlab-package/brainflow folder in Matlab IDE, add examples folder to Matlab's path and run them.
Steps to setup Matlab binding for BrainFlow:

Compilation of Core module and C++ binding
- Compile Core Module, using instructions below
- Open Matlab IDE and open brainflow/matlab-package/brainflow folder there
- Add folders lib and inc to Matlab path
- If you want to run Matlab scripts from folders different than brainflow/matlab-package/brainflow you need to add it to your Matlab path too

Compilation of Core Module and C++ Binding
-------------------------------------------

Windows
Expand Down
6 changes: 6 additions & 0 deletions docs/UserAPI.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,9 @@ Matlab API Reference
----------------------

Matlab binding calls C\C++ code as any other binding, it's not compatible with Octave. Use our code samples as a reference for Matlab API.

A few general rules to keep in mind:

- Use char arrays instead strings to work with BrainFlow API, it means 'my_string' instead "my_string", otherwise you will get calllib error
- Use int32 values intead enums, it means int32 (BoardIDs.SYNTHETIC_BOARD) instead BoardIDs.SYNTHETIC_BOARD, the same is true for all enums in BrainFlow API

6 changes: 3 additions & 3 deletions matlab-package/brainflow/BoardShim.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
function lib_name = load_lib ()
if ispc
if not (libisloaded ('BoardController'))
loadlibrary ('./lib/BoardController.dll', './inc/board_controller.h', 'includepath', './inc', 'addheader', 'board_info_getter');
loadlibrary ('BoardController.dll', 'board_controller.h', 'addheader', 'board_info_getter');
end
lib_name = 'BoardController';
elseif ismac
if not (libisloaded ('libBoardController'))
loadlibrary ('./lib/libBoardController.dylib', './inc/board_controller.h', 'includepath', './inc', 'addheader', 'board_info_getter');
loadlibrary ('libBoardController.dylib', 'board_controller.h', 'addheader', 'board_info_getter');
end
lib_name = 'libBoardController';
elseif isunix
if not (libisloaded ('libBoardController'))
loadlibrary ('./liblibBoardController.so', './inc/board_controller.h', 'includepath', './inc', 'addheader', 'board_info_getter');
loadlibrary ('libBoardController.so', 'board_controller.h', 'addheader', 'board_info_getter');
end
lib_name = 'libBoardController';
else
Expand Down
6 changes: 3 additions & 3 deletions matlab-package/brainflow/DataFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
function lib_name = load_lib ()
if ispc
if not (libisloaded ('DataHandler'))
loadlibrary ('./lib/DataHandler.dll', './inc/data_handler.h', 'includepath', './inc');
loadlibrary ('DataHandler.dll', 'data_handler.h');
end
lib_name = 'DataHandler';
elseif ismac
if not (libisloaded ('libDataHandler'))
loadlibrary ('./lib/libDataHandler.dylib', './inc/data_handler.h', 'includepath', './inc');
loadlibrary ('libDataHandler.dylib', 'data_handler.h');
end
lib_name = 'libDataHandler';
elseif isunix
if not (libisloaded ('libDataHandler'))
loadlibrary ('./lib/libDataHandler.so', './inc/data_handler.h', 'includepath', './inc');
loadlibrary ('libDataHandler.so', 'data_handler.h');
end
lib_name = 'libDataHandler';
else
Expand Down
9 changes: 1 addition & 8 deletions src/board_controller/inc/board_controller.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#pragma once

#ifdef _WIN32
#define SHARED_EXPORT __declspec(dllexport)
#define CALLING_CONVENTION __cdecl
#else
#define SHARED_EXPORT __attribute__ ((visibility ("default")))
#define CALLING_CONVENTION
#endif

#include "board_info_getter.h"
#include "brainflow_constants.h"
#include "shared_export.h"


#ifdef __cplusplus
Expand Down
8 changes: 1 addition & 7 deletions src/board_controller/inc/board_info_getter.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#pragma once

#ifdef _WIN32
#define SHARED_EXPORT __declspec(dllexport)
#define CALLING_CONVENTION __cdecl
#else
#define SHARED_EXPORT __attribute__ ((visibility ("default")))
#define CALLING_CONVENTION
#endif
#include "shared_export.h"

#ifdef __cplusplus
extern "C"
Expand Down
9 changes: 1 addition & 8 deletions src/data_handler/inc/data_handler.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
#pragma once

#ifdef _WIN32
#define SHARED_EXPORT __declspec(dllexport)
#define CALLING_CONVENTION __cdecl
#else
#define SHARED_EXPORT __attribute__ ((visibility ("default")))
#define CALLING_CONVENTION
#endif

#include "brainflow_constants.h"
#include "shared_export.h"

#define MAX_FILTER_ORDER 8 // define it here to show in the docs

Expand Down
9 changes: 9 additions & 0 deletions src/utils/inc/shared_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#ifdef _WIN32
#define SHARED_EXPORT __declspec(dllexport)
#define CALLING_CONVENTION __cdecl
#else
#define SHARED_EXPORT __attribute__ ((visibility ("default")))
#define CALLING_CONVENTION
#endif
12 changes: 12 additions & 0 deletions src/utils/inc/shared_export_matlab.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

// matlab uses regexp to parse headers and find function declarations
// this regexp doesnt work with __attribute__ ((visibility ("default"))), solution - build all code
// using shared_export.h but copypaste this file to matlab headers parser instead shared_export.h
#ifdef _WIN32
#define SHARED_EXPORT __declspec(dllexport)
#define CALLING_CONVENTION __cdecl
#else
#define SHARED_EXPORT
#define CALLING_CONVENTION
#endif

0 comments on commit 4e246c1

Please sign in to comment.