Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ if(CMAKE_TOOLCHAIN_FILE)
list(APPEND NBL_JPEG_CMAKE_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
endif()

nbl_append_sanitize_address_cmake_options(NBL_JPEG_CMAKE_OPTIONS)

# TODO: might find an alternative library which supports add_subdirectory, untill then we need to switch to a workaround just like
# we do for DXC due to: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/0b742742c873025e2a127918d4969238ace7ae5b/CMakeLists.txt#L69
execute_process(COMMAND "${CMAKE_COMMAND}" -S "${CMAKE_CURRENT_SOURCE_DIR}/libjpeg-turbo" -B "${CMAKE_CURRENT_BINARY_DIR}/libjpeg-turbo" -G "${CMAKE_GENERATOR}" ${NBL_JPEG_CMAKE_OPTIONS}
Expand Down Expand Up @@ -492,10 +494,6 @@ endif()
foreach(trgt IN LISTS NBL_3RDPARTY_TARGETS)
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL:${NBL_COMPILER_DYNAMIC_RUNTIME}>:DLL>")

if(MSVC AND NBL_SANITIZE_ADDRESS)
set_property(TARGET ${trgt} PROPERTY COMPILE_OPTIONS /fsanitize=address)
endif()

get_target_property(NBL_TARGET_TYPE ${trgt} TYPE)
if(NOT "${NBL_TARGET_TYPE}" STREQUAL "INTERFACE_LIBRARY")
# maybe explicit global mapping would be better, to discuss
Expand Down
6 changes: 5 additions & 1 deletion 3rdparty/dxc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ list(APPEND NBL_DXC_CMAKE_OPTIONS "-DDXC_SPIRV_TOOLS_DIR=${DXC_SPIRV_TOOLS_DIR}"
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DDXC_SPIRV_HEADERS_DIR=${DXC_SPIRV_HEADERS_DIR}")
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DDXC_ENABLE_ETW=OFF")

nbl_append_sanitize_address_cmake_options(NBL_DXC_CMAKE_OPTIONS)

if(NOT NBL_IS_MULTI_CONFIG)
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
endif()
Expand All @@ -54,7 +56,9 @@ endif()
#else()
# NBL_EXT_P_APPEND_COMPILE_OPTIONS(NBL_DXC_CMAKE_OPTIONS Release RelWithDebInfo Debug)
#endif()
#list(TRANSFORM NBL_DXC_CMAKE_OPTIONS REPLACE "/fp:fast" "/fp:precise")
if(MSVC AND NBL_SANITIZE_ADDRESS)
list(TRANSFORM NBL_DXC_CMAKE_OPTIONS REPLACE "/fp:fast" "/fp:precise")
endif()

if(WIN32)
if(NOT DEFINED HLSL_AUTOCRLF)
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/openexr
Submodule openexr updated 1 files
+0 −2 cmake/CMakeLists.txt
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# For conditions of distribution and use, see copyright notice in nabla.h.in or nabla.h
cmake_minimum_required(VERSION 3.31..4.2.0)

if(NOT DEFINED CMAKE_POLICY_VERSION_MINIMUM)
set(CMAKE_POLICY_VERSION_MINIMUM 3.31 CACHE STRING "Minimum policy version for third-party projects")
endif()

# TODO: Yas - once we deploy 4.x we will fire `cmake_policy(VERSION <min>[...<max>])` instead of manually picking policies
# https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html#policy-version
# also we should update deps which throw warnings about < 3.10 compatibility
Expand Down Expand Up @@ -46,6 +50,7 @@ option(NBL_STATIC_BUILD "" OFF) # ON for static builds, OFF for shared

option(NBL_COMPILER_DYNAMIC_RUNTIME "" ON)
option(NBL_SANITIZE_ADDRESS OFF)
option(NBL_DEBUG_RTC_ENABLED "Enable Runtime Checks for Debug builds" OFF)

set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT $<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>) # ignored on non xMSVC-ABI targets

Expand Down
11 changes: 9 additions & 2 deletions cmake/adjust/flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ function(nbl_adjust_flags)

# global compile options
list(APPEND _D_NBL_COMPILE_OPTIONS_ ${NBL_COMPILE_OPTIONS})
list(APPEND _D_NBL_LINK_OPTIONS_ ${NBL_LINK_OPTIONS})

foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER "${CONFIG}" CONFIG_U)
Expand Down Expand Up @@ -316,15 +317,21 @@ function(nbl_adjust_flags)

# global compile options
list(APPEND _D_NBL_COMPILE_OPTIONS_ ${NBL_COMPILE_OPTIONS})
list(APPEND _D_NBL_LINK_OPTIONS_ ${NBL_LINK_OPTIONS})
foreach(_NBL_OPTION_IMPL_ ${_NBL_OPTIONS_IMPL_})
string(REPLACE "NBL_MAP_" "" NBL_MAP_CONFIGURATION_FROM "NBL_${_NBL_OPTION_IMPL_}")
string(TOUPPER "${NBL_${_NBL_OPTION_IMPL_}}" NBL_MAP_CONFIGURATION_TO)
set(NBL_TO_CONFIG_COMPILE_OPTIONS ${NBL_${NBL_MAP_CONFIGURATION_TO}_COMPILE_OPTIONS})
set(NBL_TO_CONFIG_LINK_OPTIONS ${NBL_${NBL_MAP_CONFIGURATION_TO}_LINK_OPTIONS})

# per configuration compile options with mapping
list(APPEND _D_NBL_COMPILE_OPTIONS_ $<$<CONFIG:${NBL_MAP_CONFIGURATION_FROM}>:${NBL_TO_CONFIG_COMPILE_OPTIONS}>)
list(APPEND _D_NBL_LINK_OPTIONS_ $<$<CONFIG:${NBL_MAP_CONFIGURATION_FROM}>:${NBL_TO_CONFIG_LINK_OPTIONS}>)
endforeach()

set_directory_properties(PROPERTIES COMPILE_OPTIONS "${_D_NBL_COMPILE_OPTIONS_}")
set_directory_properties(PROPERTIES
COMPILE_OPTIONS "${_D_NBL_COMPILE_OPTIONS_}"
LINK_OPTIONS "${_D_NBL_LINK_OPTIONS_}"
)
endif()
endfunction()
endfunction()
6 changes: 3 additions & 3 deletions cmake/adjust/template/vendor/impl/Clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ else()
endif()

if(NBL_SANITIZE_ADDRESS)
NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} COMPILE_OPTIONS -fsanitize=address)
NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} COMPILE_OPTIONS -fsanitize=address LINK_OPTIONS -fsanitize=address)
endif()

if(NBL_SANITIZE_THREAD)
NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} COMPILE_OPTIONS -fsanitize=thread)
NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} COMPILE_OPTIONS -fsanitize=thread LINK_OPTIONS -fsanitize=thread)
endif()

NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} CONFIG DEBUG COMPILE_OPTIONS
Expand All @@ -106,4 +106,4 @@ else()
-mno-incremental-linker-compatible # https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mincremental-linker-compatible
-DNDEBUG
)
endif()
endif()
16 changes: 10 additions & 6 deletions cmake/adjust/template/vendor/impl/frontend/MSVC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,24 @@ if(NBL_SANITIZE_ADDRESS)
NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} COMPILE_OPTIONS
/fsanitize=address # https://learn.microsoft.com/en-us/cpp/build/reference/fsanitize?view=msvc-170
)

NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} CONFIG DEBUG COMPILE_OPTIONS
/RTC1 # https://learn.microsoft.com/en-us/cpp/build/reference/rtc-run-time-error-checks?view=msvc-170
)
endif()

NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} CONFIG DEBUG COMPILE_OPTIONS
set(_NBL_MSVC_DEBUG_COMPILE_OPTIONS
/Ob0 # https://learn.microsoft.com/en-us/cpp/build/reference/ob-inline-function-expansion?view=msvc-170
/Od # https://learn.microsoft.com/en-us/cpp/build/reference/od-disable-debug?view=msvc-170
/Oy- # https://learn.microsoft.com/en-us/cpp/build/reference/oy-frame-pointer-omission?view=msvc-170
)
if(NBL_DEBUG_RTC_ENABLED AND NOT NBL_SANITIZE_ADDRESS)
list(APPEND _NBL_MSVC_DEBUG_COMPILE_OPTIONS /RTC1)
endif()

NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} CONFIG DEBUG COMPILE_OPTIONS
${_NBL_MSVC_DEBUG_COMPILE_OPTIONS}

LINK_OPTIONS
/INCREMENTAL # https://learn.microsoft.com/en-us/cpp/build/reference/incremental-link-incrementally?view=msvc-170
)
unset(_NBL_MSVC_DEBUG_COMPILE_OPTIONS)

NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} CONFIG RELEASE COMPILE_OPTIONS
/O2 # https://learn.microsoft.com/en-us/cpp/build/reference/o1-o2-minimize-size-maximize-speed?view=msvc-170
Expand All @@ -63,4 +67,4 @@ NBL_REQUEST_COMPILE_OPTION_SUPPORT(LANG ${LANG} CONFIG RELWITHDEBINFO COMPILE_OP

LINK_OPTIONS
/INCREMENTAL # https://learn.microsoft.com/en-us/cpp/build/reference/incremental-link-incrementally?view=msvc-170
)
)
28 changes: 28 additions & 0 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@ include_guard(GLOBAL)

include(ProcessorCount)

# tmp for external projects, to be removed later when I get rid of them (dxc + jpeg currently)
function(nbl_append_sanitize_address_cmake_options out_list)
if(NOT NBL_SANITIZE_ADDRESS)
return()
endif()

if(MSVC)
set(_NBL_ASAN_FLAG "/fsanitize=address")
else()
set(_NBL_ASAN_FLAG "-fsanitize=address")
set(_NBL_ASAN_LINK_SUFFIX " ${_NBL_ASAN_FLAG}")
endif()

list(APPEND ${out_list}
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS} ${_NBL_ASAN_FLAG}"
"-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS} ${_NBL_ASAN_FLAG}"
)
if(DEFINED _NBL_ASAN_LINK_SUFFIX)
list(APPEND ${out_list}
"-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}${_NBL_ASAN_LINK_SUFFIX}"
"-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS}${_NBL_ASAN_LINK_SUFFIX}"
)
endif()
unset(_NBL_ASAN_FLAG)
unset(_NBL_ASAN_LINK_SUFFIX)
set(${out_list} "${${out_list}}" PARENT_SCOPE)
endfunction()

# Macro creating project for an executable
# Project and target get its name from directory when this macro gets executed (truncating number in the beginning of the name and making all lower case)
# Created because of common cmake code for examples and tools
Expand Down
5 changes: 4 additions & 1 deletion src/nbl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ nbl_adjust_flags(TARGET Nabla MAP_RELEASE Release MAP_RELWITHDEBINFO RelWithDebI
nbl_adjust_definitions()

option(NBL_WAVE_STRING_RESOLVER_TU_DEBUG_OPTIMISATION "Enable to optimise CWaveStringResolver.cpp in Debug configuration, uses RWDI compile options for the TU" ON)
if(NBL_SANITIZE_ADDRESS OR NBL_DEBUG_RTC_ENABLED)
set(NBL_WAVE_STRING_RESOLVER_TU_DEBUG_OPTIMISATION OFF CACHE BOOL "" FORCE)
endif()
if(NBL_WAVE_STRING_RESOLVER_TU_DEBUG_OPTIMISATION)
set_source_files_properties(asset/utils/CWaveStringResolver.cpp PROPERTIES
# just enabling inlining and optimisations will help a lot
Expand Down Expand Up @@ -868,4 +871,4 @@ source_group(TREE "${NBL_ROOT_PATH}"
source_group(TREE "${NBL_ROOT_PATH}"
PREFIX "Source Files"
FILES ${NABLA_SOURCE_FILES}
)
)
3 changes: 0 additions & 3 deletions src/nbl/builtin/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,4 @@ function(ADD_CUSTOM_BUILTIN_RESOURCES _TARGET_NAME_ _BUNDLE_NAME_ _BUNDLE_SEARCH
_ADD_PROPERTY_(BUILTIN_RESOURCES_HEADERS NBL_BUILTIN_RESOURCES_HEADERS)
_ADD_PROPERTY_(BUILTIN_RESOURCES_INCLUDE_SEARCH_DIRECTORY _OUTPUT_INCLUDE_SEARCH_DIRECTORY_CONFIG)

if(MSVC AND NBL_SANITIZE_ADDRESS)
set_property(TARGET ${_TARGET_NAME_} PROPERTY COMPILE_OPTIONS /fsanitize=address)
endif()
endfunction()
Loading
Loading