-
Notifications
You must be signed in to change notification settings - Fork 6
use cmake for compile #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
CMakeLists.txt
Outdated
| cmake_minimum_required(VERSION 3.16) | ||
| project(FastFS VERSION 1.0 LANGUAGES CXX C) | ||
|
|
||
| # 设置 C++ 标准 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
中文注释都去掉吧,部分IDE对中文编码支持不太友好
CMakeLists.txt
Outdated
| set(SCRIPTS_DIR ${CMAKE_SOURCE_DIR}/scripts) | ||
|
|
||
| # SPDK 作为 submodule 的路径 (现在在 third_party/spdk) | ||
| set(SPDK_SUBMODULE_DIR ${CMAKE_SOURCE_DIR}/third_party/spdk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
变量可以改成SPDK_ROOT_DIR,如果编译阶段用户手动声明了变量值,采用路径对应的spdk版本,否则从git仓库下载编译
|
|
||
| # 编译选项 | ||
| option(ENABLE_FIO_PLUGIN "Enable FIO plugin support" ON) | ||
| set(FIO_VERSION "fio-3.39" CACHE STRING "FIO version to download") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
声明FIO_ROOT_DIR变量,如果编译阶段用户手动声明了变量值,采用路径对应的FIO版本,否则通过FetchContent下载
CMakeLists.txt
Outdated
| set(DEPS_DIR ${CMAKE_SOURCE_DIR}/deps) | ||
|
|
||
| # 编译选项 | ||
| option(ENABLE_FIO_PLUGIN "Enable FIO plugin support" ON) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ENABLE_FIO
CMakeLists.txt
Outdated
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -O2") | ||
|
|
||
| # 检查 SPDK submodule 是否存在 | ||
| if(NOT EXISTS ${SPDK_SUBMODULE_DIR}/mk/spdk.common.mk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SPDK的编译需要绑定一个具体的Release版本,master分支不稳定,可以向FIO那样通过FetchContent获取
if(NOT SPDK_ROOT_DIR)
message(STATUS "Fetching SPDK...")
include(FetchContent)
FetchContent_Declare(
spdk
GIT_REPOSITORY https://github.com/spdk/spdk.git
GIT_TAG ${SPDK_VERSION}
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
SOURCE_DIR ${DEPS_DIR}/spdk-${SPDK_VERSION}
)
FetchContent_MakeAvailable(spdk)
set(SPDK_ROOT_DIR ${DEPS_DIR}/spdk-${SPDK_VERSION})
set(SPDK_BUILD_COMMAND ${CMAKE_SOURCE_DIR}/scripts/build_spdk.sh ${SPDK_ROOT_DIR} ${CMAKE_SOURCE_DIR}/spdk.patch)
add_custom_target(build_spdk
COMMAND ${SPDK_BUILD_COMMAND}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Building SPDK"
)
endif()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git submodule是锁定了一个发行版本的commit,如果代码不修改的情况下,是锁定这个版本了。
| @@ -1,5 +1,5 @@ | |||
| diff --git a/include/spdk/bit_pool.h b/include/spdk/bit_pool.h | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个补丁文件应该不用调整
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
调整一下操作系统相关的东西,我们那个编译镜像是阿里os的,不识别,我改了下可以识别
scripts/build_spdk.sh
Outdated
|
|
||
| # 编译 SPDK | ||
| echo "编译 SPDK..." | ||
| make -j16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
并发度改成2
scripts/build_spdk.sh
Outdated
| git submodule update --init | ||
| ./scripts/pkgdep.sh | ||
| echo "配置 SPDK..." | ||
| ./configure --disable-tests --disable-unit-tests --disable-apps --disable-examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
添加--with-shared选项
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当前是静态链接的,默认也不编译动态库,是不是先就检查静态库就行了
| # 配置 SPDK | ||
| cd "$SPDK_DIR" | ||
| git submodule update --init | ||
| ./scripts/pkgdep.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个注释掉吧,部分云主机检测会失败
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不这样没法执行编译,spdk官方编译也是执行这个脚本呀,https://github.com/spdk/spdk
scripts/build_spdk.sh
Outdated
| cd "$SPDK_DIR" | ||
|
|
||
| # 检查补丁是否已经应用 | ||
| if git apply --check "../../$PATCH_FILE" 2>/dev/null; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PATCH_FILE是绝对路径?
git apply --check $PATCH_FILE
sh compile.sh执行就行