diff --git a/.gitignore b/.gitignore index 52c7ccad..3e517858 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,7 @@ CMakeCache.txt CMakeFiles cmake_install.cmake out/ +*release*/ +*debug*/ +*.zip erofs-utils-version.h diff --git a/build.sh b/build.sh index 4de0c989..cc0c3ce6 100755 --- a/build.sh +++ b/build.sh @@ -28,6 +28,7 @@ cmake_build() -DANDROID_USE_LEGACY_TOOLCHAIN_FILE="OFF" elif [[ $TARGET == "Linux" ]]; then cmake -S ${BUILD_DIR} -B ${OUT} ${BUILD_METHOD} \ + -DCMAKE_BUILD_TYPE="Release" \ -DCMAKE_C_COMPILER_LAUNCHER="ccache" \ -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ -DCMAKE_C_COMPILER="clang" \ diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index f19493d8..3749c9fa 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -14,25 +14,27 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) add_definitions( "-D_FILE_OFFSET_BITS=64" "-D_LARGEFILE_SOURCE" - "-DNDEBUG" ) # Compile flags set(GLOBAL_CFLAGS - "-Os" - "-fdata-sections" - "-ffunction-sections" "-funwind-tables" "-fstack-protector-strong" - "-D_FORTIFY_SOURCE=2" "-Wformat" "-Werror=format-security" "-no-canonical-prefixes" - "-fvisibility=hidden" - "-fvisibility-inlines-hidden" + "-Wno-macro-redefined" "-fno-exceptions" "-fno-rtti" ) +set(GLOBAL_CFLAGS_RELEASE + "-Os" + "-D_FORTIFY_SOURCE=2" + "-fdata-sections" + "-ffunction-sections" + "-fvisibility=hidden" + "-fvisibility-inlines-hidden" +) # Linker flags set(GLOBAL_LDFLAGS @@ -40,11 +42,21 @@ set(GLOBAL_LDFLAGS "-Wl,--fatal-warnings" "-Qunused-arguments" "-Wl,--no-undefined" - "-Wl,--gc-sections" "-static" +) +set(GLOBAL_LDFLAGS_RELEASE + "-Wl,--gc-sections" "-s" ) +if (CMAKE_BUILD_TYPE STREQUAL "Release") + list(APPEND GLOBAL_CFLAGS ${GLOBAL_CFLAGS_RELEASE}) + list(APPEND GLOBAL_LDFLAGS ${GLOBAL_LDFLAGS_RELEASE}) + add_definitions("-DNDEBUG") +elseif (CMAKE_BUILD_TYPE STREQUAL "Debug") + list(APPEND GLOBAL_CFLAGS "-O0" "-g") +endif() + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") list(APPEND GLOBAL_CFLAGS "-fdiagnostics-color=always") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")