mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-06 01:13:16 +02:00
* Disables WebRTC (build fails) * Recommends disabling optimization * Recommends enabling debugging * Remove forced optimization from plugins
67 lines
3.6 KiB
CMake
67 lines
3.6 KiB
CMake
#
|
|
# MemoryDebugger.cmake
|
|
#
|
|
# Copyright 2015 High Fidelity, Inc.
|
|
# Copyright 2023 Overte e.V.
|
|
#
|
|
# Distributed under the Apache License, Version 2.0.
|
|
# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
macro(SETUP_MEMORY_DEBUGGER)
|
|
if ("$ENV{OVERTE_MEMORY_DEBUGGING}")
|
|
if (OVERTE_THREAD_DEBUGGING)
|
|
message(FATAL_ERROR "Thread debugging and memory debugging can't be enabled at the same time." )
|
|
endif()
|
|
|
|
if (OVERTE_OPTIMIZE)
|
|
message(WARNING "You should consider building without optimization by passing -DOVERTE_OPTIMIZE=false to CMake")
|
|
endif()
|
|
if (NOT CMAKE_BUILD_TYPE MATCHES "Debug")
|
|
message(WARNING "You should consider building with debugging enabled by passing -DCMAKE_BUILD_TYPE=Debug to CMake. Current type is ${CMAKE_BUILD_TYPE}")
|
|
endif()
|
|
|
|
|
|
SET( OVERTE_MEMORY_DEBUGGING true )
|
|
SET ( DISABLE_WEBRTC true )
|
|
endif ()
|
|
|
|
if ( OVERTE_MEMORY_DEBUGGING)
|
|
# WebRTC doesn't work with memory debugging enabled, it fails to link:
|
|
# /usr/bin/ld: ../../libraries/networking/libnetworking.so: undefined reference to `typeinfo for rtc::Thread'
|
|
# /usr/bin/ld: ../../libraries/networking/libnetworking.so: undefined reference to `typeinfo for webrtc::SessionDescriptionInterface'
|
|
# /usr/bin/ld: ../../libraries/networking/libnetworking.so: undefined reference to `typeinfo for webrtc::IceCandidateInterface'
|
|
add_compile_definitions(DISABLE_WEBRTC)
|
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address -fsanitize-recover=address")
|
|
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address -fsanitize-recover=address")
|
|
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address -fsanitize-recover=address")
|
|
if (UNIX)
|
|
# Only supported on Linux and OSX
|
|
# https://clang.llvm.org/docs/LeakSanitizer.html
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak")
|
|
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=leak")
|
|
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=leak")
|
|
endif()
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|
# for gcc
|
|
# For some reason, using -fstack-protector results in this error:
|
|
# usr/bin/ld: ../../libraries/audio/libaudio.so: undefined reference to `FIR_1x4_AVX512(float*, float*, float*, float*, float*, float (*) [64], int)'
|
|
# The '-DSTACK_PROTECTOR' argument below disables the usage of this function in the code. This should be fine as it only works on the latest Intel hardware,
|
|
# and is an optimization that should make no functional difference.
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fsanitize=address -fsanitize=leak -U_FORTIFY_SOURCE -DSTACK_PROTECTOR -fstack-protector-strong -fno-omit-frame-pointer")
|
|
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address -fsanitize=leak ")
|
|
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address -fsanitize=leak")
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
# https://docs.microsoft.com/en-us/cpp/sanitizers/asan?view=msvc-160
|
|
# Supported experimentally starting from VS2019 v16.4, and officially from v16.9.
|
|
# UBSan and leak detection don't seem to be implemented yet.
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address /Zi")
|
|
else()
|
|
message(FATAL_ERROR "Memory debugging is not supported on this compiler.")
|
|
endif()
|
|
endif ()
|
|
endmacro(SETUP_MEMORY_DEBUGGER)
|