Commit 3a2c5f64 authored by EXT José Ignacio Requeno Jarabo's avatar EXT José Ignacio Requeno Jarabo
Browse files

Initial commit

parents
Pipeline #28880 canceled with stage
/temp/
/build/
CMakeLists.txt.user
*.swp
image: ubuntu:18.04
variables:
GIT_SUBMODULE_STRATEGY: normal
stages:
- build
StlEval-Ubuntu18.04:
stage: build
script:
- apt-get update -qq && apt-get install -y -qq g++ make cmake git
- rm -rf build
- rm -rf bin
- rm -rf lib
- rm -rf include
- rm -f version.txt
- mkdir build
- cd build
- cmake -DBUILD_SHARED_LIBS=ON ..
- make
- cd ..
- build/bin/stle -v
- ldd build/bin/tests
- build/bin/tests
- ldd build/bin/tests-shared
- LD_LIBRARY_PATH="build/lib:$LD_LIBRARY_PATH" build/bin/tests-shared
- cp -r build/bin build/lib .
- mkdir include
- cp --parents CStle/cstle.h include
- cp --parents $(find Stle -name "*.hpp") include
- git describe --always --tags > version.txt
artifacts:
paths:
- bin/stle
- bin/mksignal
- lib/
- include/
- version.txt
[submodule "googletest"]
path = googletest
url = https://github.com/google/googletest.git
Building From Command Line
==========================
StlEval is written in C++14. It is tested with MSVC 2017 and g++ 7.3.
It uses CMake (3.9+ required) as the build system.
- [Windows](#windows)
- [Linux](#linux)
Windows
-------
1. Install Visual Studio 2017.
You can get the free Community Edition [here](https://visualstudio.microsoft.com/vs/community/).
Be sure to select 'Desktop development with C++' during installation.
2. Install CMake from [here](https://cmake.org/download/).
Version 3.9 or higher is required.
Make sure that CMake's `bin` directory is added to `PATH`.
3. Install Git for Windows from [here](https://git-scm.com/download/win).
To be able to see git commit information in the output of `stle -v`, add
Git's `bin` directory to `PATH`.
4. Open git command prompt. Clone the repository and `cd` into it.
```bash
$ git clone https://gitlab.com/abakhirkin/StlEval.git
$ cd StlEval
```
5. Initialize and update git submodules. This will fetch a version of Googletest
that is required to run tests.
```bash
$ git submodule init
$ git submodule update
```
6. Create a build directory, e.g., a directory `build` in the source tree.
You may name and place it differently; in this case you will need to adjust
the paths given in these instructions.
```
$ mkdir build
```
7. Open Visual Studio command prompt for your platform and target.
To compile x64 binaries on x64 machine (prefer this if not sure), open
`Start -> All Programs -> Visual Studio 2017 -> Visual Studio Tools -> VC ->
x64 Native Tools Command Prompt`.
Then, `cd` to the build directory.
8. Run CMake and NMake.
```
$ cmake -G "NMake Makefiles" ..
$ nmake
```
The last argument of `cmake` should point to the source directory.
If you created the build directory inside the source directory as suggested
above, then `..` will point to the source directory.
You may pass extra options to `cmake`:
- `-DCMAKE_BUILD_TYPE=Debug` to build the debug version
(release version is built by default).
- `-DBUILD_SHARED_LIBS=ON` to also build DLL versions of the libraries
(only static versions are built by default).
9. Locate the output files in the directories `bin`, `lib`, and `include`.
10. Run tests.
The current directory should be the source directory.
```
$ cd ..
$ build\bin\tests.exe
```
If you built the shared versions of the libraries, run `tests_shared`,
which runs the same tests as `tests`, but is linked to the dll versions
of the libraries.
```
$ cd ..
$ build\bin\tests_shared.exe
```
Linux
-----
1. Make sure you have the requred packages.
For Debian/Ubuntu these are:
`g++`, `make`, `cmake`, `git`.
CMake version 3.9 or higher is required.
2. Clone the repository and `cd` into it.
```bash
$ git clone https://gitlab.com/abakhirkin/StlEval.git
$ cd StlEval
```
3. Initialize and update git submodules. This will fetch a version of Googletest
that is required to run tests.
```bash
$ git submodule init
$ git submodule update
```
6. Create a build directory, e.g., a directory `build` in the source tree and
`cd` into it.
You may name and place it differently; in this case you will need to adjust
the paths given in these instructions.
```bash
$ mkdir build
$ cd build
```
5. Run CMake and Make.
```bash
$ cmake ..
$ make
```
The last argument of `cmake` should point to the source directory.
If you created the build directory inside the source directory as suggested
above, then `..` will point to the source directory.
You may pass extra options to `cmake`:
- `-DCMAKE_BUILD_TYPE=Debug` to build the debug version
(release version is built by default).
- `-DBUILD_SHARED_LIBS=ON` to also build shared versions of the libraries
(only static versions are built by default).
6. Locate the output files in the directories `bin`, `lib`, and `include`.
7. Run tests.
The current directory should be the source directory `tests`.
```bash
$ cd ..
$ build/bin/tests
```
If you built the shared versions of the libraries, run `tests_shared`,
which runs the same tests as `tests`, but is linked to the shared versions
of the libraries.
The `libcstle.so.1` should be present in the linker search path.
```bash
$ cd ..
$ LD_LIBRARY_PATH="./build/lib:$LD_LIBRARY_PATH" build/bin/tests-shared
```
cmake_minimum_required(VERSION 3.9)
set(STLE_SET_BUILD_TYPE ON CACHE BOOL "Set default build type to Release (Default: ON).")
if (STLE_SET_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (Default: Release).")
else()
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF CACHE BOOL "Link-time optimization (Default: ON except for Debug).")
else()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON CACHE BOOL "Link-time optimization (Default: ON except for Debug).")
endif()
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared versions of libraries (Default: OFF).")
if (BUILD_SHARED_LIBS)
set (NO_BUILD_SHARED_LIBS OFF)
else()
set (NO_BUILD_SHARED_LIBS ON)
endif()
set(CMAKE_SKIP_RPATH ON CACHE BOOL "Do not add RPATH/RUNPATH to executables.")
set(CMAKE_DEBUG_POSTFIX d)
project(StlEval)
set(BUILD_SHARED_LIBS_OLD ${BUILD_SHARED_LIBS})
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_OLD ${CMAKE_INTERPROCEDURAL_OPTIMIZATION})
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF CACHE BOOL "" FORCE)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/gtest-lib)
add_subdirectory(googletest EXCLUDE_FROM_ALL)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_OLD} CACHE BOOL "" FORCE)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${CMAKE_INTERPROCEDURAL_OPTIMIZATION_OLD} CACHE BOOL "" FORCE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
if(MSVC)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
if(CMAKE_CXX_FLAGS MATCHES "/Wall")
string(REGEX REPLACE "/Wall" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
add_subdirectory(Stle)
add_subdirectory(CStle)
add_subdirectory(tests)
add_subdirectory(mkblobs)
add_subdirectory(stle-cli)
add_subdirectory(mksignal)
cmake_minimum_required(VERSION 3.9)
project(CStle)
file(GLOB cstleSrc "*.cpp" "*.h")
execute_process(COMMAND git describe --always --tags WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE gitVersion ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if (gitVersion STREQUAL "")
set(gitVersion unknown)
endif()
# Static library.
add_library(cstle-static STATIC ${cstleSrc})
set_property(TARGET cstle-static PROPERTY OUTPUT_NAME cstle-static)
target_compile_features(cstle-static PRIVATE cxx_std_14)
target_compile_definitions(cstle-static PRIVATE -DCSTLE_VERSION=\"${gitVersion}\")
target_include_directories(cstle-static INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/..)
target_link_libraries(cstle-static PRIVATE stle-static)
# Shared library.
# In Windows, we can just link to 'stle-static', which will not export Stle C++
# symbols.
# In Linux, we want to link to the objects compiled with PIC with hidden
# visibility.
if (WIN32)
add_library(cstle-shared SHARED ${cstleSrc})
target_link_libraries(cstle-shared PRIVATE stle-static)
else()
add_library(cstle-shared SHARED ${cstleSrc} $<TARGET_OBJECTS:stleHiddenPicObj>)
set_property(TARGET cstle-shared PROPERTY CXX_VISIBILITY_PRESET hidden)
target_link_libraries(cstle-shared PRIVATE stle-interface)
endif()
set_property(TARGET cstle-shared PROPERTY OUTPUT_NAME cstle)
set_property(TARGET cstle-shared PROPERTY SOVERSION 1)
target_compile_features(cstle-shared PRIVATE cxx_std_14)
target_compile_definitions(cstle-shared PRIVATE -DCSTLE_VERSION=\"${gitVersion}\")
target_compile_definitions(cstle-shared PRIVATE -DCSTLE_COMPILE_DLL)
target_include_directories(cstle-shared INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/..)
set_property(TARGET cstle-shared PROPERTY EXCLUDE_FROM_ALL ${NO_BUILD_SHARED_LIBS})
# Interface library.
add_library(cstle-interface INTERFACE)
target_include_directories(cstle-interface INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/..)
#include "cstle.h"
#include "Stle/PCSignal.hpp"
#include "Stle/ArrayPCSignalReader.hpp"
#include "Stle/CsvPCSignalReader.hpp"
#include "Stle/ExprSet.hpp"
#include "Stle/SExprParser.hpp"
#include "Stle/PCMonitor.hpp"
#include "Stle/PCRobMonitor.hpp"
#include "Stle/ExprPtr.hpp"
#include "Stle/Version.hpp"
#include "Stle/U/FileReader.hpp"
#include "Stle/U/CsvReader.hpp"
#include "Stle/U/SLexer.hpp"
#include "Stle/U/Array2DRef.hpp"
#include "Stle/U/Array2DTRef.hpp"
using namespace Stle;
const char *stle_version() {
return stleVersion();
}
const char *stle_c_api_version() {
return CSTLE_VERSION;
}
stle_pcseries *stle_make_pcseries() {
stle_pcseries *series = nullptr;
try {
series = reinterpret_cast<stle_pcseries*>(new PCSeries());
} catch (...) {
}
return series;
}
int stle_pcseries_add(stle_pcseries *series, double endTime, double value) {
try {
reinterpret_cast<PCSeries*>(series)->add(Time(endTime), Space(value));
return 1;
} catch (...) {
}
return 0;
}
double stle_pcseries_value0(const stle_pcseries *series) {
return reinterpret_cast<const PCSeries*>(series)->at(0).value().value();
}
int stle_pcseries_equal(const stle_pcseries *series1, const stle_pcseries *series2) {
return static_cast<int>(*reinterpret_cast<const PCSeries*>(series1) == *reinterpret_cast<const PCSeries*>(series2));
}
void stle_delete_pcseries(const stle_pcseries *series) {
if (series)
delete reinterpret_cast<const PCSeries*>(series) ;
}
int stle_pcsignal_size(const stle_pcsignal *signal) {
return reinterpret_cast<const PCSignal*>(signal)->size();
}
const stle_pcseries *stle_pcsignal_at(const stle_pcsignal *signal, int i) {
return reinterpret_cast<const stle_pcseries*>(&reinterpret_cast<const PCSignal*>(signal)->at(i));
}
void stle_delete_pcsignal(const stle_pcsignal *signal) {
if (signal)
delete reinterpret_cast<const PCSignal*>(signal);
}
stle_pcsignal *stle_read_pcsignal_array(const double *data, int sample_count, int field_count, int by_row, int flags) {
stle_pcsignal *signal = nullptr;
try {
if (by_row)
signal = reinterpret_cast<stle_pcsignal*>(new PCSignal(readPCSignalArray(U::makeArray2DRef(data, field_count), sample_count, field_count, static_cast<ReadSignalFlags>(flags))));
else
signal = reinterpret_cast<stle_pcsignal*>(new PCSignal(readPCSignalArray(U::makeArray2DTRef(data, sample_count), sample_count, field_count, static_cast<ReadSignalFlags>(flags))));
} catch (...) {
}
return signal;
}
stle_pcsignal *stle_read_pcsignal_array2(double const *const *data, int sample_count, int field_count, int flags) {
stle_pcsignal *signal = nullptr;
try {
signal = reinterpret_cast<stle_pcsignal*>(new PCSignal(readPCSignalArray(data, sample_count, field_count, static_cast<ReadSignalFlags>(flags))));
} catch (...) {
}
return signal;
}
stle_pcsignal *stle_read_pcsignal_csv_file(FILE *file, int flags) {
stle_pcsignal *signal = nullptr;
try {
U::CsvReader<U::FileReader<U::FileRef>> csvReader(U::OF_READER, U::OF_FILE, file);
signal = reinterpret_cast<stle_pcsignal*>(new PCSignal(readPCSignalCsv(csvReader, static_cast<ReadSignalFlags>(flags))));
} catch (...) {
}
return signal;
}
stle_pcsignal *stle_read_pcsignal_csv_fname(const char *fileName, int flags) {
stle_pcsignal *signal = nullptr;
try {
U::CsvReader<U::FileReader<U::File>> csvReader(U::OF_READER, U::OF_FILE, fileName, "r");
signal = reinterpret_cast<stle_pcsignal*>(new PCSignal(readPCSignalCsv(csvReader, static_cast<ReadSignalFlags>(flags))));
} catch (...) {
}
return signal;
}
stle_exprset *stle_make_exprset() {
stle_exprset *exprset = nullptr;
try {
exprset = reinterpret_cast<stle_exprset*>(new ExprSet());
} catch (...) {
}
return exprset;
}
void stle_delete_exprset(const stle_exprset *exprset) {
if (exprset)
delete reinterpret_cast<const ExprSet*>(exprset);
}
const stle_expr_impl *stle_get_expr_impl(const stle_expr *expr) {
return reinterpret_cast<const stle_expr_impl*>(reinterpret_cast<const ExprPtr*>(expr)->get());
}
const stle_expr *stle_parse_sexpr_str(stle_exprset *exprset, const char *str, int *pos) {
const stle_expr *expr = nullptr;
try {
expr = reinterpret_cast<const stle_expr*>(new ExprPtr(parseSExprStr(*reinterpret_cast<ExprSet*>(exprset), str, pos)));
} catch (...) {
}
return expr;
}
const stle_expr *stle_parse_sexpr_file(stle_exprset *exprset, FILE *file) {
const stle_expr *expr = nullptr;
try {
SExprParser<U::SLexer<U::FileReader<U::FileRef>>> parser(*reinterpret_cast<ExprSet*>(exprset), U::OF_READER, U::OF_FILE, file);
expr = reinterpret_cast<const stle_expr*>(new ExprPtr(parser.parse()));
} catch (...) {
}
return expr;
}
void stle_unref_expr(const stle_expr *expr) {
if (expr)
delete reinterpret_cast<const ExprPtr*>(expr);
}
stle_signalvars *stle_make_signalvars_xn(int n) {
stle_signalvars *signalvars = nullptr;
try {
signalvars = reinterpret_cast<stle_signalvars*>(new SignalVars(VARS_XN, n));
} catch (...) {
}
return signalvars;
}
void stle_delete_signalvars(const stle_signalvars *signalvars) {
if (signalvars)
delete reinterpret_cast<const SignalVars*>(signalvars);
}
stle_pcmonitor *stle_make_pcmonitor(stle_pcsignal *signal, const stle_signalvars *signalvars, stle_exprset *exprset) {
stle_pcmonitor *monitor = nullptr;
try {
monitor = reinterpret_cast<stle_pcmonitor*>(
new PCMonitor(
*reinterpret_cast<PCSignal*>(signal),
*reinterpret_cast<const SignalVars*>(signalvars),
*reinterpret_cast<ExprSet*>(exprset)));
} catch (...) {
}
return monitor;
}
const stle_pcseries *stle_pcmonitor_make_output(stle_pcmonitor *monitor, const stle_expr *expr, int rewrite, const stle_expr **rewritten) {
const stle_pcseries *result = nullptr;
try {
ExprPtr rewrittenExpr;
result = reinterpret_cast<const stle_pcseries*>(
&reinterpret_cast<PCMonitor*>(monitor)->makeOutput(
*reinterpret_cast<const ExprPtr*>(expr),
static_cast<bool>(rewrite),
&rewrittenExpr));
if (rewrite && rewritten) {
*rewritten = reinterpret_cast<const stle_expr*>(new ExprPtr(std::move(rewrittenExpr)));
}
} catch (...) {
}
return result;
}
void stle_delete_pcmonitor(const stle_pcmonitor *monitor) {
if (monitor)
delete reinterpret_cast<const PCMonitor*>(monitor);
}
stle_pcmonitor *stle_make_offlinepcmonitor(stle_pcsignal *signal, const stle_signalvars *signalvars, stle_exprset *exprset) {
return stle_make_pcmonitor(signal, signalvars, exprset);
}
const stle_pcseries *stle_offlinepcmonitor_make_output(stle_offlinepcmonitor *monitor, const stle_expr *expr, int rewrite, const stle_expr **rewritten) {
return stle_pcmonitor_make_output(monitor, expr, rewrite, rewritten);
}
void stle_delete_offlinepcmonitor(const stle_offlinepcmonitor *monitor) {
return stle_delete_pcmonitor(monitor);
}
stle_pcrobmonitor *stle_make_pcrobmonitor(stle_pcsignal *signal, const stle_signalvars *signalvars, stle_exprset *exprset) {
stle_pcrobmonitor *monitor = nullptr;
try {
monitor = reinterpret_cast<stle_pcrobmonitor*>(
new PCRobMonitor(
*reinterpret_cast<PCSignal*>(signal),
*reinterpret_cast<const SignalVars*>(signalvars),
*reinterpret_cast<ExprSet*>(exprset)));
} catch (...) {
}
return monitor;
}
const stle_pcseries *stle_pcrobmonitor_make_output(stle_pcrobmonitor *monitor, const stle_expr *expr, int rewrite, const stle_expr **rewritten) {
const stle_pcseries *result = nullptr;
try {
ExprPtr rewrittenExpr;
result = reinterpret_cast<const stle_pcseries*>(
&reinterpret_cast<PCRobMonitor*>(monitor)->makeOutput(
*reinterpret_cast<const ExprPtr*>(expr),
static_cast<bool>(rewrite),
&rewrittenExpr));
if (rewrite && rewritten) {
*rewritten = reinterpret_cast<const stle_expr*>(new ExprPtr(std::move(rewrittenExpr)));
}
} catch (...) {
}
return result;
}
void stle_delete_pcrobmonitor(const stle_pcrobmonitor *monitor) {
if (monitor)
delete reinterpret_cast<const PCRobMonitor*>(monitor);
}
#ifndef CSTLE_H
#define CSTLE_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#if defined(CSTLE_COMPILE_DLL)
#define CSTLE_API __declspec(dllexport)
#elif defined(CSTLE_USE_DLL)
#define CSTLE_API __declspec(dllimport)
#else
#define CSTLE_API
#endif
#else
#if defined(CSTLE_COMPILE_DLL)
#define CSTLE_API __attribute__ ((visibility ("default")))
#else
#define CSTLE_API
#endif
#endif
#include <stdio.h>
CSTLE_API const char *stle_version(void);
CSTLE_API const char *stle_c_api_version(void);
typedef struct stle_pcseries stle_pcseries;
CSTLE_API stle_pcseries *stle_make_pcseries(void);
CSTLE_API int stle_pcseries_add(stle_pcseries *series, double endTime, double value);
CSTLE_API double stle_pcseries_value0(const stle_pcseries *series);
CSTLE_API int stle_pcseries_equal(const stle_pcseries *series1, const stle_pcseries *series2);
CSTLE_API void stle_delete_pcseries(const stle_pcseries *series);
typedef struct stle_pcsignal stle_pcsignal;
CSTLE_API int stle_pcsignal_size(const stle_pcsignal *signal);
CSTLE_API const stle_pcseries *stle_pcsignal_at(const stle_pcsignal *signal, int i);
// TODO: More PCSignal methods/functions.
CSTLE_API void stle_delete_pcsignal(const stle_pcsignal *signal);
// These should match Stl::ReadSignalFlags.
#define STLE_READ_SIGNAL_TIME_FIRST 0x0
#define STLE_READ_SIGNAL_TIME_LAST 0x1
#define STLE_READ_SIGNAL_START_POINTS 0x0
#define STLE_READ_SIGNAL_END_POINTS 0x2
#define STLE_READ_SIGNAL_RIGHT_OPEN 0x0
#define STLE_READ_SIGNAL_RIGHT_CLOSED 0x4
#define STLE_READ_SIGNAL_DEFAULT 0x0
CSTLE_API stle_pcsignal *stle_read_pcsignal_array(const double *data, int sample_count, int field_count, int by_row, int flags);
CSTLE_API stle_pcsignal *stle_read_pcsignal_array2(double const *const *data, int sample_count, int field_count, int flags);
CSTLE_API stle_pcsignal *stle_read_pcsignal_csv_file(FILE *file, int flags);