diff --git a/CMakeLists.txt b/CMakeLists.txt index fd026c5..f1dbfee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR) project(i3ipc++) +string(TIMESTAMP I3IPCppBUILD_DATETIME "%Y-%m-%d %H:%M:%S") + option(I3IPCpp_WITH_TESTS "Build unit tests executables" OFF) option(I3IPCpp_BUILD_EXAMPLES "Build example executables" OFF) @@ -58,6 +60,10 @@ target_compile_options(i3ipc++ PUBLIC -std=c++11 -Wall -Wextra -Wno-unused-parameter ) +target_compile_definitions(i3ipc++ + PRIVATE I3IPC_BUILD_DATETIME="${I3IPCppBUILD_DATETIME}" +) + if (CMAKE_BUILD_TYPE EQUAL "DEBUG") target_compile_options(i3ipc++ PUBLIC -g3 diff --git a/include/i3ipc++/ipc.hpp b/include/i3ipc++/ipc.hpp index 85c6443..9e602b1 100644 --- a/include/i3ipc++/ipc.hpp +++ b/include/i3ipc++/ipc.hpp @@ -342,6 +342,12 @@ private: const std::string m_socket_path; }; +/** + * Get version of i3ipc++ + * @return the version of i3ipc++ + */ +const version_t& get_version(); + } /** diff --git a/src/ipc.cpp b/src/ipc.cpp index 171f147..06d40cd 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -553,4 +553,19 @@ int32_t connection::get_main_socket_fd() { return m_main_socket; } int32_t connection::get_event_socket_fd() { return m_event_socket; } + +const version_t& get_version() { +#define I3IPC_VERSION_MAJOR 0 +#define I3IPC_VERSION_MINOR 3 +#define I3IPC_VERSION_PATCH 0 + static version_t version = { + .human_readable = auss_t() << I3IPC_VERSION_MAJOR << '.' << I3IPC_VERSION_MINOR << '.' << I3IPC_VERSION_PATCH << " (built on " << I3IPC_BUILD_DATETIME << ")", + .loaded_config_file_name = std::string(), + .major = I3IPC_VERSION_MAJOR, + .minor = I3IPC_VERSION_MINOR, + .patch = I3IPC_VERSION_PATCH, + }; + return version; +} + }