diff --git a/ChangeLog b/ChangeLog index 2c88b717..803f4dec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2022-02-04 Jay Berkenbilt + * New preprocessor symbols QPDF_MAJOR_VERSION, QPDF_MINOR_VERSION, + QPDF_PATCH_VERSION as numbers and QPDF_VERSION as a string. These + can be used for feature testing in code. These are in qpdf/DLL.h, + which is included by every header that adds to the public API. + Since these constants are introduced in version 10.6, it's + important for them to be in a header that everyone already + includes so you don't have to try to include a header that won't + be there. + * PointerHolder: deprecate getPointer() and getRefcount(). If you don't want to disable deprecation warnings in general but are not ready to tackle this change yet, you can define diff --git a/TODO b/TODO index 73ba5788..b57cc7e9 100644 --- a/TODO +++ b/TODO @@ -3,9 +3,6 @@ * Close issue #556. -* Add QPDF_MAJOR_VERSION, QPDF_MINOR_VERSION to some header, possibly - dll.h since this is everywhere that there's API - * Add user-defined initializer `QPDFObjectHandle operator ""_qpdf` to be like QPDFObjectHandle::parse: `auto oh = "<< /a (b) >>"_qpdf;` diff --git a/include/qpdf/DLL.h b/include/qpdf/DLL.h index 9c38f8a9..21ae2b88 100644 --- a/include/qpdf/DLL.h +++ b/include/qpdf/DLL.h @@ -23,6 +23,12 @@ #ifndef QPDF_DLL_HH #define QPDF_DLL_HH +/* The first version of qpdf to include the version constants is 10.6.0. */ +#define QPDF_MAJOR_VERSION 10 +#define QPDF_MINOR_VERSION 5 +#define QPDF_PATCH_VERSION 0 +#define QPDF_VERSION "10.5.0" + #if (defined _WIN32 || defined __CYGWIN__) && defined(DLL_EXPORT) # define QPDF_DLL __declspec(dllexport) # define QPDF_DLL_CLASS diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index ac395358..c19d5683 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -52,7 +52,8 @@ class BitWriter; class QPDF { public: - // Get the current version of the QPDF software + // Get the current version of the QPDF software. See also + // qpdf/Version.h QPDF_DLL static std::string const& QPDFVersion(); diff --git a/include/qpdf/Version.h b/include/qpdf/Version.h new file mode 100644 index 00000000..54063f0a --- /dev/null +++ b/include/qpdf/Version.h @@ -0,0 +1,34 @@ +/* Copyright (c) 2005-2021 Jay Berkenbilt + * + * This file is part of qpdf. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Versions of qpdf prior to version 7 were released under the terms + * of version 2.0 of the Artistic License. At your option, you may + * continue to consider qpdf to be licensed under those terms. Please + * see the manual for additional information. + */ + +#ifndef QPDF_VERSION_H +#define QPDF_VERSION_H + +/* The first version of qpdf to have these constants was 10.6.0. This + * file is included by qpdf/DLL.h, which is included by everything + * that adds to the public API, so you can test for these values + * without explicitly including this file in code that has to work + * with older qpdf than 10.6.0. + */ + + +#endif /* QPDF_VERSION_H */ diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 120feee8..a5b9f880 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -25,7 +25,7 @@ #include #include -std::string QPDF::qpdf_version = "10.5.0"; +std::string QPDF::qpdf_version(QPDF_VERSION); static char const* EMPTY_PDF = "%PDF-1.3\n" diff --git a/make_dist b/make_dist index dbbab032..0d94f194 100755 --- a/make_dist +++ b/make_dist @@ -121,16 +121,37 @@ sub get_version_from_configure sub get_version_from_source { - my $fh = safe_open("libqpdf/QPDF.cc"); + my $fh = safe_open("include/qpdf/DLL.h"); my $code_version = 'unknown'; + my $major = ''; + my $minor = ''; + my $patch = ''; while (<$fh>) { - if (m/QPDF::qpdf_version = \"([^\"]+)\"/) + if (m/QPDF_MAJOR_VERSION (\d+)/) + { + $major = $1; + } + elsif (m/QPDF_MINOR_VERSION (\d+)/) + { + $minor = $1; + } + elsif (m/QPDF_PATCH_VERSION (\d+)/) + { + $patch = $1; + } + elsif (m/QPDF_VERSION \"([^\"]+)\"/) { $code_version = $1; - last; } } + my $t = sprintf("%s.%s.%s", $major, $minor, $patch); + if ($t ne $code_version) + { + die "$whoami: version is inconsistent in DLL.h:" . + " $t vs $code_version\n"; + } + $fh->close(); $code_version; }