Add CMake options to control assertion levels
This commit is contained in:
parent
33cff49a20
commit
a6f15d6334
3 changed files with 29 additions and 2 deletions
|
|
@ -6,6 +6,14 @@ cmake_minimum_required(VERSION 3.3)
|
|||
project(cppast VERSION 0.0)
|
||||
|
||||
# options
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
set(default_assertions ON)
|
||||
else()
|
||||
set(default_assertions OFF)
|
||||
endif()
|
||||
option(CPPAST_ENABLE_ASSERTIONS "whether or not to enable internal assertions for the cppast library" ${default_assertions})
|
||||
option(CPPAST_ENABLE_PRECONDITION_CHECKS "whether or not to enable precondition checks" ON)
|
||||
|
||||
option(CPPAST_BUILD_TEST "whether or not to build the tests" ON)
|
||||
|
||||
include(external/external.cmake)
|
||||
|
|
|
|||
|
|
@ -7,15 +7,28 @@
|
|||
|
||||
#include <debug_assert.hpp>
|
||||
|
||||
#ifdef CPPAST_ENABLE_ASSERTIONS
|
||||
#define CPPAST_ASSERTION_LEVEL 1
|
||||
#else
|
||||
#define CPPAST_ASSERTION_LEVEL 0
|
||||
#endif
|
||||
|
||||
#ifdef CPPAST_ENABLE_PRECONDITION_CHECKS
|
||||
#define CPPAST_PRECONDITION_LEVEL 1
|
||||
#else
|
||||
#define CPPAST_PRECONDITION_LEVEL 0
|
||||
#endif
|
||||
|
||||
namespace cppast
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
struct assert_handler : debug_assert::set_level<1>, debug_assert::default_handler
|
||||
struct assert_handler : debug_assert::set_level<CPPAST_ASSERTION_LEVEL>,
|
||||
debug_assert::default_handler
|
||||
{
|
||||
};
|
||||
|
||||
struct precondition_error_handler : debug_assert::set_level<1>,
|
||||
struct precondition_error_handler : debug_assert::set_level<CPPAST_PRECONDITION_LEVEL>,
|
||||
debug_assert::default_handler
|
||||
{
|
||||
};
|
||||
|
|
|
|||
|
|
@ -101,4 +101,10 @@ target_compile_definitions(cppast PUBLIC
|
|||
CPPAST_LIBCLANG_SYSTEM_INCLUDE_DIR="${LIBCLANG_SYSTEM_INCLUDE_DIR}"
|
||||
CPPAST_CLANG_BINARY="${CLANG_BINARY}"
|
||||
CPPAST_CLANG_VERSION_STRING="${LLVM_VERSION}")
|
||||
if(CPPAST_ENABLE_ASSERTIONS)
|
||||
target_compile_definitions(cppast PUBLIC CPPAST_ENABLE_ASSERTIONS)
|
||||
endif()
|
||||
if(CPPAST_ENABLE_PRECONDITION_CHECKS)
|
||||
target_compile_definitions(cppast PUBLIC CPPAST_ENABLE_PRECONDITION_CHECKS)
|
||||
endif()
|
||||
set_target_properties(cppast PROPERTIES CXX_STANDARD 11)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue