Skip to content

Commit 2adc0c5

Browse files
committed
Add option for inkcpp to compile without exceptions
1 parent 8c7525b commit 2adc0c5

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,18 @@ set_property(CACHE INKCPP_INKLECATE PROPERTY STRINGS "NONE" "OS" "ALL")
6363
option(INKCPP_NO_EH "Disable try/catch in runtime. Used to build without error handling." OFF)
6464
option(INKCPP_NO_RTTI
6565
"Disable real time type information depended code. Used to build without RTTI." OFF)
66+
option(INKCPP_NO_EXCEPTIONS
67+
"Used to build without support for exceptions." OFF)
6668

6769
if(INKCPP_NO_EH)
6870
add_definitions(-DINKCPP_NO_EH)
6971
endif()
7072
if(INKCPP_NO_RTTI)
7173
add_definitions(-DINKCPP_NO_RTTI)
7274
endif()
73-
75+
if(INKCPP_NO_EXCEPTIONS)
76+
add_definitions(-DINKCPP_NO_EXCEPTIONS)
77+
endif()
7478
string(TOUPPER "${INKCPP_INKLECATE}" inkcpp_inklecate_upper)
7579
if(inkcpp_inklecate_upper STREQUAL "ALL")
7680
FetchContent_MakeAvailable(inklecate_windows inklecate_mac inklecate_linux)

shared/public/config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# define INK_ENABLE_UNREAL
1212
# define INKCPP_NO_EH
1313
# define INKCPP_NO_RTTI
14+
# define INKCPP_NO_EXCEPTIONS
1415
#elif INKCPP_BUILD_CLIB
1516
# define INK_ENABLE_CSTD
1617
#else
@@ -26,6 +27,10 @@
2627
# define INK_ENABLE_RTTI
2728
#endif
2829

30+
#ifndef INKCPP_NO_EXCEPTIONS
31+
# define INK_ENABLE_EXCEPTIONS
32+
#endif
33+
2934
// Only turn on if you have json.hpp and you want to use it with the compiler
3035
// #define INK_EXPOSE_JSON
3136

shared/public/system.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
# include "Hash/CityHash.h"
1616
#endif
1717
#ifdef INK_ENABLE_STL
18+
#ifdef INK_ENABLE_EXCEPTIONS
1819
# include <exception>
20+
#endif
1921
# include <stdexcept>
2022
# include <optional>
2123
# include <cctype>
@@ -31,14 +33,18 @@
3133

3234
#ifdef INK_ENABLE_UNREAL
3335
# define inkZeroMemory(buff, len) FMemory::Memset(buff, 0, len)
34-
# define inkAssert(condition, text, ...) checkf(condition, TEXT(text), ##__VA_ARGS__)
35-
# define inkFail(text, ...) checkf(false, TEXT(text), ##__VA_ARGS__)
3636
# define FORMAT_STRING_STR "%hs"
3737
#else
3838
# define inkZeroMemory ink::internal::zero_memory
39+
# define FORMAT_STRING_STR "%s"
40+
#endif
41+
42+
#ifdef INK_ENABLE_UNREAL
43+
# define inkAssert(condition, text, ...) checkf(condition, TEXT(text), ##__VA_ARGS__)
44+
# define inkFail(text, ...) checkf(false, TEXT(text), ##__VA_ARGS__)
45+
#else
3946
# define inkAssert ink::ink_assert
4047
# define inkFail(...) ink::ink_assert(false, __VA_ARGS__)
41-
# define FORMAT_STRING_STR "%s"
4248
#endif
4349

4450
namespace ink
@@ -175,7 +181,7 @@ namespace internal
175181
#endif
176182
} // namespace internal
177183

178-
#ifdef INK_ENABLE_STL
184+
#ifdef INK_ENABLE_EXCEPTIONS
179185
/** exception type thrown if something goes wrong */
180186
using ink_exception = std::runtime_error;
181187
#else
@@ -209,9 +215,19 @@ void ink_assert(bool condition, const char* msg = nullptr, Args... args)
209215
size_t size = snprintf(nullptr, 0, msg, args...) + 1;
210216
char* message = static_cast<char*>(malloc(size));
211217
snprintf(message, size, msg, args...);
218+
#ifdef INK_ENABLE_EXCEPTIONS
212219
throw ink_exception(message);
220+
#else
221+
fprintf(stderr, "Ink Assert: %s\n", message);
222+
abort();
223+
#endif
213224
} else {
225+
#ifdef INK_ENABLE_EXCEPTIONS
214226
throw ink_exception(msg);
227+
#else
228+
fprintf(stderr, "Ink Assert: %s\n", msg);
229+
abort();
230+
#endif
215231
}
216232
}
217233
}

0 commit comments

Comments
 (0)