Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 15837eb

Browse files
committedMar 3, 2024·
Initial commit
0 parents  commit 15837eb

12 files changed

+640
-0
lines changed
 

‎.clang-format

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
BasedOnStyle: Google
3+
AlignAfterOpenBracket: 'AlwaysBreak'
4+
AllowAllConstructorInitializersOnNextLine: 'false'
5+
AllowAllParametersOfDeclarationOnNextLine: 'false'
6+
AlignConsecutiveMacros: 'true'
7+
AllowShortCaseLabelsOnASingleLine: 'true'
8+
AllowShortFunctionsOnASingleLine: 'None'
9+
AllowShortIfStatementsOnASingleLine: 'Never'
10+
AllowShortLoopsOnASingleLine: 'false'
11+
BreakBeforeBraces: Allman
12+
BinPackArguments: 'false'
13+
BinPackParameters: 'false'
14+
Cpp11BracedListStyle: 'false'
15+
ColumnLimit: 125
16+
NamespaceIndentation: All
17+
SpaceAfterTemplateKeyword: 'false'
18+
SpaceBeforeCtorInitializerColon: 'true'
19+
SpaceBeforeInheritanceColon: 'true'
20+
SpaceBeforeParens: ControlStatements
21+
SpaceBeforeRangeBasedForLoopColon: 'true'
22+
SpaceInEmptyBlock: true
23+
Standard: 'Latest'
24+
...

‎.clang-tidy

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
Checks: '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm-*,-llvmlibc-*'
3+
CheckOptions: [{ key: misc-non-private-member-variables-in-classes, value: IgnoreClassesWithAllMemberVariablesBeingPublic }]
4+
WarningsAsErrors: '*'
5+
HeaderFilterRegex: ''
6+
FormatStyle: none

‎.github/workflows/cmake.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: "CMake build"
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
jobs:
13+
build:
14+
name: ${{ matrix.toolchain }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
toolchain:
20+
- linux-gcc
21+
- macos-clang
22+
- windows-msvc
23+
- windows-mingw
24+
configuration:
25+
- Debug
26+
python-version:
27+
- 3.11
28+
include:
29+
- toolchain: linux-gcc
30+
os: ubuntu-latest
31+
compiler: gcc
32+
- toolchain: macos-clang
33+
os: macos-latest
34+
compiler: clang
35+
- toolchain: windows-msvc
36+
os: windows-latest
37+
compiler: msvc
38+
- toolchain: windows-mingw
39+
os: windows-latest
40+
compiler: mingw
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 5
46+
- name: Setup python environment
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: ${{ matrix.python-version }}
50+
- name: Install python packages
51+
run: |
52+
if [ "${{ matrix.os }}" == "macos-latest" ]; then
53+
echo "/Users/runner/Library/Python/${{ matrix.python-version }}/bin" >> $GITHUB_PATH
54+
fi
55+
pip install --disable-pip-version-check --user "conan>=1.62.0,<2"
56+
- name: Configure (${{ matrix.configuration }})
57+
run: |
58+
if [ "${{ matrix.compiler }}" == "msvc" ]; then
59+
cmake -S . -B build
60+
elif [ "${{ matrix.compiler }}" == "mingw" ]; then
61+
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -G "MinGW Makefiles"
62+
else
63+
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }}
64+
fi
65+
- name: Build with ${{ matrix.compiler }}
66+
run: |
67+
if [ "${{ matrix.compiler }}" == "msvc" ]; then
68+
cmake --build build --config ${{ matrix.configuration }}
69+
else
70+
cmake --build build -- -j8
71+
fi
72+
- name: Test
73+
run: |
74+
cd build && make test

‎.gitignore

+371
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,371 @@
1+
[Bb]uild/*
2+
[Dd]ocs/*
3+
CMakeCache.*
4+
CMakeFiles/*
5+
[Tt]esting/*
6+
7+
### VisualStudioCode ###
8+
.vscode/*
9+
.vscode/settings.json
10+
.vscode/tasks.json
11+
.vscode/launch.json
12+
.vscode/extensions.json
13+
14+
### VisualStudioCode Patch ###
15+
# Ignore all local history of files
16+
.history
17+
18+
### VisualStudio ###
19+
## Ignore Visual Studio temporary files, build results, and
20+
## files generated by popular Visual Studio add-ons.
21+
22+
# User-specific files
23+
*.rsuser
24+
*.suo
25+
*.user
26+
*.userosscache
27+
*.sln.docstates
28+
29+
# User-specific files (MonoDevelop/Xamarin Studio)
30+
*.userprefs
31+
32+
# Mono auto generated files
33+
mono_crash.*
34+
35+
# Build results
36+
[Dd]ebug/
37+
[Dd]ebugPublic/
38+
[Rr]elease/
39+
[Rr]eleases/
40+
x64/
41+
x86/
42+
[Aa][Rr][Mm]/
43+
[Aa][Rr][Mm]64/
44+
bld/
45+
[Bb]in/
46+
[Oo]bj/
47+
[Ll]og/
48+
49+
# Visual Studio 2015/2017 cache/options directory
50+
.vs/
51+
# Uncomment if you have tasks that create the project's static files in wwwroot
52+
#wwwroot/
53+
54+
# Visual Studio 2017 auto generated files
55+
Generated\ Files/
56+
57+
# MSTest test Results
58+
[Tt]est[Rr]esult*/
59+
[Bb]uild[Ll]og.*
60+
61+
# NUnit
62+
*.VisualState.xml
63+
TestResult.xml
64+
nunit-*.xml
65+
66+
# Build Results of an ATL Project
67+
[Dd]ebugPS/
68+
[Rr]eleasePS/
69+
dlldata.c
70+
71+
# Benchmark Results
72+
BenchmarkDotNet.Artifacts/
73+
74+
# .NET Core
75+
project.lock.json
76+
project.fragment.lock.json
77+
artifacts/
78+
79+
# StyleCop
80+
StyleCopReport.xml
81+
82+
# Files built by Visual Studio
83+
*_i.c
84+
*_p.c
85+
*_h.h
86+
*.ilk
87+
*.obj
88+
*.iobj
89+
*.pch
90+
*.pdb
91+
*.ipdb
92+
*.pgc
93+
*.pgd
94+
*.rsp
95+
*.sbr
96+
*.tlb
97+
*.tli
98+
*.tlh
99+
*.tmp
100+
*.tmp_proj
101+
*_wpftmp.csproj
102+
*.log
103+
*.vspscc
104+
*.vssscc
105+
.builds
106+
*.pidb
107+
*.svclog
108+
*.scc
109+
110+
# Chutzpah Test files
111+
_Chutzpah*
112+
113+
# Visual C++ cache files
114+
ipch/
115+
*.aps
116+
*.ncb
117+
*.opendb
118+
*.opensdf
119+
*.sdf
120+
*.cachefile
121+
*.VC.db
122+
*.VC.VC.opendb
123+
124+
# Visual Studio profiler
125+
*.psess
126+
*.vsp
127+
*.vspx
128+
*.sap
129+
130+
# Visual Studio Trace Files
131+
*.e2e
132+
133+
# TFS 2012 Local Workspace
134+
$tf/
135+
136+
# Guidance Automation Toolkit
137+
*.gpState
138+
139+
# ReSharper is a .NET coding add-in
140+
_ReSharper*/
141+
*.[Rr]e[Ss]harper
142+
*.DotSettings.user
143+
144+
# JustCode is a .NET coding add-in
145+
.JustCode
146+
147+
# TeamCity is a build add-in
148+
_TeamCity*
149+
150+
# DotCover is a Code Coverage Tool
151+
*.dotCover
152+
153+
# AxoCover is a Code Coverage Tool
154+
.axoCover/*
155+
!.axoCover/settings.json
156+
157+
# Visual Studio code coverage results
158+
*.coverage
159+
*.coveragexml
160+
161+
# NCrunch
162+
_NCrunch_*
163+
.*crunch*.local.xml
164+
nCrunchTemp_*
165+
166+
# MightyMoose
167+
*.mm.*
168+
AutoTest.Net/
169+
170+
# Web workbench (sass)
171+
.sass-cache/
172+
173+
# Installshield output folder
174+
[Ee]xpress/
175+
176+
# DocProject is a documentation generator add-in
177+
DocProject/buildhelp/
178+
DocProject/Help/*.HxT
179+
DocProject/Help/*.HxC
180+
DocProject/Help/*.hhc
181+
DocProject/Help/*.hhk
182+
DocProject/Help/*.hhp
183+
DocProject/Help/Html2
184+
DocProject/Help/html
185+
186+
# Click-Once directory
187+
publish/
188+
189+
# Publish Web Output
190+
*.[Pp]ublish.xml
191+
*.azurePubxml
192+
# Note: Comment the next line if you want to checkin your web deploy settings,
193+
# but database connection strings (with potential passwords) will be unencrypted
194+
*.pubxml
195+
*.publishproj
196+
197+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
198+
# checkin your Azure Web App publish settings, but sensitive information contained
199+
# in these scripts will be unencrypted
200+
PublishScripts/
201+
202+
# NuGet Packages
203+
*.nupkg
204+
# NuGet Symbol Packages
205+
*.snupkg
206+
# The packages folder can be ignored because of Package Restore
207+
**/[Pp]ackages/*
208+
# except build/, which is used as an MSBuild target.
209+
!**/[Pp]ackages/build/
210+
# Uncomment if necessary however generally it will be regenerated when needed
211+
#!**/[Pp]ackages/repositories.config
212+
# NuGet v3's project.json files produces more ignorable files
213+
*.nuget.props
214+
*.nuget.targets
215+
216+
# Microsoft Azure Build Output
217+
csx/
218+
*.build.csdef
219+
220+
# Microsoft Azure Emulator
221+
ecf/
222+
rcf/
223+
224+
# Windows Store app package directories and files
225+
AppPackages/
226+
BundleArtifacts/
227+
Package.StoreAssociation.xml
228+
_pkginfo.txt
229+
*.appx
230+
*.appxbundle
231+
*.appxupload
232+
233+
# Visual Studio cache files
234+
# files ending in .cache can be ignored
235+
*.[Cc]ache
236+
# but keep track of directories ending in .cache
237+
!?*.[Cc]ache/
238+
239+
# Others
240+
ClientBin/
241+
~$*
242+
*~
243+
*.dbmdl
244+
*.dbproj.schemaview
245+
*.jfm
246+
*.pfx
247+
*.publishsettings
248+
orleans.codegen.cs
249+
250+
#KDevelop
251+
*.kdev4
252+
.kdev4/*
253+
254+
# Including strong name files can present a security risk
255+
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
256+
#*.snk
257+
258+
# Since there are multiple workflows, uncomment next line to ignore bower_components
259+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
260+
#bower_components/
261+
262+
# RIA/Silverlight projects
263+
Generated_Code/
264+
265+
# Backup & report files from converting an old project file
266+
# to a newer Visual Studio version. Backup files are not needed,
267+
# because we have git ;-)
268+
_UpgradeReport_Files/
269+
Backup*/
270+
UpgradeLog*.XML
271+
UpgradeLog*.htm
272+
ServiceFabricBackup/
273+
*.rptproj.bak
274+
275+
# SQL Server files
276+
*.mdf
277+
*.ldf
278+
*.ndf
279+
280+
# Business Intelligence projects
281+
*.rdl.data
282+
*.bim.layout
283+
*.bim_*.settings
284+
*.rptproj.rsuser
285+
*- [Bb]ackup.rdl
286+
*- [Bb]ackup ([0-9]).rdl
287+
*- [Bb]ackup ([0-9][0-9]).rdl
288+
289+
# Microsoft Fakes
290+
FakesAssemblies/
291+
292+
# GhostDoc plugin setting file
293+
*.GhostDoc.xml
294+
295+
# Node.js Tools for Visual Studio
296+
.ntvs_analysis.dat
297+
node_modules/
298+
299+
# Visual Studio 6 build log
300+
*.plg
301+
302+
# Visual Studio 6 workspace options file
303+
*.opt
304+
305+
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
306+
*.vbw
307+
308+
# Visual Studio LightSwitch build output
309+
**/*.HTMLClient/GeneratedArtifacts
310+
**/*.DesktopClient/GeneratedArtifacts
311+
**/*.DesktopClient/ModelManifest.xml
312+
**/*.Server/GeneratedArtifacts
313+
**/*.Server/ModelManifest.xml
314+
_Pvt_Extensions
315+
316+
# Paket dependency manager
317+
.paket/paket.exe
318+
paket-files/
319+
320+
# FAKE - F# Make
321+
.fake/
322+
323+
# CodeRush personal settings
324+
.cr/personal
325+
326+
# Python Tools for Visual Studio (PTVS)
327+
__pycache__/
328+
*.pyc
329+
330+
# Cake - Uncomment if you are using it
331+
# tools/**
332+
# !tools/packages.config
333+
334+
# Tabs Studio
335+
*.tss
336+
337+
# Telerik's JustMock configuration file
338+
*.jmconfig
339+
340+
# BizTalk build output
341+
*.btp.cs
342+
*.btm.cs
343+
*.odx.cs
344+
*.xsd.cs
345+
346+
# OpenCover UI analysis results
347+
OpenCover/
348+
349+
# Azure Stream Analytics local run output
350+
ASALocalRun/
351+
352+
# MSBuild Binary and Structured Log
353+
*.binlog
354+
355+
# NVidia Nsight GPU debugger configuration file
356+
*.nvuser
357+
358+
# MFractors (Xamarin productivity tool) working folder
359+
.mfractor/
360+
361+
# Local History for Visual Studio
362+
.localhistory/
363+
364+
# BeatPulse healthcheck temp database
365+
healthchecksdb
366+
367+
# Backup folder for Package Reference Convert tool in Visual Studio 2017
368+
MigrationBackup/
369+
370+
# Python Virtual Env
371+
.venv

‎CMakeLists.txt

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
cmake_minimum_required(VERSION 3.11)
2+
3+
project(MatioEigenExample C CXX)
4+
5+
if(NOT CMAKE_BUILD_TYPE)
6+
set(CMAKE_BUILD_TYPE "Debug")
7+
endif()
8+
9+
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
10+
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
11+
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake"
12+
"${CMAKE_BINARY_DIR}/conan.cmake" TLS_VERIFY ON)
13+
endif()
14+
15+
include(${CMAKE_BINARY_DIR}/conan.cmake)
16+
17+
set(CMAKE_CXX_STANDARD 17)
18+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
19+
20+
set(LIBS_DIR ${CMAKE_CURRENT_BINARY_DIR}/libs)
21+
set(EIGEN_MATIO_URL https://raw.githubusercontent.com/tesch1/eigen-matio/master/MATio)
22+
set(EIGEN_MATIO_DIR ${LIBS_DIR}/include)
23+
set(EIGEN_MATIO_DEST ${EIGEN_MATIO_DIR}/MATio)
24+
if(NOT EXISTS EIGEN_MATIO_DEST)
25+
file(DOWNLOAD ${EIGEN_MATIO_URL} ${EIGEN_MATIO_DEST})
26+
endif()
27+
28+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
29+
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR})
30+
31+
conan_cmake_configure(
32+
REQUIRES "matio/[>=1.5.24]" "eigen/[>=3.4.0]"
33+
GENERATORS cmake_find_package)
34+
conan_cmake_autodetect(settings)
35+
conan_add_remote(
36+
NAME conan-center
37+
URL https://center.conan.io
38+
VERIFY_SSL False)
39+
conan_cmake_install(
40+
PATH_OR_REFERENCE .
41+
BUILD missing
42+
REMOTE conan-center
43+
SETTINGS ${settings})
44+
45+
find_package(matio REQUIRED)
46+
find_package(Eigen3 REQUIRED)
47+
48+
add_library(example STATIC src/example.cpp include/example.hpp)
49+
target_include_directories(example PRIVATE ${EIGEN_MATIO_DIR})
50+
target_link_libraries(example PRIVATE matio::matio Eigen3::Eigen)
51+
52+
enable_testing()
53+
54+
add_subdirectory(test)

‎LICENSE

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org/>
25+

‎README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Matio-Eigen-Example
2+
3+
Simple C++ example how to use the libraries [matio](https://github.com/tbeu/matio) and [eigen](http://eigen.tuxfamily.org/) in CMake using the [Conan](https://conan.io/) package manager.
4+
5+
## Status
6+
7+
[![CMake build](https://github.com/tbeu/matio-eigen-example/actions/workflows/cmake.yml/badge.svg)](https://github.com/tbeu/matio-eigen-example/actions/workflows/cmake.yml)
8+
9+
## License
10+
11+
This software is licensed under the [Unlicense](https://unlicense.org/). See the [LICENSE](LICENSE) file for details.

‎include/example.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
namespace MatioEigenExample
4+
{
5+
double read_first(const char* file_name, const char* var_name);
6+
}

‎src/example.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <iostream>
2+
3+
// Matrix library
4+
// https://eigen.tuxfamily.org/dox/GettingStarted.html
5+
#include <Eigen/Dense>
6+
using Eigen::MatrixXd;
7+
8+
// MATio library
9+
// https://github.com/tesch1/eigen-matio
10+
#include <MATio>
11+
namespace Matio = matio;
12+
13+
namespace MatioEigenExample
14+
{
15+
double read_first(const char* file_name, const char* var_name)
16+
{
17+
MatrixXd data;
18+
Matio::read_mat(file_name, var_name, data);
19+
return data(0);
20+
}
21+
} // namespace MatioEigenExample

‎test/CMakeLists.txt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
project(${CMAKE_PROJECT_NAME}Tests LANGUAGES CXX)
2+
3+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
4+
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR})
5+
6+
conan_cmake_configure(
7+
REQUIRES "gtest/1.14.0"
8+
GENERATORS cmake_find_package)
9+
conan_cmake_autodetect(settings)
10+
conan_add_remote(
11+
NAME conan-center
12+
URL https://center.conan.io
13+
VERIFY_SSL False)
14+
conan_cmake_install(
15+
PATH_OR_REFERENCE .
16+
BUILD missing
17+
REMOTE conan-center
18+
SETTINGS ${settings})
19+
20+
find_package(GTest REQUIRED)
21+
include(GoogleTest)
22+
23+
set(TEST_SOURCES src/example_test.cpp)
24+
25+
foreach(file ${TEST_SOURCES})
26+
string(REGEX REPLACE "(.*/)([a-zA-Z0-9_ ]+)(\.cpp)" "\\2" test_name ${file})
27+
add_executable(${test_name}_Tests ${file})
28+
target_include_directories(${test_name}_Tests PRIVATE "${CMAKE_SOURCE_DIR}/include")
29+
target_link_libraries(${test_name}_Tests PRIVATE example GTest::GTest)
30+
gtest_add_tests(
31+
TARGET ${test_name}_Tests
32+
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test")
33+
endforeach()

‎test/data/data.mat

655 Bytes
Binary file not shown.

‎test/src/example_test.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "example.hpp"
2+
3+
#include <gtest/gtest.h>
4+
5+
TEST(ReadTest, CheckValues)
6+
{
7+
const auto d = MatioEigenExample::read_first("./data/data.mat", "dd");
8+
ASSERT_GE(d, 0.8);
9+
}
10+
11+
int main(int argc, char **argv)
12+
{
13+
::testing::InitGoogleTest(&argc, argv);
14+
return RUN_ALL_TESTS();
15+
}

0 commit comments

Comments
 (0)
Please sign in to comment.