Add option to force asserts in release builds
This commit is contained in:
parent
2e78e5a55d
commit
ad6e45f9ab
4 changed files with 37 additions and 33 deletions
|
|
@ -37,6 +37,7 @@ option (SFIZZ_DEVTOOLS "Enable developer tools build [default: OFF]" OF
|
||||||
option (SFIZZ_SHARED "Enable shared library build [default: ON]" ON)
|
option (SFIZZ_SHARED "Enable shared library build [default: ON]" ON)
|
||||||
option (SFIZZ_USE_VCPKG "Assume that sfizz is build using vcpkg [default: OFF]" OFF)
|
option (SFIZZ_USE_VCPKG "Assume that sfizz is build using vcpkg [default: OFF]" OFF)
|
||||||
option (SFIZZ_STATIC_LIBSNDFILE "Link libsndfile statically [default: OFF]" OFF)
|
option (SFIZZ_STATIC_LIBSNDFILE "Link libsndfile statically [default: OFF]" OFF)
|
||||||
|
option (SFIZZ_RELEASE_ASSERTS "Forced assertions in release builds [default: OFF]" OFF)
|
||||||
|
|
||||||
# Don't use IPO in non Release builds
|
# Don't use IPO in non Release builds
|
||||||
include (CheckIPO)
|
include (CheckIPO)
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ Use vcpkg: ${SFIZZ_USE_VCPKG}
|
||||||
Statically link libsndfile: ${SFIZZ_STATIC_LIBSNDFILE}
|
Statically link libsndfile: ${SFIZZ_STATIC_LIBSNDFILE}
|
||||||
Link libatomic: ${SFIZZ_LINK_LIBATOMIC}
|
Link libatomic: ${SFIZZ_LINK_LIBATOMIC}
|
||||||
Use clang libc++: ${USE_LIBCPP}
|
Use clang libc++: ${USE_LIBCPP}
|
||||||
|
Release asserts: ${SFIZZ_RELEASE_ASSERTS}
|
||||||
|
|
||||||
Install prefix: ${CMAKE_INSTALL_PREFIX}
|
Install prefix: ${CMAKE_INSTALL_PREFIX}
|
||||||
LV2 destination directory: ${LV2PLUGIN_INSTALL_DIR}
|
LV2 destination directory: ${LV2PLUGIN_INSTALL_DIR}
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,9 @@ set_target_properties (sfizz_static PROPERTIES OUTPUT_NAME sfizz PUBLIC_HEADER "
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_compile_definitions (sfizz_static PRIVATE _USE_MATH_DEFINES)
|
target_compile_definitions (sfizz_static PRIVATE _USE_MATH_DEFINES)
|
||||||
endif()
|
endif()
|
||||||
|
if (SFIZZ_RELEASE_ASSERTS)
|
||||||
|
target_compile_definitions (sfizz_static PRIVATE "SFIZZ_ENABLE_RELEASE_ASSERT=1")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (NOT MSVC)
|
if (NOT MSVC)
|
||||||
install (TARGETS sfizz_static
|
install (TARGETS sfizz_static
|
||||||
|
|
@ -95,6 +98,9 @@ if (SFIZZ_SHARED)
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_compile_definitions (sfizz_shared PRIVATE _USE_MATH_DEFINES)
|
target_compile_definitions (sfizz_shared PRIVATE _USE_MATH_DEFINES)
|
||||||
endif()
|
endif()
|
||||||
|
if (SFIZZ_RELEASE_ASSERTS)
|
||||||
|
target_compile_definitions (sfizz_shared PRIVATE "SFIZZ_ENABLE_RELEASE_ASSERT=1")
|
||||||
|
endif()
|
||||||
target_compile_definitions(sfizz_shared PRIVATE SFIZZ_EXPORT_SYMBOLS)
|
target_compile_definitions(sfizz_shared PRIVATE SFIZZ_EXPORT_SYMBOLS)
|
||||||
set_target_properties (sfizz_shared PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} OUTPUT_NAME sfizz)
|
set_target_properties (sfizz_shared PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} OUTPUT_NAME sfizz)
|
||||||
sfizz_enable_lto_if_needed(sfizz_shared)
|
sfizz_enable_lto_if_needed(sfizz_shared)
|
||||||
|
|
|
||||||
|
|
@ -6,54 +6,50 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#if !defined(NDEBUG) || defined(SFIZZ_ENABLE_RELEASE_ASSERT)
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#if (__linux__ || __unix__)
|
|
||||||
|
|
||||||
// Break in source code
|
// Break in source code
|
||||||
#if (__x86_64__ || __i386__)
|
#if defined(_WIN32) && defined(_MSC_VER)
|
||||||
#define ASSERTFALSE \
|
|
||||||
do { \
|
|
||||||
std::cerr << "Assert failed at " << __FILE__ << ":" << __LINE__ << '\n'; \
|
|
||||||
__asm__("int3"); \
|
|
||||||
} while (0)
|
|
||||||
#elif (__arm__ || __aarch64__)
|
|
||||||
#define ASSERTFALSE \
|
|
||||||
do { \
|
|
||||||
std::cerr << "Assert failed at " << __FILE__ << ":" << __LINE__ << '\n'; \
|
|
||||||
__builtin_trap(); \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif (_WIN32 || _WIN64)
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma intrinsic(__debugbreak)
|
#pragma intrinsic(__debugbreak)
|
||||||
#endif
|
#define debugBreak() __debugbreak()
|
||||||
#define ASSERTFALSE \
|
#elif defined(_WIN32)
|
||||||
do { \
|
#define debugBreak() __debugbreak()
|
||||||
std::cerr << "Assert failed at " << __FILE__ << ":" << __LINE__ << '\n'; \
|
#elif defined(__x86_64__) || defined(__i386__)
|
||||||
__debugbreak(); \
|
#define debugBreak() asm volatile("int3")
|
||||||
} while (0)
|
#elif defined(__clang__) && ((__clang_major__ > 3) || (__clang_major__ == 3 && __clang_minor__ >= 2))
|
||||||
|
#define debugBreak() __builtin_debugtrap()
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#define debugBreak() __builtin_trap()
|
||||||
#else
|
#else
|
||||||
#define ASSERTFALSE do {} while (0)
|
#include <csignal>
|
||||||
|
#define debugBreak() ::raise(SIGTRAP)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Assert stuff
|
// Assert stuff
|
||||||
|
#define ASSERTFALSE \
|
||||||
|
do { \
|
||||||
|
std::cerr << "Assert failed at " << __FILE__ << ":" << __LINE__ << '\n'; \
|
||||||
|
debugBreak(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define ASSERT(expression) \
|
#define ASSERT(expression) \
|
||||||
do { \
|
do { \
|
||||||
if (!(expression)) \
|
if (!(expression)) \
|
||||||
ASSERTFALSE; \
|
ASSERTFALSE; \
|
||||||
} \
|
} while (0)
|
||||||
while (0)
|
|
||||||
|
|
||||||
// Debug message
|
|
||||||
#define DBG(ostream) do { std::cerr << ostream << '\n'; } while (0)
|
|
||||||
|
|
||||||
#else // NDEBUG
|
#else // NDEBUG
|
||||||
|
|
||||||
#define ASSERTFALSE do {} while (0)
|
#define ASSERTFALSE do {} while (0)
|
||||||
#define ASSERT(expression) do {} while (0)
|
#define ASSERT(expression) do {} while (0)
|
||||||
#define DBG(ostream) do {} while (0)
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Debug message
|
||||||
|
#if !defined(NDEBUG) || defined(SFIZZ_ENABLE_RELEASE_DBG)
|
||||||
|
#include <iostream>
|
||||||
|
#define DBG(ostream) do { std::cerr << ostream << '\n'; } while (0)
|
||||||
|
#else
|
||||||
|
#define DBG(ostream) do {} while (0)
|
||||||
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue