Skip to content

Commit 475898e

Browse files
committed
feat cmake: implement -gz=zstd
Before: ``` build_debug$ ls -lh samples/hello_service/userver-samples-hello_service -rwxrwxr-x 1 segoon segoon 78M Jan 28 19:32 samples/hello_service/userver-samples-hello_service ``` After: ``` build_debug$ ls -lh samples/hello_service/userver-samples-hello_service -rwxrwxr-x 1 segoon segoon 37M Jan 28 19:20 samples/hello_service/userver-samples-hello_service ``` commit_hash:d09e127fadf845e60d1f4be0e59879148a1ac1f5
1 parent d47b4ed commit 475898e

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

.mapping.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@
402402
"cmake/SetupCURL.cmake":"taxi/uservices/userver/cmake/SetupCURL.cmake",
403403
"cmake/SetupClickhouseCPP.cmake":"taxi/uservices/userver/cmake/SetupClickhouseCPP.cmake",
404404
"cmake/SetupCryptoPP.cmake":"taxi/uservices/userver/cmake/SetupCryptoPP.cmake",
405+
"cmake/SetupDebugInfoCompression.cmake":"taxi/uservices/userver/cmake/SetupDebugInfoCompression.cmake",
405406
"cmake/SetupFmt.cmake":"taxi/uservices/userver/cmake/SetupFmt.cmake",
406407
"cmake/SetupGBench.cmake":"taxi/uservices/userver/cmake/SetupGBench.cmake",
407408
"cmake/SetupGTest.cmake":"taxi/uservices/userver/cmake/SetupGTest.cmake",

cmake/SetupDebugInfoCompression.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function(setup_linker_debug_info_compression)
2+
write_file("${CMAKE_CURRENT_BINARY_DIR}/empty.cpp" "int main() {return 0;}")
3+
try_compile(LINKER_HAS_ZSTD ${CMAKE_CURRENT_BINARY_DIR}
4+
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/empty.cpp
5+
LINK_OPTIONS -Werror -gz=zstd
6+
)
7+
if (NOT LINKER_HAS_ZSTD)
8+
try_compile(LINKER_HAS_GZ ${CMAKE_CURRENT_BINARY_DIR}
9+
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/empty.cpp
10+
LINK_OPTIONS -Werror -gz
11+
)
12+
endif()
13+
14+
if(LINKER_HAS_ZSTD)
15+
message(STATUS "Using linker debug info compression: zstd")
16+
add_link_options("-gz=zstd")
17+
elseif(LINKER_HAS_GZ)
18+
message(STATUS "Using linker debug info compression: z")
19+
add_link_options("-gz")
20+
else()
21+
message(STATUS "Using linker debug info compression: none")
22+
endif()
23+
endfunction()
24+
25+
function(setup_compiler_debug_info_compression)
26+
userver_is_cxx_compile_option_supported(COMPILER_HAS_ZSTD "-gz=zstd")
27+
28+
if(COMPILER_HAS_ZSTD)
29+
message(STATUS "Using compiler debug info compression: zstd")
30+
add_compile_options("-gz=zstd")
31+
else()
32+
message(STATUS "Using compiler debug info compression: z")
33+
add_compile_options("-gz")
34+
endif()
35+
endfunction()
36+
37+
setup_linker_debug_info_compression()
38+
setup_compiler_debug_info_compression()

cmake/UserverSetupEnvironment.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function(_userver_setup_environment_impl)
4949
set(CMAKE_CXX_EXTENSIONS OFF PARENT_SCOPE)
5050
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON PARENT_SCOPE)
5151

52-
add_compile_options("-pipe" "-g" "-gz" "-fPIC")
52+
add_compile_options("-pipe" "-g" "-fPIC")
5353
add_compile_definitions("PIC=1")
5454

5555
option(USERVER_COMPILATION_TIME_TRACE "Generate Clang compilation time trace" OFF)
@@ -63,6 +63,8 @@ function(_userver_setup_environment_impl)
6363
include("${USERVER_CMAKE_DIR}/SetupLinker.cmake")
6464
include("${USERVER_CMAKE_DIR}/SetupLTO.cmake")
6565
include("${USERVER_CMAKE_DIR}/SetupPGO.cmake")
66+
include("${USERVER_CMAKE_DIR}/UserverCxxCompileOptionsIfSupported.cmake")
67+
include("${USERVER_CMAKE_DIR}/SetupDebugInfoCompression.cmake")
6668
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" PARENT_SCOPE)
6769
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" PARENT_SCOPE)
6870
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION "${CMAKE_INTERPROCEDURAL_OPTIMIZATION}" PARENT_SCOPE)

universal/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,10 @@ _userver_directory_install(COMPONENT universal FILES
396396
"${USERVER_ROOT_DIR}/cmake/SetupLTO.cmake"
397397
"${USERVER_ROOT_DIR}/cmake/SetupPGO.cmake"
398398
"${USERVER_ROOT_DIR}/cmake/SetupLinker.cmake"
399+
"${USERVER_ROOT_DIR}/cmake/SetupDebugInfoCompression.cmake"
399400
"${USERVER_ROOT_DIR}/cmake/SetupHomebrew.cmake"
400401
"${USERVER_ROOT_DIR}/cmake/Sanitizers.cmake"
402+
"${USERVER_ROOT_DIR}/cmake/UserverCxxCompileOptionsIfSupported.cmake"
401403
"${USERVER_ROOT_DIR}/cmake/AddGoogleTests.cmake"
402404
"${USERVER_ROOT_DIR}/cmake/DetectVersion.cmake"
403405
"${USERVER_ROOT_DIR}/cmake/UserverSetupEnvironment.cmake"

0 commit comments

Comments
 (0)