Skip to content

Commit 2e0378d

Browse files
authored
Add more CMake options (#1715)
* Enable colored diagnostics A well-known limitation of using ninja is that it requires the user to pass -fcolor-diagnostics=always flag to the compiler to get colored diagnostics. Starting from version 3.24, CMake can do this for us if we set CMAKE_COLOR_DIAGNOSTICS flag to a truthful value. * Add CMake option to disable GDB backtrace on fatal signal Backtraces we produce are very verbose and somewhat useless. They also are sometimes so long that they fill all of terminal scrollback and hide the actual error. * Add an off-by-default CMake option for using LLD as a linker Using LLD gives a 3-fold link-time improvement on my machine.
1 parent f42d13e commit 2e0378d

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ set(CMAKE_CXX_STANDARD 20)
3333
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
3434
set(CMAKE_CXX_EXTENSIONS FALSE)
3535

36+
set(CMAKE_COLOR_DIAGNOSTICS TRUE)
37+
3638
#BEGIN internal
3739
option(BUILD_SHARED_LIBS "Use \"ON\" to build shared libraries instead of static where it's not specified (not recommended)" OFF)
3840
option(USE_EMSCRIPTEN "Use \"ON\" for config building wasm." OFF)
@@ -56,6 +58,16 @@ option(TON_USE_TSAN "Use \"ON\" to enable ThreadSanitizer." OFF)
5658
option(TON_USE_UBSAN "Use \"ON\" to enable UndefinedBehaviorSanitizer." OFF)
5759
set(TON_ARCH "native" CACHE STRING "Architecture, will be passed to -march=")
5860

61+
option(TON_PRINT_BACKTRACE_ON_CRASH "Attempt to print a backtrace when a fatal signal is caught" ON)
62+
63+
option(TON_USE_LLD "Use LLD for linking" OFF)
64+
65+
if (TON_USE_LLD)
66+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
67+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
68+
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
69+
endif()
70+
5971
#BEGIN M1 support
6072
EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )
6173

tdutils/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ set(TDUTILS_TEST_SOURCE
319319
PARENT_SCOPE
320320
)
321321

322+
if (NOT TON_PRINT_BACKTRACE_ON_CRASH)
323+
set_source_files_properties(td/utils/port/signals.cpp PROPERTIES COMPILE_DEFINITIONS TON_DISABLE_BACKTRACE)
324+
endif()
325+
322326
#RULES
323327
#LIBRARIES
324328
add_library(tdutils STATIC ${TDUTILS_SOURCE})

tdutils/td/utils/port/signals.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static void block_stdin() {
317317
#endif
318318
}
319319

320-
static void default_failure_signal_handler(int sig) {
320+
[[maybe_unused]] static void default_failure_signal_handler(int sig) {
321321
Stacktrace::init();
322322
signal_safe_write_signal_number(sig);
323323

@@ -334,9 +334,11 @@ Status set_default_failure_signal_handler() {
334334
Stdin(); // init static variables before atexit
335335
#endif
336336
std::atexit(block_stdin);
337+
#ifndef TON_DISABLE_BACKTRACE
337338
TRY_STATUS(setup_signals_alt_stack());
338339
TRY_STATUS(set_signal_handler(SignalType::Abort, default_failure_signal_handler));
339340
TRY_STATUS(set_signal_handler(SignalType::Error, default_failure_signal_handler));
341+
#endif
340342
return Status::OK();
341343
}
342344

0 commit comments

Comments
 (0)