Skip to content

Commit

Permalink
cmake: Add Release and Debug option
Browse files Browse the repository at this point in the history
CLion is supported

Signed-off-by: sekaiacg <[email protected]>
  • Loading branch information
sekaiacg committed Jan 26, 2025
1 parent 545cbfa commit c11d5dd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ CMakeCache.txt
CMakeFiles
cmake_install.cmake
out/
*release*/
*debug*/
*.zip
erofs-utils-version.h
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
28 changes: 20 additions & 8 deletions build/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,49 @@ 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
"-fstack-protector-strong"
"-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")
Expand Down

0 comments on commit c11d5dd

Please sign in to comment.