From 53704c9694d39bb4e013c5126329ec5a2c61e679 Mon Sep 17 00:00:00 2001 From: Erik Strand <erik.strand@cba.mit.edu> Date: Wed, 8 May 2019 18:46:48 -0400 Subject: [PATCH] Add skeletal C++ framework --- .gitignore | 1 + CMakeLists.txt | 18 ++++++++++++++++++ cmake/shared_settings.cmake | 34 ++++++++++++++++++++++++++++++++++ main.cpp | 11 +++++++++++ vector.h | 18 ++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/shared_settings.cmake create mode 100644 main.cpp create mode 100644 vector.h diff --git a/.gitignore b/.gitignore index 31c1c9f..7e22ad4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.swp *.swo .DS_Store +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e235272 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.13) # 3.13 is required for target_link_options +project(CompressedSensing CXX) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") +endif() +message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") + +find_package (Eigen3 3.3 REQUIRED NO_MODULE) + +include(cmake/shared_settings.cmake) + +add_executable(compressed_sensing + main.cpp + vector.h +) +target_link_libraries(compressed_sensing shared_settings Eigen3::Eigen) +target_compile_features(compressed_sensing PUBLIC cxx_std_17) diff --git a/cmake/shared_settings.cmake b/cmake/shared_settings.cmake new file mode 100644 index 0000000..0a16a23 --- /dev/null +++ b/cmake/shared_settings.cmake @@ -0,0 +1,34 @@ +# This file defines an interface library used to add common compile flags to all targets. + +add_library(shared_settings INTERFACE) + +# Warning flags +target_compile_options(shared_settings INTERFACE + -Wall + -Wcast-align + -Wcast-qual + -Wextra + -Wundef + -Wuseless-cast + -Wzero-as-null-pointer-constant + -pedantic +) + +# Speed flags +target_compile_options(shared_settings INTERFACE -march=native -ffast-math) + +# Build type for profile generation +target_compile_options(shared_settings INTERFACE $<$<CONFIG:ProfileGenerate>: + -fprofile-generate + -O3 + -DNDEBUG +>) +target_link_options(shared_settings INTERFACE $<$<CONFIG:ProfileGenerate>:-fprofile-generate>) + +# Build type for profile use +target_compile_options(shared_settings INTERFACE $<$<CONFIG:ProfileUse>: + -fprofile-use + -O3 + -DNDEBUG +>) +target_link_options(shared_settings INTERFACE $<$<CONFIG:ProfileUse>:-fprofile-use>) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..99fb5d7 --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include <iostream> +#include "vector.h" + +using namespace cs; + +//-------------------------------------------------------------------------------------------------- +int main() { + Vector<double> x = Vector<double>::Random(5); + std::cout << x << '\n'; + return 0; +} diff --git a/vector.h b/vector.h new file mode 100644 index 0000000..cf7c07e --- /dev/null +++ b/vector.h @@ -0,0 +1,18 @@ +#ifndef FUNSIM_VECTOR_H +#define FUNSIM_VECTOR_H + +#include <Eigen/Core> + +namespace cs { + +//-------------------------------------------------------------------------------------------------- +template <typename T> +using Vector = Eigen::Matrix<T, Eigen::Dynamic, 1>; + +//-------------------------------------------------------------------------------------------------- +template <typename T> +using Matrix = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>; + +} + +#endif -- GitLab