From f5cb361ffefbfc89666eb804ec6ec4997cf1376a Mon Sep 17 00:00:00 2001
From: 7iwind <7wind@7iwind.cn>
Date: Sun, 26 Jul 2026 14:44:35 +0800
Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=89=93=E5=8C=85?=
=?UTF-8?q?=E5=90=8E=E7=9A=84=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=EF=BC=8C?=
=?UTF-8?q?=E4=BE=BF=E4=BA=8E=E5=BC=95=E5=85=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitea/workflows/release.yml | 8 +-----
.idea/ctestState.xml | 9 +++++++
CMakeLists.txt | 47 +++++++++++++++++++++++++++++++++
cmake/DataRouterConfig.cmake.in | 16 +++++++++++
4 files changed, 73 insertions(+), 7 deletions(-)
create mode 100644 .idea/ctestState.xml
create mode 100644 cmake/DataRouterConfig.cmake.in
diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml
index 0bb20a6..b405730 100644
--- a/.gitea/workflows/release.yml
+++ b/.gitea/workflows/release.yml
@@ -48,13 +48,7 @@ jobs:
[ "$testing" = "ON" ] && ctest --test-dir "build-$name" --output-on-failure
pkg="datarouter-$name"
- mkdir -p "dist/$pkg"
- for f in datarouter.h datarouter_config_template.h LICENSE README.md; do
- if [ -f "$f" ]; then cp "$f" "dist/$pkg/"; fi
- done
- for f in libDataRouter.a libDataRouter.so libDataRouter.dll libDataRouter.dll.a example example.exe; do
- if [ -f "build-$name/$f" ]; then cp "build-$name/$f" "dist/$pkg/"; fi
- done
+ cmake --install "build-$name" --prefix "dist/$pkg"
done
- name: Create release & upload assets
diff --git a/.idea/ctestState.xml b/.idea/ctestState.xml
new file mode 100644
index 0000000..61d31e4
--- /dev/null
+++ b/.idea/ctestState.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 81ee1eb..020b1d6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,3 +28,50 @@ if(BUILD_TESTING OR NOT DEFINED BUILD_TESTING)
target_link_libraries(test_datarouter DataRouter)
add_test(NAME datarouter COMMAND test_datarouter)
endif()
+
+# ======== 安装规则 ========
+
+# 静态库 → lib/
+install(TARGETS DataRouter
+ EXPORT DataRouterTargets
+ ARCHIVE DESTINATION lib
+)
+
+# 共享库 → lib/(可选)
+if(TARGET DataRouter_shared)
+ install(TARGETS DataRouter_shared
+ EXPORT DataRouterTargets
+ ARCHIVE DESTINATION lib # .lib (Windows import lib)
+ LIBRARY DESTINATION lib # .so
+ RUNTIME DESTINATION lib # .dll
+ )
+endif()
+
+# 示例 → bin/
+if(TARGET example)
+ install(TARGETS example RUNTIME DESTINATION bin)
+endif()
+
+# 头文件 → include/
+install(FILES datarouter.h DESTINATION include)
+
+# 文档 → share/
+install(FILES datarouter_config_template.h LICENSE DESTINATION share)
+if(EXISTS ${CMAKE_SOURCE_DIR}/README.md)
+ install(FILES README.md DESTINATION share)
+endif()
+
+# CMake 包配置文件 → cmake/
+set(INCLUDE_INSTALL_DIR include)
+set(LIB_INSTALL_DIR lib)
+
+include(CMakePackageConfigHelpers)
+configure_package_config_file(
+ cmake/DataRouterConfig.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/DataRouterConfig.cmake
+ INSTALL_DESTINATION cmake
+ PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR
+)
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DataRouterConfig.cmake DESTINATION cmake)
+install(EXPORT DataRouterTargets FILE DataRouterTargets.cmake DESTINATION cmake)
diff --git a/cmake/DataRouterConfig.cmake.in b/cmake/DataRouterConfig.cmake.in
new file mode 100644
index 0000000..ead61c9
--- /dev/null
+++ b/cmake/DataRouterConfig.cmake.in
@@ -0,0 +1,16 @@
+@PACKAGE_INIT@
+
+set_and_check(DataRouter_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
+set_and_check(DataRouter_LIBRARY_DIR "@PACKAGE_LIB_INSTALL_DIR@")
+
+include("${CMAKE_CURRENT_LIST_DIR}/DataRouterTargets.cmake" OPTIONAL)
+
+if(NOT TARGET DataRouter::DataRouter)
+ add_library(DataRouter::DataRouter STATIC IMPORTED)
+ set_target_properties(DataRouter::DataRouter PROPERTIES
+ IMPORTED_LOCATION "${DataRouter_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}DataRouter${CMAKE_STATIC_LIBRARY_SUFFIX}"
+ INTERFACE_INCLUDE_DIRECTORIES "${DataRouter_INCLUDE_DIR}"
+ )
+endif()
+
+check_required_components(DataRouter)
--
2.54.0
From 89c4e770d51de7f807b487f09952b228f29bbc40 Mon Sep 17 00:00:00 2001
From: 7iwind <7wind@7iwind.cn>
Date: Sun, 26 Jul 2026 14:53:34 +0800
Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=89=93=E5=8C=85?=
=?UTF-8?q?=E5=90=8E=E7=9A=84=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=EF=BC=8C?=
=?UTF-8?q?=E4=BE=BF=E4=BA=8E=E5=BC=95=E5=85=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CMakeLists.txt | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 020b1d6..e032277 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,13 +5,19 @@ set(CMAKE_C_STANDARD 11)
# ======== 静态库 ========
add_library(DataRouter STATIC datarouter.c)
-target_include_directories(DataRouter PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+target_include_directories(DataRouter PUBLIC
+ $
+ $
+)
# ======== 共享库(可选,通过 BUILD_SHARED 控制) ========
option(BUILD_SHARED "Build shared library" ON)
if(BUILD_SHARED)
add_library(DataRouter_shared SHARED datarouter.c)
- target_include_directories(DataRouter_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+ target_include_directories(DataRouter_shared PUBLIC
+ $
+ $
+ )
set_target_properties(DataRouter_shared PROPERTIES OUTPUT_NAME DataRouter)
endif()
--
2.54.0