diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a82471..05aadbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/cppast/detail/assert.hpp b/include/cppast/detail/assert.hpp index 1093b6e..7af9903 100644 --- a/include/cppast/detail/assert.hpp +++ b/include/cppast/detail/assert.hpp @@ -7,15 +7,28 @@ #include +#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, + debug_assert::default_handler { }; - struct precondition_error_handler : debug_assert::set_level<1>, + struct precondition_error_handler : debug_assert::set_level, debug_assert::default_handler { }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5114b03..119dc90 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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)