From f7b7c9321720065c5faceb0cd2d81e2c7d3b14ea Mon Sep 17 00:00:00 2001 From: wangyunlai <hnwyllmm@126.com> Date: Wed, 9 Aug 2023 09:26:43 +0800 Subject: [PATCH] Static gcc (#228) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem were solved in this pull request? Issue Number: close #222 Problem: gcc使用动æ€é“¾æŽ¥åº“,在å¤åˆ¶observer到其它机器åŽï¼Œæ— 法å¯åŠ¨ã€‚ ### What is changed and how it works? 使用gccé™æ€é“¾æŽ¥åº“ --- CMakeLists.txt | 23 +++++++++++++++-------- build.sh | 2 +- docs/src/how_to_build.md | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b310a51..c4b431e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,20 +36,20 @@ ENDIF(WIN32) # This is for clangd plugin for vscode SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -Wall -Werror") IF(DEBUG) - MESSAGE("DEBUG has been set as TRUE ${DEBUG}") + MESSAGE(STATUS "DEBUG has been set as TRUE ${DEBUG}") SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -O0 -g -DDEBUG ") ADD_DEFINITIONS(-DENABLE_DEBUG) ELSEIF(NOT DEFINED ENV{DEBUG}) - MESSAGE("Disable debug") + MESSAGE(STATUS "Disable debug") SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -O2 -g ") ELSE() - MESSAGE("Enable debug") + MESSAGE(STATUS "Enable debug") SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -O0 -g -DDEBUG") ADD_DEFINITIONS(-DENABLE_DEBUG) ENDIF(DEBUG) IF (CONCURRENCY) - MESSAGE("CONCURRENCY is ON") + MESSAGE(STATUS "CONCURRENCY is ON") SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -DCONCURRENCY") ADD_DEFINITIONS(-DCONCURRENCY) ENDIF (CONCURRENCY) @@ -57,22 +57,29 @@ ENDIF (CONCURRENCY) SET(CMAKE_COMMON_FLAGS "${CMAKE_COMMON_FLAGS} -fprofile-arcs -ftest-coverage") SET(CMAKE_CXX_FLAGS ${CMAKE_COMMON_FLAGS}) SET(CMAKE_C_FLAGS ${CMAKE_COMMON_FLAGS}) -MESSAGE("CMAKE_CXX_FLAGS is " ${CMAKE_CXX_FLAGS}) +MESSAGE(STATUS "CMAKE_CXX_FLAGS is " ${CMAKE_CXX_FLAGS}) + +MESSAGE(STATUS "CMAKE_CXX_COMPILER_ID is " ${CMAKE_CXX_COMPILER_ID}) +IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + ADD_LINK_OPTIONS(-static-libgcc -static-libstdc++) +ENDIF() IF (ENABLE_ASAN) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address") - SET(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") + IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + ADD_LINK_OPTIONS(-static-libasan) + ENDIF() ENDIF() IF (CMAKE_INSTALL_PREFIX) - MESSAGE("CMAKE_INSTALL_PREFIX has been set as " ${CMAKE_INSTALL_PREFIX} ) + MESSAGE(STATUS "CMAKE_INSTALL_PREFIX has been set as " ${CMAKE_INSTALL_PREFIX} ) ELSEIF(DEFINED ENV{CMAKE_INSTALL_PREFIX}) SET(CMAKE_INSTALL_PREFIX $ENV{CMAKE_INSTALL_PREFIX}) ELSE() SET(CMAKE_INSTALL_PREFIX /tmp/${PROJECT_NAME}) ENDIF() -MESSAGE("Install target dir is " ${CMAKE_INSTALL_PREFIX}) +MESSAGE(STATUS "Install target dir is " ${CMAKE_INSTALL_PREFIX}) IF (DEFINED ENV{LD_LIBRARY_PATH}) SET(LD_LIBRARY_PATH_STR $ENV{LD_LIBRARY_PATH}) diff --git a/build.sh b/build.sh index 463458a..b45356b 100755 --- a/build.sh +++ b/build.sh @@ -5,7 +5,7 @@ TOPDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) BUILD_SH=$TOPDIR/build.sh -CMAKE_COMMAND="cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 --log-level=WARNING" +CMAKE_COMMAND="cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 --log-level=STATUS" ALL_ARGS=("$@") BUILD_ARGS=() diff --git a/docs/src/how_to_build.md b/docs/src/how_to_build.md index ab64a8c..177f718 100644 --- a/docs/src/how_to_build.md +++ b/docs/src/how_to_build.md @@ -5,7 +5,7 @@ å‡è®¾ç³»ç»Ÿä¸Šå·²ç»å®‰è£…了makeç‰ç¼–译工具。 MiniOB 需è¦ä½¿ç”¨ï¼š -- cmake 版本 >= 3.10 +- cmake 版本 >= 3.13 - gcc/clang gcc建议8.3以上,编译器需è¦æ”¯æŒc++20æ–°æ ‡å‡† 1. 环境åˆå§‹åŒ– -- GitLab