From 2b13440e2dc529e673948543ae55d04bdb5254b6 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 10 Sep 2025 00:19:55 -0300 Subject: [PATCH 1/3] Update CMakeLists.txt --- CMakeLists.txt | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e28ae07..f033083 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,23 @@ option( SS_CPPTRACE_STACKTRACE our implementation" ON ) +option(SS_STATIC_LIBSTDCPP "Statically link libstdc++" ON) +option(SS_STRIP_SYMBOLS "Strip unused symbols from binary" ON) + +set(OPTIMIZATION_FLAGS + "-O3" # Aggressive optimization + "-ffunction-sections" # Place each function in its own section + "-fdata-sections" # Place each data item in its own section + "-fvisibility=hidden" # Hide symbols by default + "-fvisibility-inlines-hidden" # Hide inline function symbols +) +set(LINKER_FLAGS + "-Wl,--gc-sections" + "-Wl,--as-needed" +) +if(SS_STATIC_LIBSTDCPP) + list(APPEND LINKER_FLAGS "-static-libstdc++") +endif() set(LIBRARY_SOURCES src/accept_operation.cc @@ -130,12 +147,14 @@ set(CLI_SOURCES add_library(${LIBRARY_NAME} OBJECT ${LIBRARY_SOURCES}) target_include_directories(${LIBRARY_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include) # TODO: check if coroutines support has been added to target_compile_features() -target_compile_options(${LIBRARY_NAME} PUBLIC "-fcoroutines") +target_compile_options(${LIBRARY_NAME} PUBLIC "-fcoroutines" ${OPTIMIZATION_FLAGS}) +target_link_options(${LIBRARY_NAME} PUBLIC ${LINKER_FLAGS}) add_executable(${EXECUTABLE_NAME} ${CLI_SOURCES}) target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${LIBRARY_NAME}) # TODO: check if coroutines support has been added to target_compile_features() -target_compile_options(${EXECUTABLE_NAME} PRIVATE "-fcoroutines") +target_compile_options(${EXECUTABLE_NAME} PRIVATE "-fcoroutines" ${OPTIMIZATION_FLAGS}) +target_link_options(${EXECUTABLE_NAME} PRIVATE ${LINKER_FLAGS}) set_target_properties( ${LIBRARY_NAME} ${EXECUTABLE_NAME} @@ -145,6 +164,13 @@ set_target_properties( #CXX_EXTENSIONS YES ) +if(SS_STRIP_SYMBOLS) + add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD + COMMAND ${CMAKE_STRIP} --strip-unneeded $ + COMMENT "Stripping unused symbols from ${EXECUTABLE_NAME}" + ) +endif() + install(TARGETS ${LIBRARY_NAME} ${EXECUTABLE_NAME} ) # Optional IPO/LTO. Do not enable them if it's not supported by compiler. From e9eda5ed604572cdcad98f1f51645ca55c127f48 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 10 Sep 2025 00:28:35 -0300 Subject: [PATCH 2/3] force release type --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f033083..6c4c6ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,10 @@ set(FETCHCONTENT_QUIET OFF) # the source. See exampleConfig.h.in for some more details. project(shared-state VERSION 0.0.0.1 LANGUAGES CXX) +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + option( SS_STAT_FILE_LOCKING "Enable shared-state network statistics file locking" OFF ) From a3e4603caacdfe9cc0f6a429859e28b233255402 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 10 Sep 2025 00:51:17 -0300 Subject: [PATCH 3/3] add CMAKE_STRIP suport --- CMakeLists.txt | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c4c6ea..47a1d01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ set(FETCHCONTENT_QUIET OFF) # the source. See exampleConfig.h.in for some more details. project(shared-state VERSION 0.0.0.1 LANGUAGES CXX) + if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() @@ -169,10 +170,25 @@ set_target_properties( ) if(SS_STRIP_SYMBOLS) - add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD - COMMAND ${CMAKE_STRIP} --strip-unneeded $ - COMMENT "Stripping unused symbols from ${EXECUTABLE_NAME}" - ) + if(NOT CMAKE_STRIP) + # Tomamos el path del compilador C (gcc o clang usado por OpenWrt) + get_filename_component(TOOLCHAIN_BIN_DIR "${CMAKE_C_COMPILER}" DIRECTORY) + get_filename_component(TOOLCHAIN_PREFIX "${CMAKE_C_COMPILER}" NAME_WE) # nombre sin extensión + + # Reemplazamos el "gcc" por "strip" para deducir la ruta correcta + string(REPLACE "gcc" "strip" TOOLCHAIN_STRIP "${TOOLCHAIN_BIN_DIR}/${TOOLCHAIN_PREFIX}") + + if(EXISTS "${TOOLCHAIN_STRIP}") + set(CMAKE_STRIP "${TOOLCHAIN_STRIP}" CACHE FILEPATH "Path to toolchain strip" FORCE) + message(STATUS "Using toolchain strip: ${CMAKE_STRIP}") + add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD + COMMAND ${CMAKE_STRIP} --strip-unneeded $ + COMMENT "Stripping unused symbols from ${EXECUTABLE_NAME}") + else() + message(WARNING "No toolchain strip found at ${TOOLCHAIN_STRIP}, will skip stripping") + endif() + endif() + endif() install(TARGETS ${LIBRARY_NAME} ${EXECUTABLE_NAME} )