From 2fedf8b4a561118f745a5d25bc9065b3795e298c Mon Sep 17 00:00:00 2001 From: wangyunlai Date: Thu, 24 Aug 2023 13:44:49 +0800 Subject: [PATCH] add static_stdlib option as there is no static gcc library on rockylinux (#248) ### What problem were solved in this pull request? Issue Number: close #247 Problem: Compile miniob with static gcc and g++ failed while there is no static gcc library on rockylinux. ### What is changed and how it works? Add cmake option static_stdlib with default value off. In normal case, we compile miniob and run/debug it on the same machine, so dynamic linking works fun. If we want to move observer binary to other machine and test, we can recompile miniob with static_stdlib ON. --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6120f4e..e8f02b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) OPTION(ENABLE_ASAN "Enable build with address sanitizer" ON) OPTION(WITH_UNIT_TESTS "Compile miniob with unit tests" ON) OPTION(CONCURRENCY "Support concurrency operations" OFF) +OPTION(STATIC_STDLIB "Link std library static or dynamic, such as libgcc, libstdc++, libasan" OFF) MESSAGE(STATUS "HOME dir: $ENV{HOME}") #SET(ENV{变量名} 值) @@ -55,13 +56,13 @@ IF (CONCURRENCY) ENDIF (CONCURRENCY) MESSAGE(STATUS "CMAKE_CXX_COMPILER_ID is " ${CMAKE_CXX_COMPILER_ID}) -IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") +IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND ${STATIC_STDLIB}) ADD_LINK_OPTIONS(-static-libgcc -static-libstdc++) ENDIF() IF (ENABLE_ASAN) SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -fno-omit-frame-pointer -fsanitize=address") - IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND ${STATIC_STDLIB}) ADD_LINK_OPTIONS(-static-libasan) ENDIF() ENDIF() -- GitLab