From 3169331e84d4cc13192403a7f218899b5e98cfba Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 5 Jun 2024 10:54:31 +0200 Subject: 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. --- src/conf/install.hpp.in | 29 +++++++++++++++++++++++++++++ src/conf/version.hpp.in | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/conf/install.hpp.in create mode 100644 src/conf/version.hpp.in (limited to 'src/conf') 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 +// +// 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 . + +// 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 +// +// 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 . + +// 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 -- cgit v1.2.3-70-g09d2 From 69a603e87496dcc05cf93d1359686c23a0c43e28 Mon Sep 17 00:00:00 2001 From: Freeyorp Date: Wed, 5 Jun 2024 10:59:41 +0000 Subject: cmake: Fix out of tree build Also remove {install,version}.hpp from source control, so they're actually generated. There may be a better way to handle this, but I'll just leave a note as a TODO for now. --- CMakeLists.txt | 8 ++++++-- src/conf/install.hpp | 30 ------------------------------ src/conf/version.hpp | 40 ---------------------------------------- 3 files changed, 6 insertions(+), 72 deletions(-) delete mode 100644 src/conf/install.hpp delete mode 100644 src/conf/version.hpp (limited to 'src/conf') diff --git a/CMakeLists.txt b/CMakeLists.txt index 11c58d0..a0587b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,8 +101,12 @@ 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) +# Generate the install.hpp and version.hpp files in the source directory. +# TODO: Is there a nicer way to handle this so we're still able to make fully +# out-of-tree builds, generating the files in the build directory, but still +# having them found by includes? +configure_file(src/conf/install.hpp.in ${CMAKE_SOURCE_DIR}/src/conf/install.hpp @ONLY) +configure_file(src/conf/version.hpp.in ${CMAKE_SOURCE_DIR}/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 diff --git a/src/conf/install.hpp b/src/conf/install.hpp deleted file mode 100644 index 42fd125..0000000 --- a/src/conf/install.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -// conf/install.hpp - Import configuration variables related to install. -// -// Copyright © 2014 Ben Longbons -// -// 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 . - -// just mention "fwd.hpp" to make formatter happy - -#include "conf-raw/str-PACKAGESYSCONFDIR.h" -#include "conf-raw/str-PACKAGELOCALSTATEDIR.h" -#include "conf-raw/str-PACKAGEDATADIR.h" - - -namespace tmwa -{ -} // namespace tmwa diff --git a/src/conf/version.hpp b/src/conf/version.hpp deleted file mode 100644 index df8a8b6..0000000 --- a/src/conf/version.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -// conf/version.hpp - Import configuration variables related to version. -// -// Copyright © 2013-2014 Ben Longbons -// -// 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 . - -// just mention "fwd.hpp" to make formatter happy - -#include "conf-raw/str-VERSION_FULL.h" -#include "conf-raw/str-VERSION_HASH.h" - -#include "conf-raw/int-VERSION_MAJOR.h" -#include "conf-raw/int-VERSION_MINOR.h" -#include "conf-raw/int-VERSION_PATCH.h" -#include "conf-raw/int-VERSION_DEVEL.h" - -#include "conf-raw/str-VENDOR_NAME.h" -#include "conf-raw/int-VENDOR_POINT.h" -#include "conf-raw/str-VENDOR_SOURCE.h" - -#include "conf-raw/str-VERSION_STRING.h" - - -namespace tmwa -{ -} // namespace tmwa -- cgit v1.2.3-70-g09d2 From 2ff7077ab900cca73e6dc3a256a67caff5d447f8 Mon Sep 17 00:00:00 2001 From: Freeyorp Date: Wed, 5 Jun 2024 13:27:51 +0000 Subject: Generate {install,version}.hpp through attoconf Or more specifically, in the attoconf buildchain. attoconf itself directly generates src/conf/install.hpp alongside Makefile, but version inforation is only available later. To generate version.hpp, I extended version.mk slightly to provide the recipe. It's not anywhere near as generic as real.make tends to be, but with any luck we'll soon be doing all builds through cmake going forward. The template for install.hpp has been changed to use variables actually provided by attoconf. PACKAGE{SYSCONF,LOCALSTATE}DIR are actually only defined in real.make, and then only in terms of SYSCONFDIR and LOCALSTATEDIR, adding `/tmwa`. It's simpler to just use the attoconf variable and adjust the template, which conveniently also simplifies the construction in CMakeLists.txt, too. --- CMakeLists.txt | 4 ++-- Makefile.in | 1 + configure | 4 +++- src/conf/install.hpp.in | 4 ++-- version.mk | 23 +++++++++++++++++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) (limited to 'src/conf') diff --git a/CMakeLists.txt b/CMakeLists.txt index dd99bf2..5981636 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,8 +98,8 @@ set(VERSION_DOTS "${PROJECT_VERSION}.${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") +set(LOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}") +set(SYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}") # Generate the install.hpp and version.hpp files in the source directory. # TODO: Is there a nicer way to handle this so we're still able to make fully diff --git a/Makefile.in b/Makefile.in index 75f91f7..df8a2df 100644 --- a/Makefile.in +++ b/Makefile.in @@ -386,6 +386,7 @@ vpath include/%.hpp ${SRC_DIR} vpath src/%.tcc ${SRC_DIR} vpath tools/% ${SRC_DIR} vpath src/%.py ${SRC_DIR} +vpath src/%.in ${SRC_DIR} .DELETE_ON_ERROR: .DEFAULT_GOAL := all diff --git a/configure b/configure index 275a9c4..7a7a9ef 100755 --- a/configure +++ b/configure @@ -112,7 +112,9 @@ def main(): srcdir = os.path.dirname(sys.argv[0]) proj = Configuration( srcdir=srcdir, - template_files=['Makefile'], + # Note that src/conf/version.hpp is made later, by Makefile. + # See version.mk (included by Makefile). + template_files=['Makefile', 'src/conf/install.hpp'], ) proj.set_package('tmwa', 'The Mana World (Athena server)'); proj.jiggle() diff --git a/src/conf/install.hpp.in b/src/conf/install.hpp.in index c44f026..e63164a 100644 --- a/src/conf/install.hpp.in +++ b/src/conf/install.hpp.in @@ -20,8 +20,8 @@ // just mention "fwd.hpp" to make formatter happy -#define PACKAGESYSCONFDIR "@PACKAGESYSCONFDIR@"_s -#define PACKAGELOCALSTATEDIR "@PACKAGELOCALSTATEDIR@"_s +#define PACKAGESYSCONFDIR "@SYSCONFDIR@/tmwa"_s +#define PACKAGELOCALSTATEDIR "@LOCALSTATEDIR@/tmwa"_s #define PACKAGEDATADIR "@PACKAGEDATADIR@"_s namespace tmwa diff --git a/version.mk b/version.mk index a5137ad..39cf181 100644 --- a/version.mk +++ b/version.mk @@ -50,6 +50,29 @@ SO_SHORT := so.${ABI_VERSION} SO_LONG := ${SO_SHORT}.${VERSION_DOTS} # and thanks for all the fish +# Fully generate version.hpp here, where we have all the relevant information. +# version.mk is included by the top level Makefile, so simply explaning how to +# make it here will let it be built later, when needed. +# Note that some variable substitutions are slightly different here to use the +# name used by standard CMake macros, such as PROJECT_VERSION_TWEAK instead of +# VERSION_DEVEL. +src/conf/version.hpp: src/conf/version.hpp.in + sed -e 's/@VERSION_FULL@/${VERSION_FULL}/g' \ + -e 's/@VERSION_HASH@/${VERSION_HASH}/g' \ + -e 's/@VERSION_STRING@/${VERSION_STRING}/g' \ + -e 's/@PROJECT_VERSION_MAJOR@/${VERSION_MAJOR}/g' \ + -e 's/@PROJECT_VERSION_MINOR@/${VERSION_MINOR}/g' \ + -e 's/@PROJECT_VERSION_PATCH@/${VERSION_PATCH}/g' \ + -e 's/@PROJECT_VERSION_TWEAK@/${VERSION_DEVEL}/g' \ + -e 's/@VENDOR_NAME@/${VENDOR_NAME}/g' \ + -e 's/@VENDOR_POINT@/${VENDOR_POINT}/g' \ + -e 's|@VENDOR_SOURCE@|${VENDOR_SOURCE}|g' \ + -e 's/@ABI_VERSION@/${ABI_VERSION}/g' \ + -e 's/@SO_SHORT@/${SO_SHORT}/g' \ + -e 's/@SO_LONG@/${SO_LONG}/g' \ + $< > $@ + + version: @echo version '${VERSION_STRING}' @echo based on commit ${VERSION_FULL} aka ${VERSION_HASH} -- cgit v1.2.3-70-g09d2