Skip to content

Commit

Permalink
Clean up maxrversion.h/autoversion.h.in
Browse files Browse the repository at this point in the history
- No longer handle MACRO `NIGHTLY_BUILD`
- `PACKAGE_VERSION` is no longer providable
- Always show git desc
- Remove MACRO `BUILD_DATADIR`
- [Premake]: generate "autoversion.h"
  • Loading branch information
Jarod42 committed Mar 16, 2024
1 parent 435764e commit ff106bb
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 58 deletions.
42 changes: 17 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.1)

project(maxr)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/mk/cmake)

# ============================================
# === Global additional includes directories
# ============================================
Expand All @@ -18,18 +20,10 @@ if(RESINSTALLER_VERSION)
add_definitions( "-DVERSION=\"${RESINSTALLER_VERSION}\"")
endif()

if(PACKAGE_VERSION)
add_definitions( "-DPACKAGE_VERSION=\"${PACKAGE_VERSION}\"")
endif()

if(CRASH_RPT_INCLUDE_DIR)
add_definitions( -DUSE_CRASH_RPT )
endif()

if(NIGHTLY_BUILD)
add_definitions( -DNIGHTLY_BUILD )
endif()

# ============================================
# === Checks
# ============================================
Expand Down Expand Up @@ -59,23 +53,6 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes") # remove noises about C++17 attributes used
endif()

# ============================================
# === Add GIT Revision
# ============================================

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/mk/cmake)
include(GetGitRevisionDescription)
git_describe(GIT_DESC --always)

if (GIT_DESC)
message(STATUS "Setting cpp define PACKAGE_REV to ${GIT_DESC}")
add_definitions("-DHAVE_AUTOVERSION_H")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/autoversion.h.in" "${CMAKE_CURRENT_BINARY_DIR}/autoversion.h")
include_directories(${CMAKE_CURRENT_BINARY_DIR})

else()
message("Could not automativally set the maxr PACKAGE_REV from git. Set cmake variable GIT_EXECUTABLE to use this feature.")
endif()

# ============================================
# === Target
Expand Down Expand Up @@ -140,6 +117,21 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_definitions(maxr_dedicatedserver PRIVATE "NOMINMAX" "_USE_MATH_DEFINES")
endif()

# ============================================
# === Add GIT Revision
# ============================================

include(GetGitRevisionDescription)
git_describe(GIT_DESC --always)

if (GIT_DESC)
message(STATUS "Setting cpp define GIT_DESC to ${GIT_DESC}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/autoversion.h.in" "${CMAKE_CURRENT_BINARY_DIR}/autoversion.h")
target_include_directories(maxr_lib PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
else()
message("Could not automativally set the maxr GIT_DESC from git. Set cmake variable GIT_EXECUTABLE to use this feature.")
endif()

# ============================================
# === Install
# ============================================
Expand Down
40 changes: 40 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,33 @@ print("SDL2 library path: ", SDL2_libraryPath)
print("vorbis header path: ", vorbis_headerPath)
print("ogg header path: ", ogg_headerPath)

local function autoversion_h()
local git_tag, errorCode = os.outputof("git describe --tag")
if errorCode == 0 then
print("git description: ", git_tag)
local content = io.readfile("src/autoversion.h.in")
content = content:gsub("${GIT_DESC}", git_tag)

local f, err = os.writefile_ifnotequal(content, path.join(locationDir, "autoversion.h"))

if (f == 0) then
-- file not modified
elseif (f < 0) then
error(err, 0)
return false
elseif (f > 0) then
print("Generated autoversion.h...")
end

return true
else
print("`git describe --tag` failed with error code", errorCode)
return false
end
end

local have_autoversion_h = autoversion_h()

local function linksToCrashRpt()
if _OPTIONS["crashRpt_root"] ~= nil then
files {
Expand Down Expand Up @@ -152,6 +179,10 @@ project "maxr"
warnings "Extra"
flags { "FatalWarnings"}

if have_autoversion_h then
includedirs { locationDir } -- for generated file (autoversion.h)
end

files { "src/ui/**.cpp", "src/ui/**.h", "src/maxr.rc" }
includedirs { "src", "src/lib" }
externalincludedirs { "submodules/nlohmann/single_include" }
Expand All @@ -172,6 +203,10 @@ project "dedicated_server"
warnings "Extra"
flags { "FatalWarnings"}

if have_autoversion_h then
includedirs { locationDir } -- for generated file (autoversion.h)
end

files { "src/dedicatedserver/**.cpp", "src/dedicated_server/**.h", "src/maxr.rc" }
includedirs { "src", "src/lib" }
externalincludedirs { "submodules/nlohmann/single_include" }
Expand Down Expand Up @@ -211,6 +246,11 @@ project "maxr_lib"
warnings "Extra"
flags { "FatalWarnings"}

if have_autoversion_h then
files { path.join(locationDir, "autoversion.h") } -- generated file
includedirs { locationDir } -- for generated file (autoversion.h)
end

files { "src/lib/**.cpp", "src/lib/**.h" } -- Source
files { "src/autoversion.h.in"} -- template to generate autoversion.h
files { "src/.clang-format" }
Expand Down
11 changes: 1 addition & 10 deletions src/autoversion.h.in
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@

# define MAX_BUILD_DATE ((std::string)__DATE__ + " " + __TIME__)

# ifdef NIGHTLY_BUILD
# define PACKAGE_REV "GIT Hash ${GIT_DESC}"
# elif NDEBUG
# define PACKAGE_REV "Releaseversion"
# else
# define PACKAGE_REV "GIT Hash ${GIT_DESC}"
# endif
#define GIT_DESC "${GIT_DESC}"
32 changes: 11 additions & 21 deletions src/lib/maxrversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,20 @@
#ifndef maxrversionH
#define maxrversionH

#if HAVE_AUTOVERSION_H
# include "autoversion.h" //include autoversion created by buildinfo.sh or cmake
# define BUILD_DATADIR "/usr/share/maxr" // TODO: reimplement setting this path in autoversion.h
#else // We have no autoversion => take care of these manually!
//default path to data dir only used on linux/other
# define BUILD_DATADIR "/usr/share/maxr"
// Builddate: Mmm DD YYYY HH:MM:SS
# define MAX_BUILD_DATE ((std::string) __DATE__ + " " + __TIME__)
# ifdef NDEBUG
# define PACKAGE_REV "Releaseversion"
# else
# define PACKAGE_REV "GIT Hash unknown"
# endif
#endif
#define PACKAGE_NAME "M.A.X.R."
#define PACKAGE_VERSION "0.2.14"

#if HAVE_CONFIG_H
# include "config.h"
#else // We have no config.h => take care of these manually
# ifndef PACKAGE_VERSION
# define PACKAGE_VERSION "0.2.14"
# endif
# define PACKAGE_NAME "M.A.X.R."
#if __has_include("autoversion.h")
# include "autoversion.h" // created by cmake/premake from autoversion.h.in
#elif !defined(GIT_DESC)
# define GIT_DESC "unknown"
#endif

#define PACKAGE_REV "GIT Hash " GIT_DESC

// Builddate: Mmm DD YYYY HH:MM:SS
#define MAX_BUILD_DATE ((std::string) __DATE__ + " " + __TIME__)

void logMAXRVersion();

#endif
4 changes: 2 additions & 2 deletions src/lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ namespace
{
// most important position holds value of configure --prefix
// to gamedata in %prefix%/$(datadir)/maxr or default path
// if autoversion.h wasn't used
BUILD_DATADIR,

"/usr/share/maxr",
"/usr/local/share/maxr",
"/usr/games/maxr",
"/usr/local/games/maxr",
Expand Down

0 comments on commit ff106bb

Please sign in to comment.