Skip to content

Commit 5bb6b8b

Browse files
committed
Merge branch 'master' into for-0.56.0/sync
2 parents f52aaeb + 83cc4b3 commit 5bb6b8b

File tree

22 files changed

+345
-799
lines changed

22 files changed

+345
-799
lines changed

CMakeLists.txt

Lines changed: 5 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,7 @@
2424
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2525
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

27-
cmake_minimum_required (VERSION 3.12)
28-
29-
# Choose Python versions by location instead of getting whatever is in PYTHON_EXECUTABLE
30-
# Can be removed once we require CMake 3.15
31-
if (POLICY CMP0094)
32-
cmake_policy(SET CMP0094 NEW)
33-
endif()
34-
35-
if (POLICY CMP0072)
36-
cmake_policy(SET CMP0072 NEW)
37-
endif()
27+
cmake_minimum_required(VERSION 3.18.4)
3828

3929
if(NOT DAEMON_DIR)
4030
set(DAEMON_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
@@ -135,25 +125,7 @@ option(USE_HARDENING "Use stack protection and other hardening flags" OFF)
135125
option(USE_WERROR "Tell the compiler to make the build fail when warnings are present" OFF)
136126
option(USE_PEDANTIC "Tell the compiler to be pedantic" OFF)
137127
option(USE_DEBUG_OPTIMIZE "Try to optimize the debug build" ON)
138-
139-
if (CMAKE_GENERATOR MATCHES "^Ninja" OR APPLE)
140-
# It isn't currently supported with Ninja yet:
141-
#
142-
# > Note that the IMPLICIT_DEPENDS option is currently supported only for
143-
# > Makefile generators and will be ignored by other generators. Note that
144-
# > the IMPLICIT_DEPENDS option is currently supported only for Makefile
145-
# > generators and will be ignored by other generators.
146-
# > -- https://cmake.org/cmake/help/latest/command/add_custom_command.html
147-
#
148-
# It would be better to be able to know if IMPLICIT_DEPENDS is supported
149-
# by the current generator instead of comparing generator name.
150-
151-
# It is broken on macOS.
152-
# See: https://github.com/DaemonEngine/Daemon/issues/1549
153-
option(USE_PRECOMPILED_HEADER "Improve build times by using a precompiled header" OFF)
154-
else()
155-
option(USE_PRECOMPILED_HEADER "Improve build times by using a precompiled header" ON)
156-
endif()
128+
option(USE_PRECOMPILED_HEADER "Improve build times by using a precompiled header" ON)
157129
option(USE_ADDRESS_SANITIZER "Try to use the address sanitizer" OFF)
158130
option(BE_VERBOSE "Tell the compiler to report all warnings" OFF)
159131
option(USE_STATIC_LIBS "Tries to use static libs where possible. Only works for Linux" OFF)
@@ -371,92 +343,9 @@ endif()
371343
# Support for precompiled headers
372344
################################################################################
373345

374-
# MSVC requires that an extra file be added to a project
375-
if (USE_PRECOMPILED_HEADER AND MSVC)
376-
file(WRITE ${OBJ_DIR}/PrecompiledHeader.cpp "")
377-
set(PCH_FILE ${OBJ_DIR}/PrecompiledHeader.cpp)
378-
if (DAEMON_PARENT_SCOPE_DIR)
379-
set(PCH_FILE ${PCH_FILE} PARENT_SCOPE)
380-
endif()
381-
endif()
382-
383346
function(ADD_PRECOMPILED_HEADER Target)
384-
if (NOT USE_PRECOMPILED_HEADER OR CMAKE_VERSION VERSION_LESS 2.8.10)
385-
return()
386-
endif()
387-
388-
# Get the common compile flags
389-
set(Flags ${CMAKE_CXX_FLAGS} ${WARNINGS})
390-
get_target_property(Type ${Target} TYPE)
391-
if (Type STREQUAL MODULE_LIBRARY)
392-
set(Flags ${Flags} ${CMAKE_SHARED_MODULE_CXX_FLAGS})
393-
endif()
394-
separate_arguments(Flags)
395-
396-
# Get the per-configuration compile flags
397-
foreach(Config DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
398-
set(ConfigFlags ${CMAKE_CXX_FLAGS_${Config}})
399-
separate_arguments(ConfigFlags)
400-
foreach(Flag ${ConfigFlags})
401-
set(Flags ${Flags} $<${${Config}_GENEXP_COND}:${Flag}>)
402-
endforeach()
403-
endforeach()
404-
405-
# Get preprocessor options for the target and directory (global)
406-
get_directory_property(DirCompileDefs COMPILE_DEFINITIONS)
407-
get_directory_property(DirIncludeDirs INCLUDE_DIRECTORIES)
408-
get_target_property(TargetCompileDefs ${Target} COMPILE_DEFINITIONS)
409-
get_target_property(TargetIncludeDirs ${Target} INCLUDE_DIRECTORIES)
410-
set(Defs)
411-
foreach(Def ${TargetCompileDefs})
412-
set(Defs ${Defs} -D${Def})
413-
endforeach()
414-
foreach(Def ${DirCompileDefs})
415-
set(Defs ${Defs} -D${Def})
416-
endforeach()
417-
foreach(Def ${DirIncludeDirs})
418-
set(Defs ${Defs} -I${Def})
419-
endforeach()
420-
foreach(Def ${TargetIncludeDirs})
421-
set(Defs ${Defs} -I${Def})
422-
endforeach()
423-
424-
# Specify minimum OSX version
425-
if (APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET)
426-
set(Flags ${Flags} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET})
427-
endif()
428-
429-
set(Header ${COMMON_DIR}/Common.h)
430-
431-
# Compiler-specific PCH support
432-
if ((DAEMON_CXX_COMPILER_GCC_COMPATIBILITY OR DAEMON_CXX_COMPILER_Clang_COMPATIBILITY)
433-
AND NOT DAEMON_CXX_COMPILER_ICC)
434-
# CMAKE_CXX_COMPILER_ARG1 is used with compilers using subcommands.
435-
# For example when doing: cmake -D'CMAKE_CXX_COMPILER'='zig;c++'
436-
# CMAKE_CXX_COMPILER will be "zig",
437-
# CMAKE_CXX_COMPILER_ARG1 will be "c++".
438-
add_custom_command(OUTPUT "${OBJ_DIR}/${Target}.h.gch"
439-
COMMAND ${PNACLPYTHON_PREFIX2} ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}
440-
${Defs} ${Flags} -x c++-header ${Header} -o "${OBJ_DIR}/${Target}.h.gch"
441-
DEPENDS ${Header}
442-
IMPLICIT_DEPENDS CXX ${Header}
443-
)
444-
445-
add_custom_target(${Target}-pch DEPENDS "${OBJ_DIR}/${Target}.h.gch")
446-
add_dependencies(${Target} ${Target}-pch)
447-
448-
# PNaCl clang doesn't support -include-pch properly
449-
if (DAEMON_CXX_COMPILER_Clang_COMPATIBILITY
450-
AND NOT DAEMON_CXX_COMPILER_PNaCl)
451-
set_property(TARGET ${Target} APPEND PROPERTY COMPILE_OPTIONS "-include-pch;${OBJ_DIR}/${Target}.h.gch")
452-
else()
453-
set_property(TARGET ${Target} APPEND PROPERTY COMPILE_OPTIONS "-include;${OBJ_DIR}/${Target}.h;-Winvalid-pch")
454-
endif()
455-
elseif (MSVC)
456-
# /Fp sets the PCH path used by either of the /Yc and /Yu options.
457-
# /Yc overrides /Yu.
458-
set_source_files_properties(${PCH_FILE} PROPERTIES COMPILE_FLAGS "/Yc${Header}")
459-
target_compile_options(${Target} PRIVATE "/Yu${Header}" "/Fp${OBJ_DIR}/${Target}_$<CONFIG>.pch" "/FI${Header}")
347+
if (USE_PRECOMPILED_HEADER)
348+
target_precompile_headers(${Target} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:\"${COMMON_DIR}/Common.h\">")
460349
endif()
461350
endfunction()
462351

@@ -1024,6 +913,7 @@ if (BUILD_CLIENT)
1024913
set(CLIENT_EXECUTABLE_NAME daemon-vulkan)
1025914
else()
1026915
set(CLIENT_EXECUTABLE_NAME daemon)
916+
set(CLIENTTESTLIST ${CLIENTTESTLIST} ${RENDERERTESTLIST})
1027917
endif()
1028918

1029919
AddApplication(

cmake/DaemonFlags.cmake

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,4 @@ endif()
695695

696696
# Configuration specific definitions
697697

698-
# This stupid trick to define THIS_IS_NOT_A_DEBUG_BUILD (rather than nothing) in the non-debug case
699-
# is so that it doesn't break the hacky gcc/clang PCH code which reads all the definitions
700-
# and prefixes "-D" to them.
701-
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS
702-
$<$<NOT:${DEBUG_GENEXP_COND}>:THIS_IS_NOT_A_>DEBUG_BUILD)
698+
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<${DEBUG_GENEXP_COND}:DEBUG_BUILD>)
-21.6 KB
Binary file not shown.

src.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ if (APPLE)
301301
endif()
302302

303303
set(CLIENTTESTLIST ${ENGINETESTLIST}
304-
${ENGINE_DIR}/renderer/gl_shader_test.cpp
305304
)
306305

307306
set(TTYCLIENTLIST

src/common/Log.cpp

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,79 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

3131
#include "Common.h"
3232

33+
#ifdef BUILD_ENGINE
34+
// TODO: when cvar multiple registration is available, just declare the cvars in each module.
35+
static Cvar::Cvar<bool> suppressionEnabled(
36+
"logs.suppression.enabled", "Whether to suppress log messages that are printed too many times", Cvar::NONE, true);
37+
static Cvar::Range<Cvar::Cvar<int>> suppressionInterval(
38+
"logs.suppression.interval", "Interval in milliseconds for detecting log spam", Cvar::NONE, 2000, 1, 1000000);
39+
static Cvar::Range<Cvar::Cvar<int>> suppressionCount(
40+
"logs.suppression.count", "Number of occurrences for a message to be considered log spam", Cvar::NONE, 10, 1, 1000000);
41+
static Cvar::Range<Cvar::Cvar<int>> suppressionBufSize(
42+
"logs.suppression.bufferSize", "How many distinct messages to track for log suppression", Cvar::NONE, 50, 1, 1000000);
43+
static Cvar::Cvar<bool> logExtendAll(
44+
"logs.writeSrcLocation.all", "Always print source code location for logs", Cvar::NONE, false);
45+
static Cvar::Cvar<bool> logExtendWarn(
46+
"logs.writeSrcLocation.warn", "Print source code location for Warn logs", Cvar::NONE, false);
47+
static Cvar::Cvar<bool> logExtendNotice(
48+
"logs.writeSrcLocation.notice", "Print source code location for Notice logs", Cvar::NONE, false);
49+
static Cvar::Cvar<bool> logExtendVerbose(
50+
"logs.writeSrcLocation.verbose", "Print source code location for Verbose logs", Cvar::NONE, false);
51+
static Cvar::Cvar<bool> logExtendDebug(
52+
"logs.writeSrcLocation.debug", "Print source code location for Debug logs", Cvar::NONE, false);
53+
54+
#define GET_LOG_CVAR(type, name, object) (object.Get())
55+
#else
56+
#define GET_LOG_CVAR(type, name, object) (GetCvarOrDie<type>(name))
57+
template <typename T>
58+
static T GetCvarOrDie(Str::StringRef cvar) {
59+
T value;
60+
std::string valueString = Cvar::GetValue(cvar);
61+
if (!Cvar::ParseCvarValue(valueString, value)) {
62+
Sys::Error("Failed to deserialize cvar %s with value: %s", cvar, valueString);
63+
}
64+
return value;
65+
}
66+
#endif
67+
3368
namespace Log {
34-
Cvar::Cvar<bool> logExtendAll(
35-
"logs.writeSrcLocation.all", "Always print source code location for logs", Cvar::NONE, false );
36-
Cvar::Cvar<bool> logExtendWarn(
37-
"logs.writeSrcLocation.warn", "Print source code location for Warn logs", Cvar::NONE, false );
38-
Cvar::Cvar<bool> logExtendNotice(
39-
"logs.writeSrcLocation.notice", "Print source code location for Notice logs", Cvar::NONE, false );
40-
Cvar::Cvar<bool> logExtendVerbose(
41-
"logs.writeSrcLocation.verbose", "Print source code location for Verbose logs", Cvar::NONE, false );
42-
Cvar::Cvar<bool> logExtendDebug(
43-
"logs.writeSrcLocation.debug", "Print source code location for Debug logs", Cvar::NONE, false );
4469

4570
Logger::Logger(Str::StringRef name, std::string prefix, Level defaultLevel)
4671
: filterLevel(new Cvar::Cvar<Log::Level>(
4772
"logs.level." + name, "Log::Level - logs from '" + name + "' below the level specified are filtered", 0, defaultLevel)),
48-
prefix(prefix), enableSuppression(true) {
73+
enableSuppression(true)
74+
{
75+
if (!prefix.empty()) {
76+
// TODO allow prefixes without a space, e.g. a color code
77+
this->prefix = prefix + " ";
78+
}
4979
}
5080

51-
std::string Logger::Prefix(std::string message) const {
52-
if (prefix.empty()) {
53-
return message;
54-
} else {
55-
return prefix + " " + message;
81+
std::string Logger::Prefix(Str::StringRef message) const {
82+
return prefix + message;
83+
}
84+
85+
static bool WantLocationInfo(Log::Level level) {
86+
if (GET_LOG_CVAR(bool, "logs.writeSrcLocation.all", logExtendAll)) {
87+
return true;
88+
}
89+
switch (level) {
90+
case Log::Level::DEBUG:
91+
return GET_LOG_CVAR(bool, "logs.writeSrcLocation.debug", logExtendDebug);
92+
case Log::Level::VERBOSE:
93+
return GET_LOG_CVAR(bool, "logs.writeSrcLocation.verbose", logExtendVerbose);
94+
case Log::Level::NOTICE:
95+
return GET_LOG_CVAR(bool, "logs.writeSrcLocation.notice", logExtendNotice);
96+
case Log::Level::WARNING:
97+
return GET_LOG_CVAR(bool, "logs.writeSrcLocation.warn", logExtendWarn);
5698
}
99+
ASSERT_UNREACHABLE();
57100
}
58101

59-
void Logger::Dispatch(std::string message, Log::Level level, Str::StringRef format) {
102+
void Logger::Dispatch(std::string message, Log::Level level, Str::StringRef format, const char* file, const char* function, int line) {
103+
if (WantLocationInfo(level)) {
104+
message = Str::Format("%s ^F(%s:%u, %s)", message, file, line, function);
105+
}
60106
if (enableSuppression) {
61107
Log::DispatchWithSuppression(std::move(message), level, format);
62108
} else {
@@ -136,15 +182,6 @@ namespace Log {
136182
}
137183
}
138184

139-
template <typename T>
140-
static T GetCvarOrDie(Str::StringRef cvar) {
141-
T value;
142-
std::string valueString = Cvar::GetValue(cvar);
143-
if (!Cvar::ParseCvarValue(valueString, value)) {
144-
Sys::Error("Failed to deserialize cvar %s with value: %s", cvar, valueString);
145-
}
146-
return value;
147-
}
148185
namespace {
149186
// Log-spam suppression: if more than MAX_OCCURRENCES log messages with the same format string
150187
// are sent in less than INTERVAL_MS milliseconds, they will stop being printed.
@@ -166,9 +203,9 @@ namespace Log {
166203
};
167204
Result UpdateAndEvaluate(Str::StringRef messageFormat) {
168205
std::lock_guard<std::mutex> lock(mutex);
169-
int intervalMs = GetCvarOrDie<int>("logs.suppression.interval");
170-
int maxOccurrences = GetCvarOrDie<int>("logs.suppression.count");
171-
int bufferSize = GetCvarOrDie<int>("logs.suppression.bufferSize");
206+
int intervalMs = GET_LOG_CVAR(int, "logs.suppression.interval", suppressionInterval);
207+
int maxOccurrences = GET_LOG_CVAR(int, "logs.suppression.count", suppressionCount);
208+
int bufferSize = GET_LOG_CVAR(int, "logs.suppression.bufferSize", suppressionBufSize);
172209
buf.resize(bufferSize);
173210
MessageStatistics* oldest = &buf[0];
174211
int now = Sys::Milliseconds();
@@ -199,7 +236,7 @@ namespace Log {
199236

200237
void DispatchWithSuppression(std::string message, Log::Level level, Str::StringRef format) {
201238
static LogSpamSuppressor suppressor;
202-
if (level == Level::DEBUG || !GetCvarOrDie<bool>("logs.suppression.enabled")) {
239+
if (level == Level::DEBUG || !GET_LOG_CVAR(bool, "logs.suppression.enabled", suppressionEnabled)) {
203240
DispatchByLevel(std::move(message), level);
204241
return;
205242
}

0 commit comments

Comments
 (0)