Skip to content

Commit a3f4d0d

Browse files
authored
re-organize project and add Octave-version (#7)
1 parent 9cdca8d commit a3f4d0d

File tree

80 files changed

+2367
-1875
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2367
-1875
lines changed

.github/workflows/build.yml

Lines changed: 93 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ jobs:
2424
matrix:
2525
os: [ubuntu-latest, windows-latest] # Windows and Linux builds
2626
outputs:
27-
linuxx64_artifact: ${{ steps.prepare_linux_artifact.outputs.linuxx64_build }}
28-
windowsx64_artifact: ${{ steps.prepare_windows_artifact.outputs.windowsx64_build }}
27+
linuxx64_matlab_artifact: ${{ steps.prepare_linux_artifact.outputs.linuxx64_matlab_build }}
28+
linuxx64_octave_artifact: ${{ steps.prepare_linux_artifact.outputs.linuxx64_octave_build }}
29+
windowsx64_matlab_artifact: ${{ steps.prepare_windows_matlab_artifact.outputs.windowsx64_matlab_build }}
30+
windowsx64_octave_artifact: ${{ steps.prepare_windows_octave_artifact.outputs.windowsx64_octave_build }}
2931
steps:
3032
- name: Check out repository
3133
uses: actions/checkout@v4
@@ -47,33 +49,104 @@ jobs:
4749
cd build
4850
cmake .. -DCMAKE_BUILD_TYPE=Release
4951
cmake --build . --config Release -j
50-
- name: Prepare artifact (Linux)
51-
id: prepare_linux_artifact
52+
- name: Prepare MATLAB artifact (Linux)
53+
id: prepare_linux_matlab_artifact
5254
if: runner.os == 'Linux'
5355
shell: bash
5456
run: |
5557
mkdir -p artifacts
56-
name="MEXlibCZI-linux-x64-$(git describe --always)"
58+
name="MATLAB-MEXlibCZI-linux-x64-$(git describe --always)"
5759
mkdir -p artifacts/${name}
5860
cp build/MEXlibCZI/MEXlibCZI.mexa64 artifacts/${name}/
5961
echo "artifactName=${name}" >> "$GITHUB_ENV"
6062
echo "artifactPath=artifacts/${name}" >> "$GITHUB_ENV"
61-
#echo "::set-output name=linuxx64_build::${name}"
62-
echo "linuxx64_build=${name}" >> $GITHUB_OUTPUT
63-
- name: Prepare artifact (Windows)
64-
id: prepare_windows_artifact
63+
echo "linuxx64_matlab_build=${name}" >> "$GITHUB_OUTPUT"
64+
- name: install Octave (Windows)
65+
if: runner.os == 'Windows'
66+
shell: bash
67+
run: |
68+
choco install octave --no-progress
69+
# I am not sure how to find the octave-cli-executable now, so we search for the link in the start menu
70+
search_dir="/c/ProgramData/Microsoft/Windows/Start Menu/Programs"
71+
octave_link=$(find "$search_dir" -type f -name "Octave*CLI*.lnk" 2>/dev/null)
72+
octave_link_windows_path=$(cygpath -w "$octave_link")
73+
echo "octave_link=$octave_link"
74+
echo "octave_link_windows_path=$octave_link_windows_path"
75+
echo "OCTAVECLI_LINK=$octave_link_windows_path" >> "$GITHUB_ENV"
76+
- name: install Octave (Linux)
77+
if: runner.os == 'Linux'
78+
shell: bash
79+
run: |
80+
sudo apt install -y -qq -o=Dpkg::Progress-Fancy="0" octave liboctave-dev
81+
- name: build Octave mex-file (Windows)
82+
if: runner.os == 'Windows'
83+
shell: cmd
84+
run: |
85+
REM We compile the mex file for Octave within Octave itself, this seems the easiest way. The
86+
REM downside is that installing octave takes a long time.
87+
REM Note that we are using cmd.exe here, because it can "execute" the .lnk file.
88+
"%OCTAVECLI_LINK%" --version
89+
REM echo "cd %GITHUB_WORKSPACE%/OctaveMex , mkoctfile --mex octavelibczi.c"
90+
set "GITHUB_WORKSPACE_FORWARD_SLASHES=%GITHUB_WORKSPACE:\=/%
91+
"%OCTAVECLI_LINK%" --eval "cd %GITHUB_WORKSPACE_FORWARD_SLASHES%/OctaveMex , mkoctfile --mex octavelibczi.c"
92+
REM now, copy the libmexlibczi.dll to this folder
93+
echo "*** directory listing of build\libmexlibczi\Release ***"
94+
dir build\libmexlibczi\Release\
95+
copy /B build\libmexlibczi\Release\libmexlibczi.dll %GITHUB_WORKSPACE%\OctaveMex
96+
echo "*** directory listing of %GITHUB_WORKSPACE%\OctaveMex ***"
97+
dir %GITHUB_WORKSPACE%\OctaveMex
98+
- name: build Octave mex-file (Linux)
99+
if: runner.os == 'Linux'
100+
shell: bash
101+
run: |
102+
cd OctaveMex
103+
octave --version
104+
octave --eval "mkoctfile --mex octavelibczi.c"
105+
cp ../build/libmexlibczi/libmexlibczi.so . # now, copy the libmexlibczi.so to this folder
106+
- name: Prepare MATLAB-mex artifact (Windows)
107+
id: prepare_windows_matlab_artifact
65108
if: runner.os == 'Windows'
66109
shell: bash
67110
run: |
68111
mkdir -p artifacts
69-
name="MEXlibCZI-windows-x64-$(git describe --always)"
112+
name="MATLAB-MEXlibCZI-windows-x64-$(git describe --always)"
70113
mkdir -p artifacts/${name}
71114
cp build/MEXlibCZI/Release/MEXlibCZI.mexw64 artifacts/${name}/
72115
echo "artifactName=${name}" >> "$GITHUB_ENV"
73116
echo "artifactPath=artifacts/${name}" >> "$GITHUB_ENV"
74-
#echo "::set-output name=windowsx64_build::${name}"
75-
echo "windowsx64_build=${name}" >> $GITHUB_OUTPUT
76-
- name: Upload artifacts
117+
echo "windowsx64_matlab_build=${name}" >> $GITHUB_OUTPUT
118+
- name: Upload MATLAB-mex artifacts
119+
uses: actions/upload-artifact@v4
120+
with:
121+
path: ${{ env.artifactPath }}/
122+
name: ${{ env.artifactName }}
123+
- name: Prepare Octave-mex artifact (Windows)
124+
id: prepare_windows_octave_artifact
125+
if: runner.os == 'Windows'
126+
shell: bash
127+
run: |
128+
mkdir -p artifacts
129+
name="Octave-MEXlibCZI-windows-x64-$(git describe --always)"
130+
mkdir -p artifacts/${name}
131+
cp $(cygpath "${GITHUB_WORKSPACE}")/OctaveMex/libmexlibczi.dll artifacts/${name}/
132+
cp $(cygpath "${GITHUB_WORKSPACE}")/OctaveMex/octavelibczi.mex artifacts/${name}/
133+
echo "artifactName=${name}" >> "$GITHUB_ENV"
134+
echo "artifactPath=artifacts/${name}" >> "$GITHUB_ENV"
135+
echo "windowsx64_octave_build=${name}" >> $GITHUB_OUTPUT
136+
- name: Prepare Octave-mex artifact (Linux)
137+
id: prepare_linux_octave_artifact
138+
if: runner.os == 'Linux'
139+
shell: bash
140+
run: |
141+
mkdir -p artifacts
142+
name="Octave-MEXlibCZI-linux-x64-$(git describe --always)"
143+
mkdir -p artifacts/${name}
144+
cp ${GITHUB_WORKSPACE}/OctaveMex/libmexlibczi.so artifacts/${name}/
145+
cp ${GITHUB_WORKSPACE}/OctaveMex/octavelibczi.mex artifacts/${name}/
146+
echo "artifactName=${name}" >> "$GITHUB_ENV"
147+
echo "artifactPath=artifacts/${name}" >> "$GITHUB_ENV"
148+
echo "linuxx64_octave_build=${name}" >> $GITHUB_OUTPUT
149+
- name: Upload Octave-mex artifacts
77150
uses: actions/upload-artifact@v4
78151
with:
79152
path: ${{ env.artifactPath }}/
@@ -88,7 +161,7 @@ jobs:
88161
- name: Check out repository
89162
uses: actions/checkout@v4
90163
- name: Download All Artifacts
91-
if: needs.build.outputs.linuxx64_artifact != '' || needs.build.outputs.windowsx64_artifact != ''
164+
if: needs.build.outputs.linuxx64_matlab_artifact != '' || needs.build.outputs.windowsx64_matlab_artifact != '' || needs.build.outputs.linuxx64_octave_artifact != '' || needs.build.outputs.windowsx64_octave_artifact != ''
92165
uses: actions/download-artifact@v4
93166
with:
94167
path: ./artifacts # download to a specific folder
@@ -108,7 +181,11 @@ jobs:
108181
name: ${{ env.releaseName }}
109182
tag_name: ${{ env.tagName }}
110183
files: |
111-
./artifacts/${{ needs.build.outputs.linuxx64_artifact }}/MEXlibCZI.mexa64
112-
./artifacts/${{ needs.build.outputs.windowsx64_artifact }}/MEXlibCZI.mexw64
184+
./artifacts/${{ needs.build.outputs.linuxx64_matlab_artifact }}/MEXlibCZI.mexa64
185+
./artifacts/${{ needs.build.outputs.windowsx64_matlab_artifact }}/MEXlibCZI.mexw64
186+
./artifacts/${{ needs.build.outputs.linuxx64_octave_artifact }}/octavelibczi.mex
187+
./artifacts/${{ needs.build.outputs.linuxx64_octave_artifact }}/libmexlibczi.so
188+
./artifacts/${{ needs.build.outputs.windowsx64_octave_artifact }}/octavelibczi.mex
189+
./artifacts/${{ needs.build.outputs.windowsx64_octave_artifact }}/libmexlibczi.dll
113190
prerelease: true
114191

AppModel/include/app_api.h

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#include <stdint.h>
8+
#include <stdbool.h>
9+
#include <stddef.h>
10+
11+
/// This type is representing a "parameter", which is the abstraction of "some object" in Matlab/Octave.
12+
/// With Matlab, it maps to mxArray*. It is to be regarded as an opaque type.
13+
typedef void* Parameter;
14+
15+
enum AppExtensionClassId
16+
{
17+
AppExtensionClassId_Unknown,
18+
AppExtensionClassId_Uint8,
19+
AppExtensionClassId_Int8,
20+
AppExtensionClassId_Uint16,
21+
AppExtensionClassId_Int16,
22+
AppExtensionClassId_Uint32,
23+
AppExtensionClassId_Int32,
24+
AppExtensionClassId_Uint64,
25+
AppExtensionClassId_Int64,
26+
AppExtensionClassId_Double,
27+
AppExtensionClassId_Single,
28+
AppExtensionClassId_Logical,
29+
};
30+
31+
struct IAppExtensionFunctions
32+
{
33+
bool (*pfn_IsNanOrInfDouble)(double d);
34+
35+
bool (*pfn_IsNanOrInfSingle)(float f);
36+
37+
double (*pfn_GetInfDouble)(void);
38+
39+
double (*pfn_GetNaNDouble)(void);
40+
41+
void* (*pfn_GetData)(const Parameter parameter);
42+
43+
uint8_t* (*pfn_GetUint8s)(const Parameter parameter);
44+
45+
int8_t* (*pfn_GetInt8s)(const Parameter parameter);
46+
47+
uint16_t* (*pfn_GetUint16s)(const Parameter parameter);
48+
49+
int16_t* (*pfn_GetInt16s)(const Parameter parameter);
50+
51+
uint32_t* (*pfn_GetUint32s)(const Parameter parameter);
52+
53+
int32_t* (*pfn_GetInt32s)(const Parameter parameter);
54+
55+
uint64_t* (*pfn_GetUint64s)(const Parameter parameter);
56+
57+
int64_t* (*pfn_GetInt64s)(const Parameter parameter);
58+
59+
double* (*pfn_GetDoubles)(const Parameter parameter);
60+
61+
float* (*pfn_GetSingles)(const Parameter parameter);
62+
63+
bool* (*pfn_GetLogicals)(const Parameter parameter);
64+
65+
bool (*pfn_IsNumeric)(const Parameter parameter);
66+
67+
bool (*pfn_IsChar)(const Parameter parameter);
68+
69+
bool (*pfn_IsSparse)(const Parameter parameter);
70+
71+
bool (*pfn_IsStruct)(const Parameter parameter);
72+
73+
Parameter(*pfn_CreateString)(const char* string);
74+
75+
void (*pfn_ReportErrorAndRaiseSignal)(const char* identifier, const char* message);
76+
77+
char* (*pfn_StrDupHostAllocated)(const char* string);
78+
79+
Parameter(*pfn_CreateStructArray)(size_t ndim, const size_t* dims, int nfields, const char** field_names);
80+
81+
void (*pfn_SetFieldByNumber)(Parameter pa, size_t i, int fieldnum, Parameter value);
82+
83+
char* (*pfn_ConvertToUTF8String)(const Parameter parameter);
84+
85+
void (*pfn_Free)(void* ptr);
86+
87+
Parameter(*pfn_CreateNumericMatrixReal)(size_t m, size_t n, enum AppExtensionClassId class_id);
88+
89+
enum AppExtensionClassId(*pfn_GetClassId)(const Parameter parameter);
90+
91+
size_t(*pfn_GetNumberOfElements)(const Parameter parameter);
92+
93+
size_t(*pfn_GetNumberOfDimensions)(const Parameter parameter);
94+
95+
void (*pfn_GetSizeOfDimensions)(const Parameter parameter, size_t number_of_dimension, size_t* sizes);
96+
97+
Parameter(*pfn_GetField)(const Parameter parameter, const char* field_name);
98+
99+
Parameter(*pfn_CreateNumericArrayReal)(size_t ndim, const size_t* dims, enum AppExtensionClassId class_id);
100+
};
101+
102+
#ifdef __cplusplus
103+
}
104+
#endif

CMakeLists.txt

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#
44
cmake_minimum_required (VERSION 3.11)
55

6-
set(MEXCZI_MAJOR 0)
7-
set(MEXCZI_MINOR 2)
8-
set(MEXCZI_PATCH 1)
9-
set(MEXCZI_EXT "alpha")
6+
set(MEXLIBCZI_MAJOR 0)
7+
set(MEXLIBCZI_MINOR 3)
8+
set(MEXLIBCZI_PATCH 0)
9+
set(MEXLIBCZI_EXT "alpha")
1010

1111
if(WIN32)
1212
# use "static C-runtime" -> https://stackoverflow.com/questions/14172856/compile-with-mt-instead-of-md-using-cmake
@@ -17,45 +17,51 @@ endif(WIN32)
1717

1818
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules" ${CMAKE_MODULE_PATH})
1919

20-
project ("MEXlibCZI")
20+
project ("MEXlibCZI"
21+
VERSION ${MEXLIBCZI_MAJOR}.${MEXLIBCZI_MINOR}.${MEXLIBCZI_PATCH}
22+
DESCRIPTION "mex extension (for MATLAB and Octave) for reading/writing CZI-files with libCZI")
23+
24+
# Options controlling the CMake-build are gathered here
25+
option(MEXLIBCZI_BUILD_MATLABMEX "Build the mex extension for MATLAB" ON)
2126

2227
# include RapidJSON -> https://www.jibbow.com/posts/rapidjson-cmake/
2328
include("${CMAKE_SOURCE_DIR}/modules/rapidJSON.cmake")
2429

25-
2630
include("${CMAKE_SOURCE_DIR}/modules/libCZI.cmake")
2731
FetchContent_GetProperties(libCZI)
2832
set(LIBCZI_INCLUDE_DIR "${libczi_SOURCE_DIR}/Src/libCZI")
2933
message(STATUS ${LIBCZI_INCLUDE_DIR})
3034

31-
if(MEXLIBCZI_HEADERS)
32-
set(Matlab_INCLUDE_DIRS ${MEXLIBCZI_HEADERS})
33-
if(UNIX)
34-
set(Matlab_MEX_LIBRARY ${MEXLIBCZI_LIBS}/libmex.so)
35-
set(Matlab_MX_LIBRARY ${MEXLIBCZI_LIBS}/libmx.so)
36-
else()
37-
set(Matlab_MEX_LIBRARY ${MEXLIBCZI_LIBS}/libmex.lib)
38-
set(Matlab_MX_LIBRARY ${MEXLIBCZI_LIBS}/libmx.lib)
39-
endif()
40-
else()
41-
find_package(Matlab REQUIRED)
42-
endif()
35+
if (MEXLIBCZI_BUILD_MATLABMEX)
36+
if(MEXLIBCZI_HEADERS)
37+
set(Matlab_INCLUDE_DIRS ${MEXLIBCZI_HEADERS})
38+
if(UNIX)
39+
set(Matlab_MEX_LIBRARY ${MEXLIBCZI_LIBS}/libmex.so)
40+
set(Matlab_MX_LIBRARY ${MEXLIBCZI_LIBS}/libmx.so)
41+
else()
42+
set(Matlab_MEX_LIBRARY ${MEXLIBCZI_LIBS}/libmex.lib)
43+
set(Matlab_MX_LIBRARY ${MEXLIBCZI_LIBS}/libmx.lib)
44+
endif()
45+
else()
46+
find_package(Matlab REQUIRED)
47+
endif()
4348

44-
message("########################################")
45-
message(STATUS "Matlab_ROOT_DIR: " ${Matlab_ROOT_DIR})
46-
message(STATUS "Matlab_INCLUDE_DIR: " ${Matlab_INCLUDE_DIRS})
47-
message(STATUS "Matlab_MEX_LIBRARY: " ${Matlab_MEX_LIBRARY})
48-
message(STATUS "Matlab_MX_LIBRARY: " ${Matlab_MX_LIBRARY})
49-
message(STATUS "Matlab_LIBRARIES: " ${Matlab_LIBRARIES})
50-
message("########################################")
49+
message("########################################")
50+
message(STATUS "Matlab_ROOT_DIR: " ${Matlab_ROOT_DIR})
51+
message(STATUS "Matlab_INCLUDE_DIR: " ${Matlab_INCLUDE_DIRS})
52+
message(STATUS "Matlab_MEX_LIBRARY: " ${Matlab_MEX_LIBRARY})
53+
message(STATUS "Matlab_MX_LIBRARY: " ${Matlab_MX_LIBRARY})
54+
message(STATUS "Matlab_LIBRARIES: " ${Matlab_LIBRARIES})
55+
message("########################################")
56+
endif()
5157

58+
# build the static library containing the MEX functions
59+
add_subdirectory("lib")
5260

53-
#[[
54-
set(OCTAVE_CONFIGEXECUTABLE_PATHHINT "D:/SW/Octave/Octave-5.2.0/mingw64/bin/")
55-
find_package(Octave)
56-
message("########################################")
57-
message(STATUS "OCTAVE_INCLUDE_DIRS: " ${OCTAVE_INCLUDE_DIRS})
58-
message("########################################")
59-
]]
61+
if (MEXLIBCZI_BUILD_MATLABMEX)
62+
# build the Matlab-MEX file
63+
add_subdirectory ("MEXlibCZI")
64+
endif()
6065

61-
add_subdirectory ("MEXlibCZI")
66+
# build a dynamic library containing the MEX functions (which is used by the mex-file for Octave)
67+
add_subdirectory("libmexlibczi")

0 commit comments

Comments
 (0)