diff --git a/CMakeLists.txt b/CMakeLists.txt index 5aa5831e0f..302d2f90e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,11 @@ cmake_minimum_required(VERSION 2.8) project(nxt C CXX) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING + "Build type (Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE) +endif() + ################################################################################ # Configuration options ################################################################################ @@ -35,6 +40,7 @@ option(NXT_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL option(NXT_ENABLE_NULL "Enable compilation of the Null backend" ON) option(NXT_ENABLE_OPENGL "Enable compilation of the OpenGL backend" ON) option(NXT_ENABLE_VULKAN "Enable compilation of the Vulkan backend" OFF) +option(NXT_ALWAYS_ASSERT "Enable assertions on all build types" OFF) ################################################################################ # Precompute compile flags and defines, functions to set them @@ -46,9 +52,9 @@ set(NXT_INTERNAL_FLAGS "") set(NXT_INTERNAL_DEFS "") set(NXT_GENERATED_FLAGS "") -if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - list(APPEND NXT_DEFS "NXT_ENABLE_ASSERTS") -endif() +set(NXT_ENABLE_ASSERTS $,$>) + +list(APPEND NXT_DEFS $<${NXT_ENABLE_ASSERTS}:NXT_ENABLE_ASSERTS>) if (NXT_ENABLE_D3D12) list(APPEND NXT_INTERNAL_DEFS "NXT_ENABLE_BACKEND_D3D12") @@ -84,7 +90,7 @@ if (MSVC) list(APPEND NXT_GENERATED_FLAGS "/wd4702") # Allow unreachable code list(APPEND NXT_GENERATED_FLAGS "/wd4189") # Allow unused variable - + if(NXT_USE_WERROR) list(APPEND NXT_INTERNAL_FLAGS "/WX") endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d49f3d109d..addb21c838 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -24,7 +24,7 @@ function(add_nxt_sample target sources) target_link_libraries(${target} sample_utils) target_include_directories(${target} SYSTEM PRIVATE ${GLM_INCLUDE_DIR}) target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - NXTInternaltarget("examples" ${target}) + NXTInternalTarget("examples" ${target}) # Suppress some warnings in our sample dependencies if (MSVC) diff --git a/src/common/Assert.h b/src/common/Assert.h index 9a24b3f408..3c96370d3f 100644 --- a/src/common/Assert.h +++ b/src/common/Assert.h @@ -68,7 +68,7 @@ void HandleAssertionFailure(const char* file, const char* function, int line, co #define NXT_ASSERT(condition) NXT_ASSERT_CALLSITE_HELPER(__FILE__, __func__, __LINE__, condition) #define NXT_UNREACHABLE() \ do { \ - NXT_ASSERT(false && "Unreachable code hit"); NXT_BUILTIN_UNREACHABLE(); \ + NXT_ASSERT(NXT_ASSERT_LOOP_CONDITION && "Unreachable code hit"); NXT_BUILTIN_UNREACHABLE(); \ } while(NXT_ASSERT_LOOP_CONDITION) #if !defined(NXT_SKIP_ASSERT_SHORTHANDS) diff --git a/src/common/Math.cpp b/src/common/Math.cpp index da5455e57c..5fc2a40705 100644 --- a/src/common/Math.cpp +++ b/src/common/Math.cpp @@ -62,7 +62,9 @@ void* AlignVoidPtr(void* ptr, size_t alignment) { } uint32_t Align(uint32_t value, size_t alignment) { + ASSERT(alignment <= UINT32_MAX); ASSERT(IsPowerOfTwo(alignment)); ASSERT(alignment != 0); - return (value + (alignment - 1)) & ~(alignment - 1); + uint32_t alignment32 = static_cast(alignment); + return (value + (alignment32 - 1)) & ~(alignment32 - 1); }