Skip to content

Commit

Permalink
changing to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
xanthospap committed Sep 16, 2024
1 parent 0196d59 commit 94e962b
Show file tree
Hide file tree
Showing 32 changed files with 333 additions and 241 deletions.
32 changes: 6 additions & 26 deletions .github/workflows/cpp-linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,9 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: install scons
run: sudo apt-get install -y scons

- name: install (latest) eigen
run: sudo apt install libeigen3-dev

- name: build (production), gcc
run: scons

- name: build (production, c++20), gcc
run: scons --std=20

- name: build (debug), gcc
run: scons debug=1

- name: build (debug & tests), gcc
run: scons debug=1 test=1

- name: build (production), clang
run: scons --cxx=clang++

- name: build (debug & tests), clang
run: scons debug=1 test=1 --cxx=clang++

- name: build (production, C++20), clang
run: scons --cxx=clang++ --std=20
- name: "prepare build (production/standard), gcc"
run: cmake -S . -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
- name: "build"
run: cmake --build build --target all --config Release -- -j4
- name: "Test"
run: ctest --test-dir build
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.1)

project(
datetime
VERSION 1.1.0
DESCRIPTION "DateTime Library for Satellite Geoddesy"
LANGUAGES CXX
)

# The library
add_subdirectory(src)

# The tests
include(CTest)
add_subdirectory(test//unit_tests)
enable_testing()

add_compile_options(
-Wall -Wextra -Werror -pedantic -W -Wshadow -march=native
$<$<CONFIG:RELEASE>:-O2 -march=native>
$<$<CONFIG:DEBUG>:-g -pg -Wdisabled-optimization -DDEBUG>
)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_CXX_EXTENSIONS Off)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions src/datetime_tops.hpp → include/datetime_tops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,13 @@ constexpr Strg cast_to(Ssrc s) noexcept {
Ssrc::template sec_factor<SecIntType>();
return Strg(s.__member_ref__() * factor);
} else {
// this is tricky! We must first compute the numerator and then the fraction.
// why? check this out
// seconds _s1 = cast_to<milliseconds, seconds>(milliseconds{2000L});
// this is: (1/1000)*2000 which is 0 because 1/1000 is 0, but
// (2000*1)/1000 = 2 which is correct
const auto numerator = s.__member_ref__() * Strg::template sec_factor<long>();
return Strg(numerator / Ssrc::template sec_factor<long>());
// this is tricky! We must first compute the numerator and then the
// fraction. why? check this out seconds _s1 = cast_to<milliseconds,
// seconds>(milliseconds{2000L}); this is: (1/1000)*2000 which is 0 because
// 1/1000 is 0, but (2000*1)/1000 = 2 which is correct
const auto numerator =
s.__member_ref__() * Strg::template sec_factor<long>();
return Strg(numerator / Ssrc::template sec_factor<long>());
}
}

Expand Down
23 changes: 12 additions & 11 deletions src/datetime_write.hpp → include/datetime_write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ template <YMDFormat F> class SpitDate {};
template <> class SpitDate<YMDFormat::YYYYMMDD> {
public:
static const int numChars = 10;
static int spit(const ymd_date &ymd, char *buffer, char delimeter='/') noexcept {
return std::sprintf(buffer, "%4d%c%02d%c%02d", ymd.yr().as_underlying_type(),
delimeter,
ymd.mn().as_underlying_type(),
delimeter,
static int spit(const ymd_date &ymd, char *buffer,
char delimeter = '/') noexcept {
return std::sprintf(buffer, "%4d%c%02d%c%02d",
ymd.yr().as_underlying_type(), delimeter,
ymd.mn().as_underlying_type(), delimeter,
ymd.dm().as_underlying_type());
}
};
Expand All @@ -35,11 +35,11 @@ template <> class SpitDate<YMDFormat::YYYYMMDD> {
template <> class SpitDate<YMDFormat::DDMMYYYY> {
public:
static const int numChars = 10;
static int spit(const ymd_date &ymd, char *buffer, char delimeter='/') noexcept {
return std::sprintf(buffer, "%02d%c%02d%c%4d", ymd.dm().as_underlying_type(),
delimeter,
ymd.mn().as_underlying_type(),
delimeter,
static int spit(const ymd_date &ymd, char *buffer,
char delimeter = '/') noexcept {
return std::sprintf(buffer, "%02d%c%02d%c%4d",
ymd.dm().as_underlying_type(), delimeter,
ymd.mn().as_underlying_type(), delimeter,
ymd.yr().as_underlying_type());
}
};
Expand All @@ -60,7 +60,8 @@ template <> class SpitDate<YMDFormat::DDMMYYYY> {
* to represent the date
* @return On success, a pointer to \p buffer
*/
template <YMDFormat F> const char *to_char(const ymd_date &ymd, char *buffer, char delimeter='/') {
template <YMDFormat F>
const char *to_char(const ymd_date &ymd, char *buffer, char delimeter = '/') {
if (SpitDate<F>::spit(ymd, buffer, delimeter) != SpitDate<F>::numChars) {
throw std::runtime_error("[ERROR] Failed to format date to string\n");
}
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions src/dtdatetime.hpp → include/dtdatetime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class datetime_interval {

public:
/** Default constructor (everything set to 0). */
explicit constexpr datetime_interval() noexcept : m_days(0), m_secs(0){};
explicit constexpr datetime_interval() noexcept : m_days(0), m_secs(0) {};

/** Constructor from number of days and number of *seconds.
*
Expand Down Expand Up @@ -268,7 +268,7 @@ class datetime {
* the user intents to use this function.
*/
datetime(modified_julian_day mjd, S sec, [[maybe_unused]] char c) noexcept
: m_mjd(mjd), m_sec(sec){};
: m_mjd(mjd), m_sec(sec) {};

public:
/** Expose the underlying sec type S */
Expand Down Expand Up @@ -296,7 +296,7 @@ class datetime {
}

/** Default constructor. */
explicit constexpr datetime() noexcept : m_mjd(dso::J2000_MJD), m_sec(0){};
explicit constexpr datetime() noexcept : m_mjd(dso::J2000_MJD), m_sec(0) {};

double jcenturies_sinceJ2000() const noexcept {
const double d_mjd = (double)(m_mjd.as_underlying_type());
Expand Down Expand Up @@ -543,8 +543,7 @@ class datetime {

/** @brief Cast to double (i.e. fractional) Modified Julian Date. */
constexpr double fmjd() const noexcept {
return static_cast<double>(m_mjd.as_underlying_type()) +
fractional_days();
return static_cast<double>(m_mjd.as_underlying_type()) + fractional_days();
}

/** @brief Cast to double (i.e. fractional) Julian Date. */
Expand Down Expand Up @@ -614,7 +613,7 @@ class datetime {
[[nodiscard]] constexpr datetime<S> tai2gps() const noexcept {
return datetime(m_mjd, m_sec - dso::cast_to<seconds, S>(seconds(19)));
}

[[nodiscard]] constexpr datetime<S> tt2gps() const noexcept {
return datetime(m_mjd, m_sec - dso::cast_to<milliseconds, S>(
milliseconds(19000 + 32184)));
Expand Down Expand Up @@ -674,7 +673,7 @@ class datetime {

modified_julian_day m_mjd; /** Modified Julian Day */
S m_sec; /** Time of day in S precision. */
}; /* datetime<S> */
}; /* datetime<S> */

#if __cplusplus >= 202002L
template <gconcepts::is_sec_dt S>
Expand Down Expand Up @@ -703,7 +702,8 @@ class datetimeUtc {
}

/** Default constructor. */
explicit constexpr datetimeUtc() noexcept : m_mjd(dso::J2000_MJD), m_sec(0){};
explicit constexpr datetimeUtc() noexcept
: m_mjd(dso::J2000_MJD), m_sec(0) {};

/** Constructor from year, month, day of month and sec type.
* If an invalid date is passed-in, the constructor will throw.
Expand Down Expand Up @@ -875,7 +875,7 @@ class datetimeUtc {
* Remove whole days of from the time part and add them to the date part.
*/
constexpr void normalize() noexcept {
int extra_sec_in_day;
int extra_sec_in_day = 0;
dat(m_mjd, extra_sec_in_day);
/* for each MJD, remove integral days. Each MJD may have a different
* number of seconds, since we are in UTC time scale. Hence, iteratively
Expand Down Expand Up @@ -948,7 +948,7 @@ class datetimeUtc {

modified_julian_day m_mjd; /** Modified Julian Day */
S m_sec; /** Time of day in S precision. */
}; /* datetimeUtc<S> */
}; /* datetimeUtc<S> */

template <typename S1, typename S2,
typename = std::enable_if_t<S1::is_of_sec_type>,
Expand Down
Loading

0 comments on commit 94e962b

Please sign in to comment.