Skip to content

Commit a9fdb05

Browse files
committed
noe cmake pack shared lib into ./lib
1 parent 6622ad9 commit a9fdb05

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ log/
1212
test*
1313
compile_commands.json
1414
dev_tools/inspector
15-
backup/
15+
backup/
16+
shinxbot

CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ endif()
5454
add_library(utils SHARED ${UTIL_SOURCES} ${UTIL_META_SOURCES} ${INT_SOURCES})
5555
add_executable(${PROJECT_NAME} ${BOT_SOURCES} ${META_SOURCES} ${MAIN_SOURCES} ${FUNC_SOURCES} ${EVEN_SOURCES})
5656

57+
set_target_properties(${PROJECT_NAME} PROPERTIES
58+
INSTALL_RPATH "\$ORIGIN/lib"
59+
BUILD_WITH_INSTALL_RPATH TRUE
60+
)
61+
5762
target_link_libraries(${PROJECT_NAME} PRIVATE utils)
5863
target_link_libraries(${PROJECT_NAME} PUBLIC ${ImageMagick_LIBRARIES})
5964

@@ -66,3 +71,23 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC -pthread)
6671
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC -lm)
6772
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC -ldl)
6873
target_link_libraries(${PROJECT_NAME} PUBLIC ${OPENSSL_LIBRARIES})
74+
75+
include(CMakeParseArguments)
76+
77+
function(copy_original_files)
78+
cmake_parse_arguments(ARG "" "DESTINATION" "FILES" ${ARGN})
79+
80+
foreach(file ${ARG_FILES})
81+
get_filename_component(original_file "${file}" REALPATH)
82+
file(COPY "${original_file}" DESTINATION "${ARG_DESTINATION}")
83+
endforeach()
84+
endfunction()
85+
86+
copy_original_files(
87+
DESTINATION "${CMAKE_BINARY_DIR}/../lib"
88+
FILES ${ImageMagick_LIBRARIES} ${JSONCPP_LIBRARIES} ${OPENSSL_LIBRARIES}
89+
)
90+
91+
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_BINARY_DIR}/../)
92+
install(FILES DESTINATION ${CMAKE_BINARY_DIR}/../lib)
93+
# install(FILES ${ImageMagick_LIBRARIES} ${JSONCPP_LIBRARIES} zip curl jsoncpp thread m dl ${OPENSSL_LIBRARIES} DESTINATION ./lib)

README.MD

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@
5555

5656
### 运行Bot
5757

58+
以下提供3种运行的方法:
59+
5860
1. 从Release中下载并解压,运行`shinxbot`
5961

60-
2. 克隆仓库,于根目录下执行`docker compose up -d`进行容器内自动配置并编译为可执行文件`./build/shinxbot`
62+
2. 克隆仓库,于根目录下执行`docker compose up -d`进行容器内自动配置并编译为可执行文件`./shinxbot`
6163

6264
使用`docker exec -it shinx-bot bash`以进入容器终端,在容器内运行
6365

64-
3. 裸机编译后运行`./build/shinxbot`,详见下一节
66+
3. 裸机编译后运行`./shinxbot`,详见下一节
6567

6668
运行前,请确保Onebot 11标准后端正在运行,运行`shinxbot`后port行请分别输入Onebot 11后端的上报端口及其API端口
6769

build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ done
1111

1212
cd ./build
1313
cmake -DCMAKE_BUILD_TYPE=Release .. -DMODE="$1"
14-
make -j$(( $(nproc) - 1 ))
14+
make -j$(( $(nproc) - 1 ))
15+
cmake --install .

lib/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/**/*.so
1+
/**/*.so*

src/interfaces/dynamic_lib.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ std::pair<T *, void *> load_function(const std::string &dlname,
1111
typedef T *(*create_t)();
1212
void *handle = dlopen(dlname.c_str(), RTLD_LAZY);
1313
if (!handle) {
14-
set_global_log(LOG::ERROR, "Cannot open library: " + dlerror());
14+
set_global_log(LOG::ERROR, std::string("Cannot open library: ") + dlerror());
1515
return std::make_pair(nullptr, nullptr);
1616
}
1717

@@ -20,7 +20,7 @@ std::pair<T *, void *> load_function(const std::string &dlname,
2020
const char *dlsym_error = dlerror();
2121
if (dlsym_error) {
2222
set_global_log(LOG::ERROR,
23-
"Cannot load symbol 'create': " + dlsym_error);
23+
std::string("Cannot load symbol 'create': ") + dlsym_error);
2424
dlclose(handle);
2525
return std::make_pair(nullptr, nullptr);
2626
}

0 commit comments

Comments
 (0)