From 016378b392ee2baa1b3d271a43f4d7b3c13ef4c3 Mon Sep 17 00:00:00 2001 From: tbeu Date: Thu, 29 Feb 2024 21:59:58 +0100 Subject: [PATCH] Initial commit --- .clang-format | 24 +++ .clang-tidy | 6 + .github/workflows/cmake.yml | 74 +++++++ .gitignore | 371 ++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 54 ++++++ LICENSE | 25 +++ README.md | 206 ++++++++++++++++++++ include/example.hpp | 6 + src/example.cpp | 21 ++ test/CMakeLists.txt | 33 ++++ test/data/data.mat | Bin 0 -> 655 bytes test/src/example_test.cpp | 15 ++ 12 files changed, 835 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .github/workflows/cmake.yml create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 README.md create mode 100644 include/example.hpp create mode 100644 src/example.cpp create mode 100644 test/CMakeLists.txt create mode 100644 test/data/data.mat create mode 100644 test/src/example_test.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..8d70915 --- /dev/null +++ b/.clang-format @@ -0,0 +1,24 @@ +--- +BasedOnStyle: Google +AlignAfterOpenBracket: 'AlwaysBreak' +AllowAllConstructorInitializersOnNextLine: 'false' +AllowAllParametersOfDeclarationOnNextLine: 'false' +AlignConsecutiveMacros: 'true' +AllowShortCaseLabelsOnASingleLine: 'true' +AllowShortFunctionsOnASingleLine: 'None' +AllowShortIfStatementsOnASingleLine: 'Never' +AllowShortLoopsOnASingleLine: 'false' +BreakBeforeBraces: Allman +BinPackArguments: 'false' +BinPackParameters: 'false' +Cpp11BracedListStyle: 'false' +ColumnLimit: 125 +NamespaceIndentation: All +SpaceAfterTemplateKeyword: 'false' +SpaceBeforeCtorInitializerColon: 'true' +SpaceBeforeInheritanceColon: 'true' +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: 'true' +SpaceInEmptyBlock: true +Standard: 'Latest' +... diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..d85b250 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,6 @@ +--- +Checks: '*,-fuchsia-*,-google-*,-zircon-*,-abseil-*,-modernize-use-trailing-return-type,-llvm-*,-llvmlibc-*' +CheckOptions: [{ key: misc-non-private-member-variables-in-classes, value: IgnoreClassesWithAllMemberVariablesBeingPublic }] +WarningsAsErrors: '*' +HeaderFilterRegex: '' +FormatStyle: none diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml new file mode 100644 index 0000000..2a2bd44 --- /dev/null +++ b/.github/workflows/cmake.yml @@ -0,0 +1,74 @@ +name: "CMake build" + +on: + push: + pull_request: + workflow_dispatch: + +defaults: + run: + shell: bash + +jobs: + build: + name: ${{ matrix.toolchain }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + toolchain: + - linux-gcc + - macos-clang + - windows-msvc + - windows-mingw + configuration: + - Debug + python-version: + - 3.11 + include: + - toolchain: linux-gcc + os: ubuntu-latest + compiler: gcc + - toolchain: macos-clang + os: macos-latest + compiler: clang + - toolchain: windows-msvc + os: windows-latest + compiler: msvc + - toolchain: windows-mingw + os: windows-latest + compiler: mingw + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 5 + - name: Setup python environment + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install python packages + run: | + if [ "${{ matrix.os }}" == "macos-latest" ]; then + echo "/Users/runner/Library/Python/${{ matrix.python-version }}/bin" >> $GITHUB_PATH + fi + pip install --disable-pip-version-check --user "conan>=1.62.0,<2" + - name: Configure (${{ matrix.configuration }}) + run: | + if [ "${{ matrix.compiler }}" == "msvc" ]; then + cmake -S . -B build + elif [ "${{ matrix.compiler }}" == "mingw" ]; then + cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -G "MinGW Makefiles" + else + cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} + fi + - name: Build with ${{ matrix.compiler }} + run: | + if [ "${{ matrix.compiler }}" == "msvc" ]; then + cmake --build build --config ${{ matrix.configuration }} + else + cmake --build build -- -j8 + fi + - name: Test + run: | + cd build && make test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0b469d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,371 @@ +[Bb]uild/* +[Dd]ocs/* +CMakeCache.* +CMakeFiles/* +[Tt]esting/* + +### VisualStudioCode ### +.vscode/* +.vscode/settings.json +.vscode/tasks.json +.vscode/launch.json +.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +#KDevelop +*.kdev4 +.kdev4/* + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Python Virtual Env +.venv diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c842ba5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 3.11) + +project(MatioEigenExample C CXX) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() + +if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") + message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") + file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake" + "${CMAKE_BINARY_DIR}/conan.cmake" TLS_VERIFY ON) +endif() + +include(${CMAKE_BINARY_DIR}/conan.cmake) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(LIBS_DIR ${CMAKE_CURRENT_BINARY_DIR}/libs) +set(EIGEN_MATIO_URL https://raw.githubusercontent.com/tesch1/eigen-matio/master/MATio) +set(EIGEN_MATIO_DIR ${LIBS_DIR}/include) +set(EIGEN_MATIO_DEST ${EIGEN_MATIO_DIR}/MATio) +if(NOT EXISTS EIGEN_MATIO_DEST) + file(DOWNLOAD ${EIGEN_MATIO_URL} ${EIGEN_MATIO_DEST}) +endif() + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR}) +list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}) + +conan_cmake_configure( + REQUIRES "matio/[>=1.5.24]" "eigen/[>=3.4.0]" + GENERATORS cmake_find_package) +conan_cmake_autodetect(settings) +conan_add_remote( + NAME conan-center + URL https://center.conan.io + VERIFY_SSL False) +conan_cmake_install( + PATH_OR_REFERENCE . + BUILD missing + REMOTE conan-center + SETTINGS ${settings}) + +find_package(matio REQUIRED) +find_package(Eigen3 REQUIRED) + +add_library(example STATIC src/example.cpp include/example.hpp) +target_include_directories(example PRIVATE ${EIGEN_MATIO_DIR}) +target_link_libraries(example PRIVATE matio::matio Eigen3::Eigen) + +enable_testing() + +add_subdirectory(test) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..471f09f --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to + diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c9d7ea --- /dev/null +++ b/README.md @@ -0,0 +1,206 @@ +[![Actions Status](https://github.com/filipdutescu/modern-cpp-template/workflows/MacOS/badge.svg)](https://github.com/filipdutescu/modern-cpp-template/actions) +[![Actions Status](https://github.com/filipdutescu/modern-cpp-template/workflows/Windows/badge.svg)](https://github.com/filipdutescu/modern-cpp-template/actions) +[![Actions Status](https://github.com/filipdutescu/modern-cpp-template/workflows/Ubuntu/badge.svg)](https://github.com/filipdutescu/modern-cpp-template/actions) +[![codecov](https://codecov.io/gh/filipdutescu/modern-cpp-template/branch/master/graph/badge.svg)](https://codecov.io/gh/filipdutescu/modern-cpp-template) +[![GitHub release (latest by date)](https://img.shields.io/github/v/release/filipdutescu/modern-cpp-template)](https://github.com/filipdutescu/modern-cpp-template/releases) + +# Modern C++ Template + +A quick C++ template for modern CMake projects, aimed to be an easy to use +starting point. + +This is my personal take on such a type of template, thus I might not use the +best practices or you might disagree with how I do things. Any and all feedback +is greatly appreciated! + +## Features + +* Modern **CMake** configuration and project, which, to the best of my +knowledge, uses the best practices, + +* An example of a **Clang-Format** config, inspired from the base *Google* model, +with minor tweaks. This is aimed only as a starting point, as coding style +is a subjective matter, everyone is free to either delete it (for the *LLVM* +default) or supply their own alternative, + +* **Static analyzers** integration, with *Clang-Tidy* and *Cppcheck*, the former +being the default option, + +* **Doxygen** support, through the `ENABLE_DOXYGEN` option, which you can enable +if you wish to use it, + +* **Unit testing** support, through *GoogleTest* (with an option to enable +*GoogleMock*) or *Catch2*, + +* **Code coverage**, enabled by using the `ENABLE_CODE_COVERAGE` option, through +*Codecov* CI integration, + +* **Package manager support**, with *Conan* and *Vcpkg*, through their respective +options + +* **CI workflows for Windows, Linux and MacOS** using *GitHub Actions*, making +use of the caching features, to ensure minimum run time, + +* **.md templates** for: *README*, *Contributing Guideliness*, +*Issues* and *Pull Requests*, + +* **Permissive license** to allow you to integrate it as easily as possible. The +template is licensed under the [Unlicense](https://unlicense.org/), + +* Options to build as a header-only library or executable, not just a static or +shared library. + +* **Ccache** integration, for speeding up rebuild times + +## Getting Started + +These instructions will get you a copy of the project up and running on your local +machine for development and testing purposes. + +### Prerequisites + +This project is meant to be only a template, thus versions of the software used +can be change to better suit the needs of the developer(s). If you wish to use the +template *as-is*, meaning using the versions recommended here, then you will need: + +* **CMake v3.15+** - found at [https://cmake.org/](https://cmake.org/) + +* **C++ Compiler** - needs to support at least the **C++17** standard, i.e. *MSVC*, +*GCC*, *Clang* + +> ***Note:*** *You also need to be able to provide ***CMake*** a supported +[generator](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html).* + +### Installing + +It is fairly easy to install the project, all you need to do is clone if from +[GitHub](https://github.com/filipdutescu/modern-cpp-template) or +[generate a new repository from it](https://github.com/filipdutescu/modern-cpp-template/generate) +(also on **GitHub**). + +If you wish to clone the repository, rather than generate from it, you simply need +to run: + +```bash +git clone https://github.com/filipdutescu/modern-cpp-template/ +``` + +After finishing getting a copy of the project, with any of the methods above, create +a new folder in the `include/` folder, with the name of your project. Edit +`cmake/SourcesAndHeaders.cmake` to add your files. + +You will also need to rename the `cmake/ProjectConfig.cmake.in` file to start with +the ***exact name of your project***. Such as `cmake/MyNewProjectConfig.cmake.in`. +You should also make the same changes in the GitHub workflows provided, notably +[`.github/workflows/ubuntu.yml`](.github/workflows/ubuntu.yml), in which you should +replace the CMake option `-DProject_ENABLE_CODE_COVERAGE=1` to +`-DMyNewProject_ENABLE_CODE_COVERAGE=1`. + +Finally, change `"Project"` from `CMakeLists.txt`, from + +```cmake +project( + "Project" + VERSION 0.1.0 + LANGUAGES CXX +) +``` + +to the ***exact name of your project***, i.e. using the previous name it will become: + +```cmake +project( + MyNewProject + VERSION 0.1.0 + LANGUAGES CXX +) +``` + +To install an already built project, you need to run the `install` target with CMake. +For example: + +```bash +cmake --build build --target install --config Release + +# a more general syntax for that command is: +cmake --build --target install --config +``` + +## Building the project + +To build the project, all you need to do, ***after correctly +[installing the project](README.md#Installing)***, is run a similar **CMake** routine +to the the one below: + +```bash +mkdir build/ && cd build/ +cmake .. -DCMAKE_INSTALL_PREFIX=/absolute/path/to/custom/install/directory +cmake --build . --target install +``` + +> ***Note:*** *The custom ``CMAKE_INSTALL_PREFIX`` can be omitted if you wish to +install in [the default install location](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html).* + +More options that you can set for the project can be found in the +[`cmake/StandardSettings.cmake` file](cmake/StandardSettings.cmake). For certain +options additional configuration may be needed in their respective `*.cmake` files +(i.e. Conan needs the `CONAN_REQUIRES` and might need the `CONAN_OPTIONS` to be setup +for it work correctly; the two are set in the [`cmake/Conan.cmake` file](cmake/Conan.cmake)). + +## Generating the documentation + +In order to generate documentation for the project, you need to configure the build +to use Doxygen. This is easily done, by modifying the workflow shown above as follows: + +```bash +mkdir build/ && cd build/ +cmake .. -D_ENABLE_DOXYGEN=1 -DCMAKE_INSTALL_PREFIX=/absolute/path/to/custom/install/directory +cmake --build . --target doxygen-docs +``` + +> ***Note:*** *This will generate a `docs/` directory in the **project's root directory**.* + +## Running the tests + +By default, the template uses [Google Test](https://github.com/google/googletest/) +for unit testing. Unit testing can be disabled in the options, by setting the +`ENABLE_UNIT_TESTING` (from +[cmake/StandardSettings.cmake](cmake/StandardSettings.cmake)) to be false. To run +the tests, simply use CTest, from the build directory, passing the desire +configuration for which to run tests for. An example of this procedure is: + +```bash +cd build # if not in the build directory already +ctest -C Release # or `ctest -C Debug` or any other configuration you wish to test + +# you can also run tests with the `-VV` flag for a more verbose output (i.e. +#GoogleTest output as well) +``` + +### End to end tests + +If applicable, should be presented here. + +### Coding style tests + +If applicable, should be presented here. + +## Contributing + +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our how you can +become a contributor and the process for submitting pull requests to us. + +## Versioning + +This project makes use of [SemVer](http://semver.org/) for versioning. A list of +existing versions can be found in the +[project's releases](https://github.com/filipdutescu/modern-cpp-template/releases). + +## Authors + +* **Filip-Ioan Dutescu** - [@filipdutescu](https://github.com/filipdutescu) + +## License + +This project is licensed under the [Unlicense](https://unlicense.org/) - see the +[LICENSE](LICENSE) file for details diff --git a/include/example.hpp b/include/example.hpp new file mode 100644 index 0000000..4d940c4 --- /dev/null +++ b/include/example.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace MatioEigenExample +{ + double read_first(const char* file_name, const char* var_name); +} diff --git a/src/example.cpp b/src/example.cpp new file mode 100644 index 0000000..473363b --- /dev/null +++ b/src/example.cpp @@ -0,0 +1,21 @@ +#include + +// Matrix library +// https://eigen.tuxfamily.org/dox/GettingStarted.html +#include +using Eigen::MatrixXd; + +// MATio library +// https://github.com/tesch1/eigen-matio +#include +namespace Matio = matio; + +namespace MatioEigenExample +{ + double read_first(const char* file_name, const char* var_name) + { + MatrixXd data; + Matio::read_mat(file_name, var_name, data); + return data(0); + } +} // namespace MatioEigenExample diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..1e17398 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,33 @@ +project(${CMAKE_PROJECT_NAME}Tests LANGUAGES CXX) + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR}) +list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}) + +conan_cmake_configure( + REQUIRES "gtest/1.14.0" + GENERATORS cmake_find_package) +conan_cmake_autodetect(settings) +conan_add_remote( + NAME conan-center + URL https://center.conan.io + VERIFY_SSL False) +conan_cmake_install( + PATH_OR_REFERENCE . + BUILD missing + REMOTE conan-center + SETTINGS ${settings}) + +find_package(GTest REQUIRED) +include(GoogleTest) + +set(TEST_SOURCES src/example_test.cpp) + +foreach(file ${TEST_SOURCES}) + string(REGEX REPLACE "(.*/)([a-zA-Z0-9_ ]+)(\.cpp)" "\\2" test_name ${file}) + add_executable(${test_name}_Tests ${file}) + target_include_directories(${test_name}_Tests PRIVATE "${CMAKE_SOURCE_DIR}/include") + target_link_libraries(${test_name}_Tests PRIVATE example GTest::GTest) + gtest_add_tests( + TARGET ${test_name}_Tests + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test") +endforeach() diff --git a/test/data/data.mat b/test/data/data.mat new file mode 100644 index 0000000000000000000000000000000000000000..784ada35ec5387bdcfb5373e7a0761d7a6825e67 GIT binary patch literal 655 zcmeZu4DoSvQZUssQ1EpO(M`+DN!3vZ$Vn_o%P-2cQgHY2i*PhE(NSB|pf=KyiVoX5!t2^tJZW(v<5 zE-4(~dTPvQ$Sq*Z6sf7n!!yTW8?!+8`&Xw7#H&){PYcWC|9{?F>sxxbM)NrHx8H~5 z3{@ibZVjKA5c?|g^O1iCrY<|wBX9l2_?)TKzFj33{~f$0zq(Rd?iMpc;%~(jAUhAk z?X+M#lH+iOagig7zy_zEX9CWgIB;abq>~2@aHdoC$(nlWzcc?fN~li^na}#|e%b#^lkZhtv~$?<`^mEcApRTo?-!F8FbyQ&D|0#>F#4Y~W zKKEX&{O_l6O=S$CZoKUv^D5xxy?~h~z{s*Dz|L627#Ph(%wf%U`)N`yi zt8ERo?3dnp;@yJejkPN*)~~(th`o$^G5_toe;(%W8?i6DS2SsRt^1a}v9}h+m+?=T ie?wL`aBIE&;VW@hZ(NKs-f{h%eY0GIEkkv^f)oIJj}{&P literal 0 HcmV?d00001 diff --git a/test/src/example_test.cpp b/test/src/example_test.cpp new file mode 100644 index 0000000..68cb768 --- /dev/null +++ b/test/src/example_test.cpp @@ -0,0 +1,15 @@ +#include "example.hpp" + +#include + +TEST(ReadTest, CheckValues) +{ + const auto d = MatioEigenExample::read_first("./data/data.mat", "dd"); + ASSERT_GE(d, 0.8); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}