diff --git a/CMakeLists.txt b/CMakeLists.txt index 5212bd2da8aa31be96977a62d4d9bb875fb4cb3e..d29525a41c2d95cf5d685247ccf6e29c4ff49a85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,26 +53,48 @@ if(AUTOFORMATTING) endif() +####################################################### +### Build utility library +####################################################### +# The library will be called maoxdb until we find a better name. The name is not very important +# though, since the library is used only internally. + +execute_process(COMMAND mkoctfile -p OCTINCLUDEDIR + OUTPUT_VARIABLE OCTINCLUDEDIR + ) +string(REGEX REPLACE "\n" "" OCTINCLUDEDIR "${OCTINCLUDEDIR}") + +set(MAOXDB_DIR "${PROJECT_SOURCE_DIR}/src/lib") +add_library(maoxdb STATIC "${MAOXDB_DIR}/test.cpp") +set_target_properties(maoxdb PROPERTIES PUBLIC_HEADER "${MAOXDB_DIR}/maoxdb.hpp") +message(STATUS "-----\n${FLAGS_MEX_I}") +target_compile_options(maoxdb PRIVATE "-I${OCTINCLUDEDIR}") + + ####################################################### ### Compile into *.mex files ####################################################### +# Only files in src/private will be compiled. This is to separate the non-mex files in src/lib; if +# this is to change, the GLOB_RECURSE code needs to be changed. + add_subdirectory(src) set(PKG_INST_DIR "${PROJECT_SOURCE_DIR}/inst") file(MAKE_DIRECTORY ${PKG_INST_DIR}) # Options for mex compilation -string(REGEX REPLACE ";" ";-I" _MKOCTFILE_INCLUDES "-I${CONAN_INCLUDE_DIRS}") -string(REGEX REPLACE ";" ";-L" _MKOCTFILE_LIB_DIRS "-L${CONAN_LIB_DIRS}") +string(REGEX REPLACE ";" ";-I" _MKOCTFILE_INCLUDES "-I${CONAN_INCLUDE_DIRS};${MAOXDB_DIR}") +string(REGEX REPLACE ";" ";-L" _MKOCTFILE_LIB_DIRS "-L${CONAN_LIB_DIRS};-L;${MAOXDB_DIR}") string(REGEX REPLACE ";" ";-l" _MKOCTFILE_LIBS "-l${CONAN_LIBS}") string(REGEX REPLACE ";" ":" _MKOCTFILE_RPATH "${CONAN_LIB_DIRS}") set(_MKOCTFILE_OPTIONS "-Wl,-rpath,${_MKOCTFILE_RPATH}" "--mex" "-std=gnu++17" "-L/usr/local/lib" ${_MKOCTFILE_INCLUDES} ${_MKOCTFILE_LIB_DIRS} ${_MKOCTFILE_LIBS}) -add_custom_target(mex ALL) -file(GLOB_RECURSE _CPP_SOURCES RELATIVE "${PROJECT_SOURCE_DIR}/src" src/*.cpp) +add_custom_target(mex ALL + DEPENDS maoxdb) +file(GLOB_RECURSE _CPP_SOURCES RELATIVE "${PROJECT_SOURCE_DIR}/src" src/private/*.cpp) foreach(sourcefile ${_CPP_SOURCES}) string(REGEX REPLACE ".cpp$" ".mex" _mex_ext_file ${sourcefile}) - STRING(REGEX REPLACE "/" "__" _target_name "${sourcefile}") + string(REGEX REPLACE "/" "__" _target_name "${sourcefile}") set(_mex_ext_file "${PKG_INST_DIR}/${_mex_ext_file}") set(_mkoct_output "-o" "${_mex_ext_file}") set(_abs_source "${PROJECT_SOURCE_DIR}/src/${sourcefile}") @@ -91,11 +113,6 @@ endforeach(sourcefile) ####################################################### option(LINTING "clang-tidy and iwyu" OFF) if(LINTING) - execute_process(COMMAND mkoctfile -p OCTINCLUDEDIR - OUTPUT_VARIABLE _OCTINCLUDEDIR - ) - string(REGEX REPLACE "\n" "" _OCTINCLUDEDIR "${_OCTINCLUDEDIR}") - find_program(clang_tidy NAMES clang-tidy clang-tidy-11) if(NOT clang_tidy) message(WARNING "clang-tidy: Not found") @@ -113,7 +130,7 @@ if(LINTING) COMMAND ${clang_tidy} ARGS ${_CMAKE_CXX_CLANG_TIDY} ${_CMAKE_CXX_CLANG_TIDY_CHECKS} ${OCTAVE_CAOSDB_SRC} "--" ${_MKOCTFILE_INCLUDES} "-I/usr/include" - "-I${_OCTINCLUDEDIR}" "-std=c++17" + "-I${OCTINCLUDEDIR}" "-std=c++17" DEPENDS ${OCTAVE_CAOSDB_SRC}) endif() @@ -131,7 +148,7 @@ if(LINTING) add_custom_command( TARGET caosdb.mex COMMAND ${iwyu} - ARGS ${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE} "-I${_OCTINCLUDEDIR}" + ARGS ${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE} "-I${OCTINCLUDEDIR}" "-std=c++17" "-I/usr/include" ${_MKOCTFILE_INCLUDES} ${OCTAVE_CAOSDB_SRC} "||" "true" DEPENDS ${OCTAVE_CAOSDB_SRC}) diff --git a/src/caosdbClass.m b/src/caosdbClass.m index a282e1eb6de346542b7a0ff89fea44aa9772857c..eba38525652276b47b73c77691206dae058962f3 100644 --- a/src/caosdbClass.m +++ b/src/caosdbClass.m @@ -16,8 +16,13 @@ classdef caosdbClass < handle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function res = info(obj) disp(["connection: >", obj.connection, "<"]); - info_result = _info(obj.connection); - res = info_result; + try + info_result = _info(obj.connection); + res = info_result; + catch + disp("some error!") + res = NA + end_try_catch endfunction endmethods endclassdef diff --git a/src/private/maoxdbUtils.hpp b/src/lib/maoxdb.hpp similarity index 78% rename from src/private/maoxdbUtils.hpp rename to src/lib/maoxdb.hpp index 1f68dade79877457f4e7c16aa19a3b031ae76ef2..c2e93c31e89d20d2a1f8cd173f52eefa11eec807 100644 --- a/src/private/maoxdbUtils.hpp +++ b/src/lib/maoxdb.hpp @@ -1,9 +1,11 @@ -#ifndef MAOXDBUTILS_H -#define MAOXDBUTILS_H +#ifndef MAOXDB_H +#define MAOXDB_H #include "mex.h" #include "mexproto.h" +// Macros ///////////////////////////////////////////////////////////////////// + /** * mxSCALAR(type, name, value): Create a 1x1 mxArray of type TYPE and value * VALUE. The NAME must be unique within each scope. @@ -26,4 +28,8 @@ __##name##_data[0] = value; \ mxSetData(name, __##name##_data) -#endif /* MAOXDBUTILS_H */ +// Utility functions ////////////////////////////////////////////////////////// + +void test(); + +#endif /* MAOXDB_H */ diff --git a/src/lib/test.cpp b/src/lib/test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6b5449cb35bb6825564c644e30039fb3506e272e --- /dev/null +++ b/src/lib/test.cpp @@ -0,0 +1,8 @@ +#include "maoxdb.hpp" +#include "mex.h" +#include "mexproto.h" + +void test() { + // do nothing. + auto *mx_str = mxCreateString("Hello World!"); +} diff --git a/src/private/_info.cpp b/src/private/_info.cpp index cdd248f6c32084a70473d3184111531635a377b5..26b294686765d3aeae28a8cd5617b92cd2528e6f 100644 --- a/src/private/_info.cpp +++ b/src/private/_info.cpp @@ -1,12 +1,13 @@ #include "caosdb/connection.h" // for Connection, ConnectionManager #include "caosdb/constants.h" // for LIBCAOSDB_VERSION_MAJOR, LIBCAOSDB_VE... +#include "caosdb/exceptions.h" // for all error handling #include "caosdb/info.h" // for VersionInfo -#include "maoxdbUtils.hpp" // caosDB utils for mex files #include "mex.h" // for mxArray, mexFunction #include "mexproto.h" // for mexPrintf, mxCreateString, mxGetChars #include <cstring> // for strcmp #include <memory> // for unique_ptr, __shared_ptr_access, shar... #include <string> // for allocator, char_traits, operator+ +#include "maoxdb.hpp" // caosDB utils for mex files using caosdb::connection::Connection; using caosdb::connection::ConnectionManager; @@ -60,6 +61,12 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { conn_name = mxGetChars(prhs[0]); } mexPrintf("Connection: >%s< \t %d\n", conn_name.c_str(), nrhs); - auto info_struct = info(conn_name); - plhs[0] = info_struct; + try { + auto info_struct = info(conn_name); + plhs[0] = info_struct; + } catch (const std::runtime_error &err) { + mexPrintf("Some exception!"); + mexErrMsgIdAndTxt("someID", err.what()); + } + test(); }