diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-06-05 10:54:31 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-06-05 10:54:31 +0200 |
commit | 3169331e84d4cc13192403a7f218899b5e98cfba (patch) | |
tree | 304ca917b4fb0ed4c1f6edb17492f82ec4e43d42 | |
parent | 0f838aa20384425198b832df3317667201808765 (diff) | |
download | tmwa-3169331e84d4cc13192403a7f218899b5e98cfba.tar.gz tmwa-3169331e84d4cc13192403a7f218899b5e98cfba.tar.bz2 tmwa-3169331e84d4cc13192403a7f218899b5e98cfba.tar.xz tmwa-3169331e84d4cc13192403a7f218899b5e98cfba.zip |
CMake: Generate the install.hpp and version.hpp files
The values of defines in these files should be the same as those set
from version.mk / Makefile.in.
-rw-r--r-- | CMakeLists.txt | 57 | ||||
-rw-r--r-- | src/conf/install.hpp.in | 29 | ||||
-rw-r--r-- | src/conf/version.hpp.in | 39 |
3 files changed, 121 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 564fffe..9f4effc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,31 @@ cmake_minimum_required(VERSION 3.10) -project(tmwAthena) +# Function for conveniently capturing git output, used to set version related variables +find_package(Git REQUIRED) +function(git_capture_output var) + execute_process(COMMAND ${GIT_EXECUTABLE} ${ARGN} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE ${var} + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) + message(STATUS "${var} = ${${var}}") + set(${var} ${${var}} PARENT_SCOPE) +endfunction() + +git_capture_output(VERSION_FULL describe --tags) +git_capture_output(VERSION_HASH rev-parse HEAD) + +# Capture the major.minor.patch part of the version based on the last tag +string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION ${VERSION_FULL}) + +# Capture the tweak part of the version +if(${VERSION_FULL} MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+-([0-9]+)-g[0-9a-f]+$") + set(VERSION "${VERSION}.${CMAKE_MATCH_1}") +else() + set(VERSION "${VERSION}.0") +endif() + +project(tmwAthena VERSION ${VERSION} LANGUAGES CXX) # Prefer to use G++ as the compiler set(CMAKE_CXX_COMPILER g++) @@ -39,8 +64,32 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -fstack-protector -fno-strict-aliasi # Add debug information #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb") -set_source_files_properties($(ALL_SOURCES) PROPERTIES IMPLICIT_DEPENDS CXX) - +# Vendor Name: String (no newlines, no parentheses) +# This is usually one word, and does not (usually) change over time. +# (Examples: Gentoo, Debian, Fedora, Ubuntu) +set(VENDOR_NAME Vanilla) +# Vendor Point: Integer (max value 65535) +# This is intended to be the "packaging revision number", assuming that's +# an integer. At a minimum, please try to make it nonzero if you have +# any non-upstream patches (unconditionally nonzero is also okay). +# (If your revision 0 package has patches ... please be nicer to upstream) +set(VENDOR_POINT 0) +# URL where the source may be found (after searching for version number). +# See AGPLv3 section 13 +set(VENDOR_SOURCE https://github.com/themanaworld/tmwa) + +# Convenience +set(VERSION_STRING "TMWA ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} dev${PROJECT_VERSION_TWEAK} +${VENDOR_POINT} (${VENDOR_NAME})") +set(VERSION_DOTS "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK}.${VENDOR_POINT}") + +include(GNUInstallDirs) +set(PACKAGEDATADIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/tmwa") +set(PACKAGELOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/tmwa") +set(PACKAGESYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/tmwa") + +configure_file(src/conf/install.hpp.in src/conf/install.hpp @ONLY) +configure_file(src/conf/version.hpp.in src/conf/version.hpp @ONLY) +set(conf_SOURCES ${conf_SOURCES} src/conf/install.hpp src/conf/version.hpp) # Add a shared library: libtmwa-shared.so.0 # When we add_executable later, we need to link against this library. @@ -52,7 +101,7 @@ add_library(tmwa-shared SHARED ${shared_SOURCES} ${strings_SOURCES} ) # SO versioning -set_target_properties(tmwa-shared PROPERTIES VERSION 23.10.22.24.0 SOVERSION 0) +set_target_properties(tmwa-shared PROPERTIES VERSION ${PROJECT_VERSION}.0 SOVERSION 0) # We have four binaries we want to build: tmwa-{login,char,map,admin} add_executable(tmwa-login ${login_SOURCES} diff --git a/src/conf/install.hpp.in b/src/conf/install.hpp.in new file mode 100644 index 0000000..c44f026 --- /dev/null +++ b/src/conf/install.hpp.in @@ -0,0 +1,29 @@ +#pragma once +// conf/install.hpp - Import configuration variables related to install. +// +// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com> +// +// This file is part of The Mana World (Athena server) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +// just mention "fwd.hpp" to make formatter happy + +#define PACKAGESYSCONFDIR "@PACKAGESYSCONFDIR@"_s +#define PACKAGELOCALSTATEDIR "@PACKAGELOCALSTATEDIR@"_s +#define PACKAGEDATADIR "@PACKAGEDATADIR@"_s + +namespace tmwa +{ +} // namespace tmwa diff --git a/src/conf/version.hpp.in b/src/conf/version.hpp.in new file mode 100644 index 0000000..126fae2 --- /dev/null +++ b/src/conf/version.hpp.in @@ -0,0 +1,39 @@ +#pragma once +// conf/version.hpp - Import configuration variables related to version. +// +// Copyright © 2013-2014 Ben Longbons <b.r.longbons@gmail.com> +// +// This file is part of The Mana World (Athena server) +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. + +// just mention "fwd.hpp" to make formatter happy + +#define VERSION_FULL "@VERSION_FULL@"_s +#define VERSION_HASH "@VERSION_HASH@"_s + +#define VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define VERSION_PATCH @PROJECT_VERSION_PATCH@ +#define VERSION_DEVEL @PROJECT_VERSION_TWEAK@ + +#define VENDOR_NAME "@VENDOR_NAME@"_s +#define VENDOR_POINT @VENDOR_POINT@ +#define VENDOR_SOURCE "@VENDOR_SOURCE@"_s + +#define VERSION_STRING "@VERSION_STRING@"_s + +namespace tmwa +{ +} // namespace tmwa |