Skip to content

Commit c5d1716

Browse files
committed
chore: use a separated text to record version
1 parent 07f74a0 commit c5d1716

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ if (NOT CMAKE_CXX_STANDARD)
2424
set(CMAKE_CXX_STANDARD 17)
2525
endif ()
2626

27+
file(READ version.txt VERSION_STR)
28+
string(STRIP ${VERSION_STR} VERSION_STR)
29+
2730
find_path(SIMPLEINI_INCLUDE_DIRS "ConvertUTF.c")
2831
if (SIMPLEINI_INCLUDE_DIRS)
2932
message(STATUS "SIMPLEINI_INCLUDE_DIRS: ${SIMPLEINI_INCLUDE_DIRS}")
@@ -36,4 +39,5 @@ find_package(RdKafka CONFIG REQUIRED)
3639
find_package(argparse CONFIG REQUIRED)
3740

3841
add_executable(snctl-cpp main.cc)
42+
target_compile_definitions(snctl-cpp PUBLIC VERSION_STR="${VERSION_STR}")
3943
target_link_libraries(snctl-cpp PRIVATE argparse::argparse RdKafka::rdkafka)

main.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@
3232
#include <vector>
3333

3434
int main(int argc, char *argv[]) {
35-
const auto version = "0.1.0";
36-
3735
std::vector<std::string> default_config_paths{
3836
std::filesystem::current_path() / "sncloud.ini",
3937
std::filesystem::path(std::getenv("HOME")) / ".snctl-cpp" /
4038
"sncloud.ini"};
4139

42-
argparse::ArgumentParser program("snctl-cpp", version);
40+
argparse::ArgumentParser program("snctl-cpp",
41+
#ifdef VERSION_STR
42+
VERSION_STR
43+
#else
44+
"unknown"
45+
#endif
46+
);
4347
program.add_argument("--config")
4448
.default_value(default_config_paths)
4549
.help("Path to the config file");

version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.1

0 commit comments

Comments
 (0)