8000 Merge pull request #17 from luadebug/export · orange-cpp/omath@5f8fc40 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f8fc40

Browse files
authored
Merge pull request #17 from luadebug/export
Create Export for DLL (shared MSVC build)
2 parents c0efa35 + fc164b3 commit 5f8fc40

File tree

20 files changed

+144
-110
lines changed

20 files changed

+144
-110
lines changed

CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.26)
22

33
project(omath VERSION 1.0.0)
44

5-
5+
include(CMakePackageConfigHelpers)
66

77
set(CMAKE_CXX_STANDARD 26)
88

@@ -19,10 +19,16 @@ else()
1919
add_library(omath STATIC source/Vector3.cpp)
2020
endif()
2121

22+
target_compile_definitions(omath PUBLIC OMATH_EXPORT)
23+
24+
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
25+
target_compile_options(omath PRIVATE /Zc:static_assert-)
26+
endif()
27+
2228
add_subdirectory(source)
23-
add_subdirectory(extlibs)
2429

2530
if(OMATH_BUILD_TESTS)
31+
add_subdirectory(extlibs)
2632
add_subdirectory(tests)
2733
endif()
2834

@@ -79,4 +85,4 @@ install(FILES
7985
"${CMAKE_CURRENT_BINARY_DIR}/omathConfig.cmake"
8086
"${CMAKE_CURRENT_BINARY_DIR}/omathConfigVersion.cmake"
8187
DESTINATION lib/cmake/omath
82-
)
88+
)

include/omath/Angle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "omath/Angles.hpp"
77

88
#include <algorithm>
9-
9+
#include "omath/omath_export.hpp"
1010

1111
namespace omath
1212
{
@@ -18,7 +18,7 @@ namespace omath
1818

1919
template<class Type = float, Type min = Type(0), Type max = Type(360), AngleFlags flags = AngleFlags::Normalized>
2020
requires std::is_arithmetic_v<Type>
21-
class Angle
21+
class OMATH_API Angle
2222
{
2323
Type m_angle;
2424
constexpr Angle(const Type& degrees)

include/omath/Angles.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <numbers>
77
#include <cmath>
88

9-
109
namespace omath::angles
1110
{
1211
template<class Type>

include/omath/Color.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
#include "omath/Vector3.hpp"
88
#include <cstdint>
99
#include "omath/Vector4.hpp"
10-
10+
#include "omath/omath_export.hpp"
1111

1212
namespace omath
1313
{
14-
struct HSV
14+
struct OMATH_API HSV
1515
{
1616
float m_hue{};
1717
float m_saturation{};
1818
float m_value{};
1919
};
2020

2121

22-
class Color final : public Vector4
22+
class OMATH_API Color final : public Vector4
2323
{
2424
public:
2525
constexpr Color(float r, float g, float b, float a) : Vector4(r,g,b,a)

include/omath/Mat.hpp

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#include <stdexcept>
99
#include <utility>
1010
#include "Vector3.hpp"
11-
11+
#include "omath/omath_export.hpp"
1212

1313
namespace omath
1414
{
15-
struct MatSize
15+
struct OMATH_API MatSize
1616
{
1717
size_t rows, columns;
1818
};
@@ -28,15 +28,15 @@ namespace omath
2828
class Mat final
2929
{
3030
public:
31-
constexpr Mat()
31+
OMATH_API constexpr Mat()
3232
{
3333
Clear();
3434
}
35-
constexpr static MatStoreType GetStoreOrdering()
35+
OMATH_API constexpr static MatStoreType GetStoreOrdering()
3636
{
3737
return StoreType;
3838
}
39-
constexpr Mat(const std::initializer_list<std::initializer_list<Type>>& rows)
39+
OMATH_API constexpr Mat(const std::initializer_list<std::initializer_list<Type>>& rows)
4040
{
4141
if (rows.size() != Rows)
4242
throw std::invalid_argument("Initializer list rows size does not match template parameter Rows");
@@ -56,40 +56,40 @@ namespace omath
5656
}
5757
}
5858

59-
constexpr explicit Mat(const Type* rawData)
59+
OMATH_API constexpr explicit Mat(const Type* rawData)
6060
{
6161
std::copy_n(rawData, Rows * Columns, m_data.begin());
6262
}
6363

64-
constexpr Mat(const Mat& other) noexcept
64+
OMATH_API constexpr Mat(const Mat& other) noexcept
6565
{
6666
m_data = other.m_data;
6767
}
6868

69-
constexpr Mat(Mat&& other) noexcept
69+
OMATH_API constexpr Mat(Mat&& other) noexcept
7070
{
7171
m_data = std::move(other.m_data);
7272
}
7373

7474
[[nodiscard]]
75-
static constexpr size_t RowCount() noexcept
75+
OMATH_API static constexpr size_t RowCount() noexcept
7676
{
7777
return Rows;
7878
}
7979

8080
[[nodiscard]]
81-
static constexpr size_t ColumnsCount() noexcept
81+
OMATH_API static constexpr size_t ColumnsCount() noexcept
8282
{
8383
return Columns;
8484
}
8585

8686
[[nodiscard]]
87-
static consteval MatSize Size() noexcept
87+
OMATH_API static consteval MatSize Size() noexcept
8888
{
8989
return {Rows, Columns};
9090
}
9191

92-
[[nodiscard]] constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const
92+
[[nodiscard]] OMATH_API constexpr const Type& At(const size_t rowIndex, const size_t columnIndex) const
9393
{
9494
if (rowIndex >= Rows || columnIndex >= Columns)
9595
throw std::out_of_range("Index out of range");
@@ -107,13 +107,13 @@ namespace omath
107107
}
108108
}
109109

110-
[[nodiscard]] constexpr Type& At(const size_t rowIndex, const size_t columnIndex)
110+
[[nodiscard]] OMATH_API constexpr Type& At(const size_t rowIndex, const size_t columnIndex)
111111
{
112112
return const_cast<Type&>(std::as_const(*this).At(rowIndex, columnIndex));
113113
}
114114

115115
[[nodiscard]]
116-
constexpr Type Sum() const noexcept
116+
OMATH_API constexpr Type Sum() const noexcept
117117
{
118118
Type sum = 0;
119119
for (size_t i = 0; i < Rows; ++i)
@@ -123,20 +123,20 @@ namespace omath
123123
return sum;
124124
}
125125

126-
constexpr void Clear() noexcept
126+
OMATH_API constexpr void Clear() noexcept
127127
{
128128
Set(0);
129129
}
130130

131-
constexpr void Set(const Type& value) noexcept
131+
OMATH_API constexpr void Set(const Type& value) noexcept
132132
{
133133
std::ranges::fill(m_data, value);
134134
}
135135

136136
// Operator overloading for multiplication with another Mat
137137
template<size_t OtherColumns>
138138
constexpr Mat<Rows, OtherColumns, Type, StoreType>
139-
operator*(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
139+
OMATH_API operator*(const Mat<Columns, OtherColumns, Type, StoreType>& other) const
140140
{
141141
Mat<Rows, OtherColumns, Type, StoreType> result;
142142

@@ -151,7 +151,7 @@ namespace omath
151151
return result;
152152
}
153153

154-
constexpr Mat& operator*=(const Type& f) noexcept
154+
OMATH_API constexpr Mat& operator*=(const Type& f) noexcept
155155
{
156156
for (size_t i = 0; i < Rows; ++i)
157157
for (size_t j = 0; j < Columns; ++j)
@@ -161,34 +161,34 @@ namespace omath
161161

162162
template<size_t OtherColumns>
163163
constexpr Mat<Rows, OtherColumns, Type, StoreType>
164-
operator*=(const Mat<Columns, OtherColumns, Type, StoreType>& other)
164+
OMATH_API operator*=(const Mat<Columns, OtherColumns, Type, StoreType>& other)
165165
{
166166
return *this = *this * other;
167167
}
168168

169-
constexpr Mat operator*(const Type& f) const noexcept
169+
OMATH_API constexpr Mat operator*(const Type& f) const noexcept
170170
{
171171
Mat result(*this);
172172
result *= f;
173173
return result;
174174
}
175175

176-
constexpr Mat& operator/=(const Type& f) noexcept
176+
OMATH_API constexpr Mat& operator/=(const Type& f) noexcept
177177
{
178178
for (size_t i = 0; i < Rows; ++i)
179179
for (size_t j = 0; j < Columns; ++j)
180180
At(i, j) /= f;
181181
return *this;
182182
}
183183

184-
constexpr Mat operator/(const Type& f) const noexcept
184+
OMATH_API constexpr Mat operator/(const Type& f) const noexcept
185185
{
186186
Mat result(*this);
187187
result /= f;
188188
return result;
189189
}
190190

191-
constexpr Mat& operator=(const Mat& other) noexcept
191+
OMATH_API constexpr Mat& operator=(const Mat& other) noexcept
192192
{
193193
if (this == &other)
194194
return *this;
@@ -198,7 +198,7 @@ namespace omath
198198
return *this;
199199
}
200200

201-
constexpr Mat& operator=(Mat&& other) noexcept
201+
OMATH_API constexpr Mat& operator=(Mat&& other) noexcept
202202
{
203203
if (this == &other)
204204
return *this;
@@ -211,7 +211,7 @@ namespace omath
211211
}
212212

213213
[[nodiscard]]
214-
constexpr Mat<Columns, Rows, Type, StoreType> Transposed() const noexcept
214+
OMATH_API constexpr Mat<Columns, Rows, Type, StoreType> Transposed() const noexcept
215215
{
216216
Mat<Columns, Rows, Type, StoreType> transposed;
217217
for (size_t i = 0; i < Rows; ++i)
@@ -222,7 +222,7 @@ namespace omath
222222
}
223223

224224
[[nodiscard]]
225-
constexpr Type Determinant() const
225+
OMATH_API constexpr Type Determinant() const
226226
{
227227
static_assert(Rows == Columns, "Determinant is only defined for square matrices.");
228228

@@ -244,7 +244,7 @@ namespace omath
244244
}
245245

246246
[[nodiscard]]
247-
constexpr Mat<Rows - 1, Columns - 1, Type, StoreType> Minor(const size_t row, const size_t column) const
247+
OMATH_API constexpr Mat<Rows - 1, Columns - 1, Type, StoreType> Minor(const size_t row, const size_t column) const
248248
{
249249
Mat<Rows - 1, Columns - 1, Type, StoreType> result;
250250
for (size_t i = 0, m = 0; i < Rows; ++i)
@@ -264,19 +264,19 @@ namespace omath
264264
}
265265

266266
[[nodiscard]]
267-
constexpr const std::array<Type, Rows * Columns>& RawArray() const
267+
OMATH_API constexpr const std::array<Type, Rows * Columns>& RawArray() const
268268
{
269269
return m_data;
270270
}
271271

272272
[[nodiscard]]
273-
constexpr std::array<Type, Rows * Columns>& RawArray()
273+
OMATH_API constexpr std::array<Type, Rows * Columns>& RawArray()
274274
{
275275
return const_cast<std::array<Type, Rows * Columns>>(std::as_const(*this).RawArray());
276276
}
277277

278278
[[nodiscard]]
279-
std::string ToString() const noexcept
279+
OMATH_API std::string ToString() const noexcept
280280
{
281281
std::ostringstream oss;
282282
for (size_t i = 0; i < Rows; ++i)
@@ -293,20 +293,20 @@ namespace omath
293293
}
294294

295295
[[nodiscard]]
296-
bool operator==(const Mat& mat) const
296+
OMATH_API bool operator==(const Mat& mat) const
297297
{
298298
return m_data == mat.m_data;
299299
}
300300

301301
[[nodiscard]]
302-
bool operator!=(const Mat& mat) const
302+
OMATH_API bool operator!=(const Mat& mat) const
303303
{
304304
return !operator==(mat);
305305
}
306306

307307
// Static methods that return fixed-size matrices
308308
[[nodiscard]]
309-
constexpr static Mat<4, 4> ToScreenMat(const Type& screenWidth, const Type& screenHeight) noexcept
309+
OMATH_API constexpr static Mat<4, 4> ToScreenMat(const Type& screenWidth, const Type& screenHeight) noexcept
310310
{
311311
return {
312312
{screenWidth / 2, 0, 0, 0},
@@ -336,7 +336,7 @@ namespace omath
336336

337337
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
338338
[[nodiscard]]
339-
constexpr Mat<4, 4, Type, St> MatTranslation(const Vector3& diff) noexcept
339+
OMATH_API constexpr Mat<4, 4, Type, St> MatTranslation(const Vector3& diff) noexcept
340340
{
341341
return
342342
{
@@ -349,7 +349,7 @@ namespace omath
349349

350350
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
351351
[[nodiscard]]
352-
Mat<4, 4, Type, St> MatRotationAxisX(const Angle& angle) noexcept
352+
OMATH_API Mat<4, 4, Type, St> MatRotationAxisX(const Angle& angle) noexcept
353353
{
354354
return
355355
{
@@ -362,7 +362,7 @@ namespace omath
362362

363363
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
364364
[[nodiscard]]
365-
Mat<4, 4, Type, St> MatRotationAxisY(const Angle& angle) noexcept
365+
OMATH_API Mat<4, 4, Type, St> MatRotationAxisY(const Angle& angle) noexcept
366366
{
367367
return
368368
{
@@ -375,7 +375,7 @@ namespace omath
375375

376376
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
377377
[[nodiscard]]
378-
Mat<4, 4, Type, St> MatRotationAxisZ(const Angle& angle) noexcept
378+
OMATH_API Mat<4, 4, Type, St> MatRotationAxisZ(const Angle& angle) noexcept
379379
{
380380
return
381381
{
@@ -403,7 +403,7 @@ namespace omath
403403

404404
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class ViewAngles>
405405
[[nodiscard]]
406-
Mat<4, 4, Type, St> MatRotation(const ViewAngles& angles) noexcept
406+
OMATH_API Mat<4, 4, Type, St> MatRotation(const ViewAngles& angles) noexcept
407407
{
408408
return MatRotationAxisZ(angles.yaw) * MatRotationAxisY(angles.pitch) * MatRotationAxisX(angles.roll);
409409
}

0 commit comments

Comments
 (0)
0