From f05c2ebc71d9ceca9bd1b1a524c84c89d36c54b4 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 26 May 2022 12:25:55 -0400 Subject: [PATCH] macro removals clean up version cmake stuff clean up generated cpp version stuff make all the windows rc stuff get generated by cmake bump release motto message properly inject release motto into version --- CMakeLists.txt | 9 +---- cmake/Version.cmake | 43 +++++++++++++++++++---- daemon/CMakeLists.txt | 2 +- llarp/constants/version.cpp.in | 23 ++++-------- llarp/constants/version.h | 24 ------------- llarp/win32/{resource.h => resource.h.in} | 2 ++ llarp/win32/{version.rc => version.rc.in} | 28 ++++++--------- 7 files changed, 57 insertions(+), 74 deletions(-) delete mode 100644 llarp/constants/version.h rename llarp/win32/{resource.h => resource.h.in} (74%) rename llarp/win32/{version.rc => version.rc.in} (64%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a36f117e..007daf6e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,14 +35,7 @@ if(APPLE) set(LOKINET_APPLE_BUILD 0) endif() -set(RELEASE_MOTTO "A Series of Tubes" CACHE STRING "Release motto") - -add_definitions(-DLLARP_VERSION_MAJOR=${lokinet_VERSION_MAJOR}) -add_definitions(-DLLARP_VERSION_MINOR=${lokinet_VERSION_MINOR}) -add_definitions(-DLLARP_VERSION_PATCH=${lokinet_VERSION_PATCH}) -if(RELEASE_MOTTO AND CMAKE_BUILD_TYPE MATCHES "[Rr][Ee][Ll][Ee][Aa][Ss][Ee]") - add_definitions(-DLLARP_RELEASE_MOTTO="${RELEASE_MOTTO}") -endif() +set(RELEASE_MOTTO "The Current Thing" CACHE STRING "Release motto") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") diff --git a/cmake/Version.cmake b/cmake/Version.cmake index 45037a081..c967d53e3 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -1,9 +1,9 @@ +# We do this via a custom command that re-invokes a cmake script because we need the DEPENDS on .git/index so that we will re-run it (to regenerate the commit tag in the version) whenever the current commit changes. If we used a configure_file directly here, it would only re-run when something else causes cmake to re-run. -find_package(Git QUIET) +set(VERSIONTAG "${GIT_VERSION}") set(GIT_INDEX_FILE "${PROJECT_SOURCE_DIR}/.git/index") if(EXISTS ${GIT_INDEX_FILE} AND ( GIT_FOUND OR Git_FOUND) ) message(STATUS "Found Git: ${GIT_EXECUTABLE}") - add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp" COMMAND "${CMAKE_COMMAND}" @@ -12,11 +12,40 @@ if(EXISTS ${GIT_INDEX_FILE} AND ( GIT_FOUND OR Git_FOUND) ) "-D" "DEST=${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp" "-P" "${CMAKE_CURRENT_LIST_DIR}/GenVersion.cmake" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/constants/version.cpp.in" - "${GIT_INDEX_FILE}") + "${GIT_INDEX_FILE}") + if(WIN32) + add_custom_command( + OUTPUT "${CMAKE_BINARY_DIR}/version.rc" + COMMAND "${CMAKE_COMMAND}" + "-D" "GIT=${GIT_EXECUTABLE}" + "-D" "SRC=${CMAKE_CURRENT_SOURCE_DIR}/constants/version.cpp.in" + "-D" "DEST=${CMAKE_BINARY_DIR}/version.rc" + "-P" "${CMAKE_CURRENT_LIST_DIR}/GenVersion.cmake" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/win32/version.rc.in" + "${GIT_INDEX_FILE}") + + add_custom_command( + OUTPUT "${CMAKE_BINARY_DIR}/lokinet_resource.h" + COMMAND "${CMAKE_COMMAND}" + "-D" "GIT=${GIT_EXECUTABLE}" + "-D" "SRC=${CMAKE_CURRENT_SOURCE_DIR}/win32/resource.h.in" + "-D" "DEST=${CMAKE_BINARY_DIR}/lokinet_resource.h" + "-P" "${CMAKE_CURRENT_LIST_DIR}/GenVersion.cmake" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/win32/resource.h.in" + "${GIT_INDEX_FILE}") + endif() else() - message(STATUS "Git was not found! Setting version to to nogit") - set(VERSIONTAG "nogit") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/constants/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp") + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/constants/version.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp" @ONLY) + if(WIN32) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/version.rc.in" "${CMAKE_BINARY_DIR}/version.rc" @ONLY) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/resource.h.in" "${CMAKE_BINARY_DIR}/lokinet_resource.h" @ONLY) + endif() endif() -add_custom_target(genversion DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp") +add_custom_target(genversion_cpp DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/constants/version.cpp") +if(WIN32) + add_custom_target(genversion_rc DEPENDS "${CMAKE_BINARY_DIR}/version.rc" "${CMAKE_BINARY_DIR}/lokinet_resource.h") +else() + add_custom_target(genversion_rc) +endif() +add_custom_target(genversion DEPENDS genversion_cpp genversion_rc) diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index a565bf96f..a65ed660a 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -49,7 +49,7 @@ endif() foreach(exe ${exetargets}) if(WIN32 AND NOT MSVC_VERSION) - target_sources(${exe} PRIVATE ../llarp/win32/version.rc) + target_sources(${exe} PRIVATE ${CMAKE_BINARY_DIR}/version.rc) target_link_libraries(${exe} PRIVATE -static-libstdc++ -static-libgcc --static -Wl,--pic-executable,-e,mainCRTStartup,--subsystem,console:5.00) target_link_libraries(${exe} PRIVATE ws2_32 iphlpapi) elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") diff --git a/llarp/constants/version.cpp.in b/llarp/constants/version.cpp.in index c21cdc8ee..57156338d 100644 --- a/llarp/constants/version.cpp.in +++ b/llarp/constants/version.cpp.in @@ -1,27 +1,16 @@ #include -#include #include -// clang-format off -#define LLARP_STRINGIFY2(val) #val -#define LLARP_STRINGIFY(val) LLARP_STRINGIFY2(val) - -#define LLARP_VERSION_STR \ - LLARP_STRINGIFY(LLARP_VERSION_MAJOR) \ - "." LLARP_STRINGIFY(LLARP_VERSION_MINOR) "." LLARP_STRINGIFY( \ - LLARP_VERSION_PATCH) -#define LLARP_VERSION_FULL LLARP_VERSION_STR "-@VERSIONTAG@" - namespace llarp { // clang-format off - const std::array VERSION{{LLARP_VERSION_MAJOR, LLARP_VERSION_MINOR, LLARP_VERSION_PATCH}}; - const std::array ROUTER_VERSION{{llarp::constants::proto_version, LLARP_VERSION_MAJOR, LLARP_VERSION_MINOR, LLARP_VERSION_PATCH}}; - const char* const VERSION_STR = LLARP_VERSION_STR; + const std::array VERSION{{@lokinet_VERSION_MAJOR@, @lokinet_VERSION_MINOR@, @lokinet_VERSION_PATCH@}}; + const std::array ROUTER_VERSION{{llarp::constants::proto_version, @lokinet_VERSION_MAJOR@, @lokinet_VERSION_MINOR@, @lokinet_VERSION_PATCH@}}; + const char* const VERSION_STR = "@lokinet_VERSION_MAJOR@.@lokinet_VERSION_MINOR@.@lokinet_VERSION_PATCH@"; const char* const VERSION_TAG = "@VERSIONTAG@"; - const char* const VERSION_FULL = LLARP_NAME "-" LLARP_VERSION_STR "-@VERSIONTAG@"; + const char* const VERSION_FULL = "lokinet-@lokinet_VERSION_MAJOR@.@lokinet_VERSION_MINOR@.@lokinet_VERSION_PATCH@-@VERSIONTAG@"; - const char* const RELEASE_MOTTO = LLARP_RELEASE_MOTTO; - const char* const DEFAULT_NETID = LLARP_DEFAULT_NETID; + const char* const RELEASE_MOTTO = "@RELEASE_MOTTO@"; + const char* const DEFAULT_NETID = "lokinet"; // clang-format on } // namespace llarp diff --git a/llarp/constants/version.h b/llarp/constants/version.h deleted file mode 100644 index 30893701e..000000000 --- a/llarp/constants/version.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -// Don't include this file directly but rather go through version.hpp instead. -// This is only here so version.cpp.in and the weird archaic windows build -// recipies can use the version. - -#define LLARP_NAME "lokinet" - -#define LLARP_DEFAULT_NETID "lokinet" - -#ifndef LLARP_RELEASE_MOTTO -#define LLARP_RELEASE_MOTTO "(dev build)" -#endif - -#if defined(_WIN32) && defined(RC_INVOKED) -#define LLARP_VERSION LLARP_VERSION_MAJOR, LLARP_VERSION_MINOR, LLARP_VERSION_PATCH, 0 - -#define MAKE_TRIPLET(X, Y, Z) TRIPLET_CAT(X, ., Y, ., Z) -#define TRIPLET_CAT(X, D1, Y, D2, Z) X##D1##Y##D2##Z - -#define LLARP_VERSION_TRIPLET \ - MAKE_TRIPLET(LLARP_VERSION_MAJOR, LLARP_VERSION_MINOR, LLARP_VERSION_PATCH) - -#endif diff --git a/llarp/win32/resource.h b/llarp/win32/resource.h.in similarity index 74% rename from llarp/win32/resource.h rename to llarp/win32/resource.h.in index d90e55303..477e93b9b 100644 --- a/llarp/win32/resource.h +++ b/llarp/win32/resource.h.in @@ -13,3 +13,5 @@ #define _APS_NEXT_SYMED_VALUE 101 #endif #endif +// clang-format off +#define lokinet_VERSION @lokinet_VERSION_MAJOR@, @lokinet_VERSION_MINOR@, @lokinet_VERSION_PATCH@, 0 diff --git a/llarp/win32/version.rc b/llarp/win32/version.rc.in similarity index 64% rename from llarp/win32/version.rc rename to llarp/win32/version.rc.in index 8b024dccd..23b4e996d 100644 --- a/llarp/win32/version.rc +++ b/llarp/win32/version.rc.in @@ -6,19 +6,13 @@ // // Microsoft Visual C++ generated resource script. // -#include "resource.h" -#include +#include "lokinet_resource.h" #ifdef __GNUC__ // make windows rc accept this #include #endif ///////////////////////////////////////////////////////////////////////////// // English (United States) resources -#define STRINGIZER(version) #version - -#define VERSION_STRING(version, codename, revision) \ - STRINGIZER(version) "-release [" STRINGIZER(codename) "] (rev-" STRINGIZER(revision) ")" - #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #ifdef _WIN32 LANGUAGE 1033,1 @@ -56,8 +50,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION LLARP_VERSION - PRODUCTVERSION LLARP_VERSION + FILEVERSION lokinet_VERSION + PRODUCTVERSION lokinet_VERSION FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x3L @@ -72,15 +66,15 @@ BEGIN BEGIN BLOCK "040904b0" BEGIN - VALUE "Comments", "includes relay/exit functionality, such code is highly experimental on non-Linux targets" - VALUE "CompanyName", "Loki Foundation" - VALUE "FileDescription", "LokiNET daemon for Microsoft® Windows® NT™" - VALUE "FileVersion", VERSION_STRING(LLARP_VERSION_TRIPLET, LLARP_RELEASE_MOTTO, VERSIONTAG) - VALUE "InternalName", "llarpd" - VALUE "LegalCopyright", "Copyright ©2018-2020 Jeff Becker, Rick V for the Loki Foundation. All rights reserved. This software is provided under the terms of the zlib-libpng licence; see the file LICENSE for details." - VALUE "OriginalFilename", "llarpd.exe" + VALUE "Comments", "This comment has invoked its 5th ammendment constitutional right to remain silent" + VALUE "CompanyName", "OPTF" + VALUE "FileDescription", "LokiNET daemon for Windows" + VALUE "FileVersion", "@lokinet_VERSION@" + VALUE "InternalName", "lokinet" + VALUE "LegalCopyright", "Copyright (c) 2018-2022 Jeff Becker, Rick V for the OPTF. This software is provided under the terms of the GPL3; see the file LICENSE for details." + VALUE "OriginalFilename", "lokinet.exe" VALUE "ProductName", "LokiNET for Windows" - VALUE "ProductVersion", VERSION_STRING(LLARP_VERSION_TRIPLET, LLARP_RELEASE_MOTTO, VERSIONTAG) + VALUE "ProductVersion", "@lokinet_VERSION@" END END BLOCK "VarFileInfo"