From 1a8edf682ba4f8407de85b32d40856f71b0444ff Mon Sep 17 00:00:00 2001 From: baocm Date: Fri, 16 Jan 2026 11:15:33 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 17 +++++++++++------ common/DEBUG.hpp | 6 +++--- core/main.cxx | 4 +--- demo/main.cxx | 2 +- gatectrl/main.cxx | 4 +--- httpserver/main.cxx | 4 +--- ioctrl/main.cxx | 4 +--- mqttdds/main.cxx | 4 +--- print/main.cxx | 4 +--- weigh/main.cxx | 4 +--- 10 files changed, 22 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e37f32c..2b5afba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ project("system") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_EXTENSIONS OFF) +set(PROGRAM_VERSION "v1.0.0") set(fastcdr_DIR "/opt/fastdds/v3.2.2/lib/cmake/fastcdr") set(fastdds_DIR "/opt/fastdds/v3.2.2/share/fastdds/cmake") @@ -33,11 +34,13 @@ add_library(System_lib lib/SystemTypeObjectSupport.cxx lib/SystemPubSubTypes.cxx target_link_libraries(System_lib fastcdr fastdds) # Demo Application. +# set(PROGRAM_MODULE "Demo") # add_executable(Demo # demo/main.cxx # demo/Publisher.cxx # demo/Subscriber.cxx # ) +# target_compile_definitions(Demo PRIVATE PROGRAM_MODULE="${PROGRAM_MODULE}" PROGRAM_VERSION="${PROGRAM_VERSION}") # target_include_directories(Demo PRIVATE demo) # target_link_libraries(Demo fastcdr fastdds # System_lib @@ -50,7 +53,7 @@ add_executable(Core core/Publisher.cxx core/Subscriber.cxx ) -target_compile_definitions(Core PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") +target_compile_definitions(Core PRIVATE PROGRAM_MODULE="${PROGRAM_MODULE}" PROGRAM_VERSION="${PROGRAM_VERSION}") target_include_directories(Core PRIVATE core) target_link_libraries(Core fastcdr fastdds System_lib @@ -65,13 +68,14 @@ add_executable(GateCtrl gatectrl/MsgHandler.cxx common/CanMsgHandler.cxx ) -target_compile_definitions(GateCtrl PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") +target_compile_definitions(GateCtrl PRIVATE PROGRAM_MODULE="${PROGRAM_MODULE}" PROGRAM_VERSION="${PROGRAM_VERSION}") target_include_directories(GateCtrl PRIVATE gatectrl) target_link_libraries(GateCtrl fastcdr fastdds System_lib ) # IoCtrl Application. +# set(PROGRAM_MODULE "IoCtrl") # add_executable(IoCtrl # ioctrl/main.cxx # ioctrl/Publisher.cxx @@ -79,6 +83,7 @@ target_link_libraries(GateCtrl fastcdr fastdds # ioctrl/MsgHandler.cxx # common/CanMsgHandler.cxx # ) +# target_compile_definitions(IoCtrl PRIVATE PROGRAM_MODULE="${PROGRAM_MODULE}" PROGRAM_VERSION="${PROGRAM_VERSION}") # target_include_directories(IoCtrl PRIVATE ioctrl) # target_link_libraries(IoCtrl fastcdr fastdds # System_lib @@ -92,7 +97,7 @@ add_executable(HttpServer httpserver/Subscriber.cxx httpserver/httpserver.cxx ) -target_compile_definitions(HttpServer PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") +target_compile_definitions(HttpServer PRIVATE PROGRAM_MODULE="${PROGRAM_MODULE}" PROGRAM_VERSION="${PROGRAM_VERSION}") target_include_directories(HttpServer PRIVATE httpserver) target_link_libraries(HttpServer fastcdr fastdds System_lib @@ -108,7 +113,7 @@ add_executable(Print common/SerialMsgHandler.cxx lib/strcode.cpp ) -target_compile_definitions(Print PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") +target_compile_definitions(Print PRIVATE PROGRAM_MODULE="${PROGRAM_MODULE}" PROGRAM_VERSION="${PROGRAM_VERSION}") target_include_directories(Print PRIVATE print) target_link_libraries(Print fastcdr fastdds System_lib @@ -124,7 +129,7 @@ add_executable(Weigh weigh/WeightStabilityDetector.cxx common/SerialMsgHandler.cxx ) -target_compile_definitions(Weigh PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") +target_compile_definitions(Weigh PRIVATE PROGRAM_MODULE="${PROGRAM_MODULE}" PROGRAM_VERSION="${PROGRAM_VERSION}") target_include_directories(Weigh PRIVATE weigh) target_link_libraries(Weigh fastcdr fastdds System_lib @@ -137,7 +142,7 @@ add_executable(MqttDds mqttdds/Publisher.cxx mqttdds/Subscriber.cxx ) -target_compile_definitions(MqttDds PRIVATE PROGRAM_MODULE_NAME="${PROGRAM_MODULE}") +target_compile_definitions(MqttDds PRIVATE PROGRAM_MODULE="${PROGRAM_MODULE}" PROGRAM_VERSION="${PROGRAM_VERSION}") target_include_directories(MqttDds PRIVATE mqttdds) target_link_libraries(MqttDds fastcdr fastdds System_lib PahoMqttCpp::paho-mqttpp3 diff --git a/common/DEBUG.hpp b/common/DEBUG.hpp index 2129ebe..27f51f3 100644 --- a/common/DEBUG.hpp +++ b/common/DEBUG.hpp @@ -3,9 +3,9 @@ #include // 使用CMake定义的模块名 -#ifndef PROGRAM_MODULE_NAME - #define PROGRAM_MODULE_NAME "DefaultApp" +#ifndef PROGRAM_MODULE + #define PROGRAM_MODULE "DefaultApp" #endif // 使用CMake设置的模块名 -#define DEBUG(...) std::cout << "[" << PROGRAM_MODULE_NAME << "] " << __VA_ARGS__ << std::endl +#define DEBUG(...) std::cout << "[" << PROGRAM_MODULE << "] " << __VA_ARGS__ << std::endl diff --git a/core/main.cxx b/core/main.cxx index 8fdbf2a..dd5fc46 100644 --- a/core/main.cxx +++ b/core/main.cxx @@ -34,8 +34,6 @@ #include "msg.hpp" #include "DEBUG.hpp" -#define VERSION "v1.0" - using eprosima::fastdds::dds::Log; std::function stop_handler; @@ -91,7 +89,7 @@ int main(int argc, char** argv) } else if (strcmp(argv[i], "--version") == 0) { - std::cout << "Vesrion: " << VERSION << "\n"; + std::cout << "Vesrion: " << PROGRAM_VERSION << "\n"; return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) diff --git a/demo/main.cxx b/demo/main.cxx index 2c780ee..b19a143 100644 --- a/demo/main.cxx +++ b/demo/main.cxx @@ -98,7 +98,7 @@ int main(int argc, char** argv) } else if (strcmp(argv[i], "--version") == 0) { - std::cout << "Vesrion: " << VERSION << "\n"; + std::cout << "Vesrion: " << PROGRAM_VERSION << "\n"; return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) diff --git a/gatectrl/main.cxx b/gatectrl/main.cxx index ddfcd49..d1f1e93 100644 --- a/gatectrl/main.cxx +++ b/gatectrl/main.cxx @@ -34,8 +34,6 @@ #include "msg.hpp" #include "DEBUG.hpp" -#define VERSION "v1.0" - using eprosima::fastdds::dds::Log; std::function stop_handler; @@ -111,7 +109,7 @@ int main(int argc, char** argv) } else if (strcmp(argv[i], "--version") == 0) { - std::cout << "Vesrion: " << VERSION << "\n"; + std::cout << "Vesrion: " << PROGRAM_VERSION << "\n"; return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) diff --git a/httpserver/main.cxx b/httpserver/main.cxx index 61d7a79..c488666 100644 --- a/httpserver/main.cxx +++ b/httpserver/main.cxx @@ -34,8 +34,6 @@ #include "httpserver.hpp" #include "DEBUG.hpp" -#define VERSION "v1.0.0" - using eprosima::fastdds::dds::Log; std::function stop_handler; @@ -87,7 +85,7 @@ int main(int argc, char** argv) } else if (strcmp(argv[i], "--version") == 0) { - std::cout << "Vesrion: " << VERSION << "\n"; + std::cout << "Vesrion: " << PROGRAM_VERSION << "\n"; return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) diff --git a/ioctrl/main.cxx b/ioctrl/main.cxx index d272ecb..50d6db5 100644 --- a/ioctrl/main.cxx +++ b/ioctrl/main.cxx @@ -37,8 +37,6 @@ #include "msg.hpp" #include "json.hpp" -#define VERSION "v1.0" - using eprosima::fastdds::dds::Log; using json = nlohmann::json; @@ -129,7 +127,7 @@ int main(int argc, char** argv) } else if (strcmp(argv[i], "--version") == 0) { - std::cout << "Vesrion: " << VERSION << "\n"; + std::cout << "Vesrion: " << PROGRAM_VERSION << "\n"; return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) diff --git a/mqttdds/main.cxx b/mqttdds/main.cxx index 0ded6f4..5a8d115 100644 --- a/mqttdds/main.cxx +++ b/mqttdds/main.cxx @@ -35,8 +35,6 @@ #include "msg.hpp" #include "DEBUG.hpp" -#define VERSION "v1.0" - using eprosima::fastdds::dds::Log; std::function stop_handler; @@ -167,7 +165,7 @@ int main(int argc, char** argv) } else if (strcmp(argv[i], "--version") == 0) { - std::cout << "Vesrion: " << VERSION << "\n"; + std::cout << "Vesrion: " << PROGRAM_VERSION << "\n"; return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) diff --git a/print/main.cxx b/print/main.cxx index 39c6ee1..e96bfec 100644 --- a/print/main.cxx +++ b/print/main.cxx @@ -34,8 +34,6 @@ #include "msg.hpp" #include "DEBUG.hpp" -#define VERSION "v1.0" - using eprosima::fastdds::dds::Log; std::function stop_handler; @@ -105,7 +103,7 @@ int main(int argc, char** argv) } else if (strcmp(argv[i], "--version") == 0) { - std::cout << "Vesrion: " << VERSION << "\n"; + std::cout << "Vesrion: " << PROGRAM_VERSION << "\n"; return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0) diff --git a/weigh/main.cxx b/weigh/main.cxx index 8d52f66..0e30b0c 100644 --- a/weigh/main.cxx +++ b/weigh/main.cxx @@ -34,8 +34,6 @@ #include "msg.hpp" #include "DEBUG.hpp" -#define VERSION "v1.0" - using eprosima::fastdds::dds::Log; std::function stop_handler; @@ -110,7 +108,7 @@ int main(int argc, char** argv) } else if (strcmp(argv[i], "--version") == 0) { - std::cout << "Vesrion: " << VERSION << "\n"; + std::cout << "Vesrion: " << PROGRAM_VERSION << "\n"; return EXIT_SUCCESS; } else if (strcmp(argv[i], "--help") == 0)