diff --git a/CMakeLists.txt b/CMakeLists.txt index 6120f4e914090e2892cb60dde3eb1a49f5b853dc..e8f02b5f079b68ad9399c0dab6d853f0e4113e2e 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()