Skip to content
Snippets Groups Projects
Commit af85d9a5 authored by Erik Strand's avatar Erik Strand
Browse files

Define basic project structure

parent 2969ba73
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 3.13) # 3.13 is required for target_link_options
project(simucene 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_subdirectory(simucene)
# cpp_starter
A hello world C++ application using cmake and Eigen
## Dependencies
- a modern C++ compiler (i.e. one that supports C++17 features, ex. gcc 7+)
- cmake 3.13 or newer
- Eigen3 (installable via apt, yum, or homebrew)
## Building
From the project's root directory,
```
mkdir build
cd build
cmake ..
make
```
Tips:
- you can build using multiple threads at once using e.g. `make -j4`
- you can specify a specific compiler using `cmake .. -DCMAKE_CXX_COMPILER=g++-8`
- for debugging symbols use `cmake .. -DCMAKE_BUILD_TYPE=Debug`
## Running
From the build directory,
```
cpp_starter/cpp_starter
```
# This file defines an interface library used to add common compile flags to all libraries and
# executables.
#---------------------------------------------------------------------------------------------------
add_library(shared_settings INTERFACE)
# Speed flags
target_compile_options(shared_settings INTERFACE -march=native -ffast-math)
# Warning flags
target_compile_options(shared_settings INTERFACE
-Wall
-Wcast-align
-Wcast-qual
-Wextra
-Wundef
-Wzero-as-null-pointer-constant
-pedantic
)
add_library(simucene_lib
my_class.cpp
my_class.h
vector.h
)
target_include_directories(simucene_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(simucene_lib shared_settings Eigen3::Eigen)
target_compile_features(simucene_lib PUBLIC cxx_std_17)
add_executable(simucene
main.cpp
)
target_link_libraries(simucene shared_settings simucene_lib)
#include "my_class.h"
#include "vector.h"
#include <iostream>
using namespace cpp_starter;
//--------------------------------------------------------------------------------------------------
int main(int const, char const**) {
MyClass my_class("world");
my_class.hello();
Vector3<double> x = {0, 1, 2};
x = exp(x.array());
std::cout << x << '\n';
return 0;
}
#include "my_class.h"
#include <iostream>
namespace cpp_starter {
//..................................................................................................
void MyClass::hello() const {
std::cout << "Hello, " << name_ << '\n';
}
}
#ifndef CPP_STARTER_MY_CLASS_H
#define CPP_STARTER_MY_CLASS_H
#include <string>
namespace cpp_starter {
//--------------------------------------------------------------------------------------------------
class MyClass {
public:
MyClass(std::string const& name): name_(std::move(name)) {}
void hello() const;
private:
std::string name_;
};
}
#endif
#ifndef CPP_STARTER_VECTOR_H
#define CPP_STARTER_VECTOR_H
#include <Eigen/Core>
namespace cpp_starter {
//--------------------------------------------------------------------------------------------------
template <typename T>
using Vector2 = Eigen::Matrix<T, 2, 1>;
//--------------------------------------------------------------------------------------------------
template <typename T>
using Vector3 = Eigen::Matrix<T, 3, 1>;
//--------------------------------------------------------------------------------------------------
template <typename T>
using VectorX = Eigen::Matrix<T, Eigen::Dynamic, 1>;
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment