From babf95785c82f8be1a6d0333c5349820f72e802a Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 30 Sep 2025 18:11:33 +0500 Subject: [PATCH] Move IFCOPENSHELL_VERSION definition from IfcParse.h To prevent recompiling all files that have IfcParse.h include and improve caching. --- cmake/CMakeLists.txt | 10 +++++---- src/ifcconvert/IfcConvert.cpp | 2 +- src/ifcgeomserver/IfcGeomServer.cpp | 2 +- src/ifcparse/IfcParse.cpp | 4 ++-- src/ifcparse/IfcParse.h | 7 ++---- src/ifcparse/buildinfo.cpp | 35 +++++++++++++++++++++++++++++ src/serializers/GltfSerializer.cpp | 2 +- src/serializers/USDSerializer.cpp | 2 +- 8 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 src/ifcparse/buildinfo.cpp diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 1ddd2e8469..c123deb45f 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -91,8 +91,8 @@ option(WITH_ROCKSDB "Support a RocksDB key-value store as a file backend in IfcO option(WITH_ZSTD "Use Zstd compression in RocksDB writes" OFF) option(USERSPACE_PYTHON_PREFIX "Installs IfcPython for the current user only instead of system-wide." OFF) -option(ADD_COMMIT_SHA "Add commit sha and branch in version number, warning results in many rebuilds, requires git" OFF) -option(VERSION_OVERRIDE "Override the version defined in IfcParse.h with the file VERSION in the repository root" OFF) +option(ADD_COMMIT_SHA "Add commit sha and branch in version number, requires git" OFF) +option(VERSION_OVERRIDE "Override the version defined in buildinfo.cpp with the file VERSION in the repository root" OFF) set( PYTHON_MODULE_INSTALL_DIR @@ -1363,8 +1363,10 @@ if(ADD_COMMIT_SHA) message(FATAL_ERROR "Unable to determine commit sha and/or branch") endif() - add_definitions(-DIFCOPENSHELL_BRANCH=${git_branch}) - add_definitions(-DIFCOPENSHELL_COMMIT=${git_sha}) + target_compile_definitions(IfcParse PRIVATE + -DIFCOPENSHELL_BRANCH=${git_branch} + -DIFCOPENSHELL_COMMIT=${git_sha} + ) endif() endif(ADD_COMMIT_SHA) diff --git a/src/ifcconvert/IfcConvert.cpp b/src/ifcconvert/IfcConvert.cpp index a87ebaf93c..376373006f 100644 --- a/src/ifcconvert/IfcConvert.cpp +++ b/src/ifcconvert/IfcConvert.cpp @@ -1664,7 +1664,7 @@ void fix_quantities(IfcParse::IfcFile& f, bool no_progress, bool quiet, bool std latebound_access::set(application, "ApplicationDeveloper", org); latebound_access::set(application, "Version", std::string(IFCOPENSHELL_VERSION)); latebound_access::set(application, "ApplicationFullName", std::string("IfcConvert")); - latebound_access::set(application, "ApplicationIdentifier", std::string("IfcConvert" IFCOPENSHELL_VERSION)); + latebound_access::set(application, "ApplicationIdentifier", std::string("IfcConvert") + IFCOPENSHELL_VERSION); auto ownerhist = latebound_access::create(f, "IfcOwnerHistory"); latebound_access::set(ownerhist, "OwningUser", pando); diff --git a/src/ifcgeomserver/IfcGeomServer.cpp b/src/ifcgeomserver/IfcGeomServer.cpp index 34ff040dd8..b01e4ed992 100644 --- a/src/ifcgeomserver/IfcGeomServer.cpp +++ b/src/ifcgeomserver/IfcGeomServer.cpp @@ -191,7 +191,7 @@ protected: } public: const std::string& string() { return str; } - Hello() : Command(HELLO), str("IfcOpenShell-" IFCOPENSHELL_VERSION "-0") {} + Hello() : Command(HELLO), str("IfcOpenShell-" + std::string(IFCOPENSHELL_VERSION) + "-0") {} }; class More : public Command { diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index a92b9b1347..4f06ce4660 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -2706,8 +2706,8 @@ void IfcFile::setDefaultHeaderValues() { header().file_name()->settime_stamp(createTimestamp()); header().file_name()->setauthor(string_vector); header().file_name()->setorganization(string_vector); - header().file_name()->setpreprocessor_version("IfcOpenShell " IFCOPENSHELL_VERSION); - header().file_name()->setoriginating_system("IfcOpenShell " IFCOPENSHELL_VERSION); + header().file_name()->setpreprocessor_version("IfcOpenShell " + std::string(IFCOPENSHELL_VERSION)); + header().file_name()->setoriginating_system("IfcOpenShell " + std::string(IFCOPENSHELL_VERSION)); header().file_name()->setauthorization(empty_string); header().file_schema()->setschema_identifiers(schema_identifiers); diff --git a/src/ifcparse/IfcParse.h b/src/ifcparse/IfcParse.h index 229ea1b9c1..9430866ae7 100644 --- a/src/ifcparse/IfcParse.h +++ b/src/ifcparse/IfcParse.h @@ -43,11 +43,8 @@ #include #include -#if defined(IFCOPENSHELL_BRANCH) && defined(IFCOPENSHELL_COMMIT) -#define IFCOPENSHELL_VERSION STRINGIFY(IFCOPENSHELL_BRANCH) "-" STRINGIFY(IFCOPENSHELL_COMMIT) -#else -#define IFCOPENSHELL_VERSION "0.8.0" -#endif + +extern const char *IFCOPENSHELL_VERSION; namespace IfcParse { diff --git a/src/ifcparse/buildinfo.cpp b/src/ifcparse/buildinfo.cpp new file mode 100644 index 0000000000..0785712e2e --- /dev/null +++ b/src/ifcparse/buildinfo.cpp @@ -0,0 +1,35 @@ +/******************************************************************************** + * * + * This file is part of IfcOpenShell. * + * * + * IfcOpenShell is free software: you can redistribute it and/or modify * + * it under the terms of the Lesser GNU General Public License as published by * + * the Free Software Foundation, either version 3.0 of the License, or * + * (at your option) any later version. * + * * + * IfcOpenShell 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 * + * Lesser GNU General Public License for more details. * + * * + * You should have received a copy of the Lesser GNU General Public License * + * along with this program. If not, see . * + * * + ********************************************************************************/ + +/******************************************************************************** + * * + * This file provides functions for loading an IFC file into memory and access * + * its entities either by ID, by an IfcSchema::Type or by reference * + * * + ********************************************************************************/ + +#include +#include "macros.h" + + +#if defined(IFCOPENSHELL_BRANCH) && defined(IFCOPENSHELL_COMMIT) +const char *IFCOPENSHELL_VERSION = STRINGIFY(IFCOPENSHELL_BRANCH) "-" STRINGIFY(IFCOPENSHELL_COMMIT); +#else +const char *IFCOPENSHELL_VERSION = "0.8.0"; +#endif diff --git a/src/serializers/GltfSerializer.cpp b/src/serializers/GltfSerializer.cpp index b8487a5fb7..32844c67ca 100644 --- a/src/serializers/GltfSerializer.cpp +++ b/src/serializers/GltfSerializer.cpp @@ -74,7 +74,7 @@ bool GltfSerializer::ready() { } void GltfSerializer::writeHeader() { - json_["asset"]["generator"] = "IfcOpenShell IfcConvert " IFCOPENSHELL_VERSION; + json_["asset"]["generator"] = "IfcOpenShell IfcConvert " + std::string(IFCOPENSHELL_VERSION); json_["asset"]["version"] = "2.0"; json_["scene"] = 0; diff --git a/src/serializers/USDSerializer.cpp b/src/serializers/USDSerializer.cpp index 82c1131534..4a4b0a7cf6 100644 --- a/src/serializers/USDSerializer.cpp +++ b/src/serializers/USDSerializer.cpp @@ -257,4 +257,4 @@ void USDSerializer::finalize() { template pxr::UsdGeomMesh USDSerializer::writeNode(const IfcGeom::Element*, const IfcGeom::Element*); template pxr::UsdGeomXform USDSerializer::writeNode(const IfcGeom::Element*, const IfcGeom::Element*); -#endif // WITH_USD \ No newline at end of file +#endif // WITH_USD