From 3cda7481228dc8f21e765bb765431f39bc9a38db Mon Sep 17 00:00:00 2001 From: Olivia Date: Sun, 22 Dec 2024 21:15:46 +0100 Subject: [PATCH] Sort out versioning I should've done this ages ago --- CMakeLists.txt | 31 +++++++++++++++++++++++++------ src/CMakeLists.txt | 2 ++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 688d9ad..895063e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,26 +34,31 @@ set(CURL_INSTALL OFF CACHE STRING "" FORCE) include(FetchContent) -FetchContent_Declare(stc GIT_REPOSITORY https://github.com/LunarWatcher/stc) +FetchContent_Declare(stc + GIT_REPOSITORY https://github.com/LunarWatcher/stc +) FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git - GIT_TAG 1.10.0) + GIT_TAG 1.11.1 +) FetchContent_Declare(nlohmann GIT_REPOSITORY https://github.com/nlohmann/json - GIT_TAG v3.11.2) + GIT_TAG v3.11.3 +) FetchContent_Declare(spdlog GIT_REPOSITORY https://github.com/gabime/spdlog - GIT_TAG v1.11.0) + GIT_TAG v1.15.0 +) FetchContent_Declare(lua-cmake GIT_REPOSITORY https://github.com/LunarWatcher/lua-cmake/ ) FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git - GIT_TAG 9.1.0) + GIT_TAG 11.0.2 +) FetchContent_MakeAvailable(stc) FetchContent_MakeAvailable(fmt) -#FetchContent_MakeAvailable(cpr) FetchContent_MakeAvailable(nlohmann) FetchContent_MakeAvailable(spdlog) FetchContent_MakeAvailable(lua-cmake) @@ -62,6 +67,20 @@ if (NOT cpr_POPULATED) FetchContent_Populate(cpr) add_subdirectory(${cpr_SOURCE_DIR} ${cpr_BINARY_DIR} EXCLUDE_FROM_ALL) endif() + +# Versioning {{{ +find_program(GIT git) +if (GIT) + execute_process(COMMAND ${GIT} describe --tags --always + OUTPUT_VARIABLE UPM_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message(STATUS "Detected version: ${UPM_VERSION}") +else() + message(WARNING "Git not found. Defaulting to unknown version. This will not have an effect on the program beyond a missing version") + set(UPM_VERSION "VERSION UNKNOWN. Who doesn't have Git? It's the 2020s. Install it already") +endif() +# }}} add_subdirectory(src) add_subdirectory(tests EXCLUDE_FROM_ALL) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9f41d28..08af50e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,6 +35,8 @@ set (SOURCE_FILES add_library(upm_sources STATIC ${SOURCE_FILES}) +target_compile_options(upm_sources PUBLIC -DUPM_VERSION="${UPM_VERSION}") + target_link_libraries(upm_sources PUBLIC stc cpr::cpr fmt::fmt nlohmann_json::nlohmann_json spdlog::spdlog lua::lib) target_include_directories(upm_sources PUBLIC .)