Produce release builds without exceptions and RTTI

pull/928/head
Hleb Valoshka 2021-03-02 20:19:49 +02:00
parent f5f8770f7f
commit 6b14925798
4 changed files with 44 additions and 1 deletions

View File

@ -350,6 +350,9 @@ if("${build_type_lc}" STREQUAL "debug")
add_definitions(-D_DEBUG -DDEBUG) add_definitions(-D_DEBUG -DDEBUG)
else() else()
add_definitions(-DNO_DEBUG -DEIGEN_NO_DEBUG) add_definitions(-DNO_DEBUG -DEIGEN_NO_DEBUG)
if(NOT MSVC)
add_compile_options(-fno-rtti -fno-exceptions)
endif()
endif() endif()
# Turning all debug on dramatically decreases performance # Turning all debug on dramatically decreases performance

View File

@ -6,7 +6,14 @@
#else #else
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#if defined(_MSC_VER) && !defined(__clang__)
// M$VC++ build without C++ exceptions are not supported yet
#define __cpp_exceptions 1
#endif
#if ! __cpp_exceptions
#include <cstdlib>
#endif
namespace celestia namespace celestia
{ {
@ -339,7 +346,11 @@ uintmax_t file_size(const path& p)
std::error_code ec; std::error_code ec;
uintmax_t s = file_size(p, ec); uintmax_t s = file_size(p, ec);
if (ec) if (ec)
#if __cpp_exceptions
throw filesystem_error(ec, "celfs::file_size error"); throw filesystem_error(ec, "celfs::file_size error");
#else
std::abort();
#endif
return s; return s;
} }
@ -383,7 +394,11 @@ bool exists(const path& p)
std::error_code ec; std::error_code ec;
bool r = exists(p, ec); bool r = exists(p, ec);
if (ec) if (ec)
#if __cpp_exceptions
throw filesystem_error(ec, "celfs::exists error"); throw filesystem_error(ec, "celfs::exists error");
#else
std::abort();
#endif
return r; return r;
} }
@ -415,7 +430,11 @@ bool is_directory(const path& p)
std::error_code ec; std::error_code ec;
bool r = is_directory(p, ec); bool r = is_directory(p, ec);
if (ec) if (ec)
#if __cpp_exceptions
throw filesystem_error(ec, "celfs::is_directory error"); throw filesystem_error(ec, "celfs::is_directory error");
#else
std::abort();
#endif
return r; return r;
} }

View File

@ -18,6 +18,8 @@
#if defined(_MSC_VER) && !defined(__clang__) #if defined(_MSC_VER) && !defined(__clang__)
// M$VC++ 2015 doesn't have required features // M$VC++ 2015 doesn't have required features
#define CEL_CPP_VER (_MSC_VER == 1900 ? 201103L : _MSVC_LANG) #define CEL_CPP_VER (_MSC_VER == 1900 ? 201103L : _MSVC_LANG)
// M$VC++ build without C++ exceptions are not supported yet
#define __cpp_exceptions 1
#else #else
#define CEL_CPP_VER __cplusplus #define CEL_CPP_VER __cplusplus
#endif #endif
@ -28,6 +30,10 @@
#define CEL_constexpr /* constexpr */ #define CEL_constexpr /* constexpr */
#endif #endif
#if ! __cpp_exceptions
#include <cstdlib>
#endif
namespace std namespace std
{ {
template< template<
@ -101,8 +107,11 @@ template<
{ {
if (pos < size()) if (pos < size())
return m_data[pos]; return m_data[pos];
#if __cpp_exceptions
throw std::out_of_range("pos >= size()"); throw std::out_of_range("pos >= size()");
#else
std::abort();
#endif
} }
constexpr const_reference front() const constexpr const_reference front() const
{ {
@ -166,7 +175,11 @@ template<
size_type copy(CharT* dest, size_type count, size_type pos = 0) const size_type copy(CharT* dest, size_type count, size_type pos = 0) const
{ {
if (pos > m_size) if (pos > m_size)
#if __cpp_exceptions
throw std::out_of_range("pos >= size()"); throw std::out_of_range("pos >= size()");
#else
std::abort();
#endif
auto rcount = std::min(count, m_size - pos); auto rcount = std::min(count, m_size - pos);
return Traits::copy(dest, m_data + pos, rcount); return Traits::copy(dest, m_data + pos, rcount);
@ -174,7 +187,11 @@ template<
CEL_constexpr basic_string_view substr(size_type pos = 0, size_type count = npos ) const CEL_constexpr basic_string_view substr(size_type pos = 0, size_type count = npos ) const
{ {
if (pos > m_size) if (pos > m_size)
#if __cpp_exceptions
throw std::out_of_range("pos >= size()"); throw std::out_of_range("pos >= size()");
#else
std::abort();
#endif
auto rcount = std::min(count, m_size - pos); auto rcount = std::min(count, m_size - pos);
return { m_data + pos, rcount }; return { m_data + pos, rcount };

View File

@ -20,3 +20,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
build_cmod_tool(cmodview WIN32 cmodview.cpp glframebuffer.cpp glshader.cpp mainwindow.cpp materialwidget.cpp modelviewwidget.cpp glsupport.cpp) build_cmod_tool(cmodview WIN32 cmodview.cpp glframebuffer.cpp glshader.cpp mainwindow.cpp materialwidget.cpp modelviewwidget.cpp glsupport.cpp)
qt5_use_modules(cmodview ${QT_LIBS}) qt5_use_modules(cmodview ${QT_LIBS})
if(NOT MSVC)
target_compile_options(cmodview PRIVATE "-frtti")
endif()