External dependencies for Matrixgen
are:
In order to build the unittests a recent version of doctest is required. To enable unittests set the BUILD_TESTS
CMake-variable accordingly.
Makeshift
makes use of C++20 features. Tested compilers include GCC 9.2.1
Using Matrixgen
in another project can be done by way of a regular sudo make install
which will copy the pertinent files into your system's include, lib and share directories. The base path defaults to /usr/local/ and may be changed via CMake's CMAKE_INSTALL_PREFIX
variable in the CMakeCache.txt file inside Matrixgen
's build directory.
git clone https://github.com/slavistan/matrixgen.git
cd matrixgen
mkdir build
cd build
cmake ..
# Optionally set `CMAKE_BUILD_TYPE` to match your project's needs.
sudo make install
Alternatively, you may also export Matrixgen
's build directory without copying any files by setting CMake's EXPORT_BUILD_DIR
variable in the CMakeCache.txt file.
git clone https://github.com/slavistan/matrixgen.git
cd matrixgen
mkdir build
cd build
cmake ..
sed -i 's/EXPORT_BUILD_DIR:BOOL=.*/EXPORT_BUILD_DIR:BOOL=ON/g' CMakeCache.txt
make
After successfully performing one of the above methods of installation you may use Matrixgen
like any other library via CMake's find_package(Matrixgen 1.0.0 REQUIRED)
. The CMake target is called Matrixgen::matrixgen
.
For a minimum working example create a file main.cpp
...
// main.cpp
#include <matrixgen/core>
#include <iostream>
int main() {
using Matrix_t = Eigen::SparseMatrix<double, Eigen::RowMajor>;
const auto mat = matrixgen::create<Matrix_t>(2, 2,
{ 1, 3,
3, 7 });
std::cout << mat << std::endl;
}
and alongside it define your CMake configuration in a CMakeLists.txt
in the same directory ...
# CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
find_package(Matrixgen 1.0.0 REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE Matrixgen::matrixgen)
Then build and run the binary.
mkdir build
cd build
cmake ..
make && ./main
Set the CMake-variable BUILD_EXAMPLES
to build the examples and check out their verbosely commented source code in examples/
.