diff --git a/build.sh b/build.sh index 46c69312..3983d662 100755 --- a/build.sh +++ b/build.sh @@ -25,7 +25,8 @@ cmake_build() -DANDROID_ABI="$ABI" \ -DANDROID_STL="c++_static" \ -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ - -DANDROID_USE_LEGACY_TOOLCHAIN_FILE="OFF" + -DANDROID_USE_LEGACY_TOOLCHAIN_FILE="OFF" \ + -DMAX_BLOCK_SIZE="4096" elif [[ $TARGET == "Linux" ]]; then local LINUX_PLATFORM=$4 local WSL="OFF" @@ -37,7 +38,8 @@ cmake_build() -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ -DCMAKE_C_COMPILER="clang" \ -DCMAKE_CXX_COMPILER="clang++" \ - -DENABLE_FULL_LTO="ON" + -DENABLE_FULL_LTO="ON" \ + -DMAX_BLOCK_SIZE="4096" fi ${MAKE_CMD} diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index 03970aa4..15380e3c 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -17,6 +17,23 @@ add_definitions( "-D_LARGEFILE64_SOURCE" ) +if (NOT MAX_BLOCK_SIZE) + try_run(CHECK_MAX_BLOCK_SIZE_RESULT + CHECK_MAX_BLOCK_SIZE_COMPILE_RESULT + ${CMAKE_CURRENT_BINARY_DIR}/sources + ${CMAKE_CURRENT_SOURCE_DIR}/sources/checkMaxBlockSize.c + NO_CACHE + RUN_OUTPUT_VARIABLE erofs_cv_max_block_size + ) + if (erofs_cv_max_block_size GREATER 0) + add_definitions(-DEROFS_MAX_BLOCK_SIZE=${erofs_cv_max_block_size}) + else () + add_definitions(-DEROFS_MAX_BLOCK_SIZE=4096) + endif () +else () + add_definitions(-DEROFS_MAX_BLOCK_SIZE=${MAX_BLOCK_SIZE}) +endif () + # Compile flags set(GLOBAL_CFLAGS "-Wformat" diff --git a/build/cmake/sources/checkMaxBlockSize.c b/build/cmake/sources/checkMaxBlockSize.c new file mode 100644 index 00000000..cefd86e8 --- /dev/null +++ b/build/cmake/sources/checkMaxBlockSize.c @@ -0,0 +1,10 @@ +#include +#include + +int main(int argc, char **argv) { + int result = sysconf(_SC_PAGESIZE); + if (result < 0) + return 1; + printf("%d", result); + return 0; +} diff --git a/build_darwin.sh b/build_darwin.sh index af2b0752..9cab5ece 100755 --- a/build_darwin.sh +++ b/build_darwin.sh @@ -26,7 +26,8 @@ cmake_build() -DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \ -DCMAKE_C_COMPILER="clang" \ -DCMAKE_CXX_COMPILER="clang++" \ - -DENABLE_FULL_LTO="ON" + -DENABLE_FULL_LTO="ON" \ + -DMAX_BLOCK_SIZE="4096" fi ${MAKE_CMD}