Commit 8eab616d6232099d9ad49af7be1f2e2d6b4c8d0f
1 parent
abc300f0
Add qpdf version macros to qpdf/DLL.h
Showing
7 changed files
with
76 additions
and
8 deletions
ChangeLog
| 1 | 2022-02-04 Jay Berkenbilt <ejb@ql.org> | 1 | 2022-02-04 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | ||
| 3 | + * New preprocessor symbols QPDF_MAJOR_VERSION, QPDF_MINOR_VERSION, | ||
| 4 | + QPDF_PATCH_VERSION as numbers and QPDF_VERSION as a string. These | ||
| 5 | + can be used for feature testing in code. These are in qpdf/DLL.h, | ||
| 6 | + which is included by every header that adds to the public API. | ||
| 7 | + Since these constants are introduced in version 10.6, it's | ||
| 8 | + important for them to be in a header that everyone already | ||
| 9 | + includes so you don't have to try to include a header that won't | ||
| 10 | + be there. | ||
| 11 | + | ||
| 3 | * PointerHolder: deprecate getPointer() and getRefcount(). If you | 12 | * PointerHolder: deprecate getPointer() and getRefcount(). If you |
| 4 | don't want to disable deprecation warnings in general but are not | 13 | don't want to disable deprecation warnings in general but are not |
| 5 | ready to tackle this change yet, you can define | 14 | ready to tackle this change yet, you can define |
TODO
| @@ -3,9 +3,6 @@ | @@ -3,9 +3,6 @@ | ||
| 3 | 3 | ||
| 4 | * Close issue #556. | 4 | * Close issue #556. |
| 5 | 5 | ||
| 6 | -* Add QPDF_MAJOR_VERSION, QPDF_MINOR_VERSION to some header, possibly | ||
| 7 | - dll.h since this is everywhere that there's API | ||
| 8 | - | ||
| 9 | * Add user-defined initializer `QPDFObjectHandle operator ""_qpdf` to | 6 | * Add user-defined initializer `QPDFObjectHandle operator ""_qpdf` to |
| 10 | be like QPDFObjectHandle::parse: `auto oh = "<< /a (b) >>"_qpdf;` | 7 | be like QPDFObjectHandle::parse: `auto oh = "<< /a (b) >>"_qpdf;` |
| 11 | 8 |
include/qpdf/DLL.h
| @@ -23,6 +23,12 @@ | @@ -23,6 +23,12 @@ | ||
| 23 | #ifndef QPDF_DLL_HH | 23 | #ifndef QPDF_DLL_HH |
| 24 | #define QPDF_DLL_HH | 24 | #define QPDF_DLL_HH |
| 25 | 25 | ||
| 26 | +/* The first version of qpdf to include the version constants is 10.6.0. */ | ||
| 27 | +#define QPDF_MAJOR_VERSION 10 | ||
| 28 | +#define QPDF_MINOR_VERSION 5 | ||
| 29 | +#define QPDF_PATCH_VERSION 0 | ||
| 30 | +#define QPDF_VERSION "10.5.0" | ||
| 31 | + | ||
| 26 | #if (defined _WIN32 || defined __CYGWIN__) && defined(DLL_EXPORT) | 32 | #if (defined _WIN32 || defined __CYGWIN__) && defined(DLL_EXPORT) |
| 27 | # define QPDF_DLL __declspec(dllexport) | 33 | # define QPDF_DLL __declspec(dllexport) |
| 28 | # define QPDF_DLL_CLASS | 34 | # define QPDF_DLL_CLASS |
include/qpdf/QPDF.hh
| @@ -52,7 +52,8 @@ class BitWriter; | @@ -52,7 +52,8 @@ class BitWriter; | ||
| 52 | class QPDF | 52 | class QPDF |
| 53 | { | 53 | { |
| 54 | public: | 54 | public: |
| 55 | - // Get the current version of the QPDF software | 55 | + // Get the current version of the QPDF software. See also |
| 56 | + // qpdf/Version.h | ||
| 56 | QPDF_DLL | 57 | QPDF_DLL |
| 57 | static std::string const& QPDFVersion(); | 58 | static std::string const& QPDFVersion(); |
| 58 | 59 |
include/qpdf/Version.h
0 → 100644
| 1 | +/* Copyright (c) 2005-2021 Jay Berkenbilt | ||
| 2 | + * | ||
| 3 | + * This file is part of qpdf. | ||
| 4 | + * | ||
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | + * you may not use this file except in compliance with the License. | ||
| 7 | + * You may obtain a copy of the License at | ||
| 8 | + * | ||
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + * | ||
| 11 | + * Unless required by applicable law or agreed to in writing, software | ||
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | + * See the License for the specific language governing permissions and | ||
| 15 | + * limitations under the License. | ||
| 16 | + * | ||
| 17 | + * Versions of qpdf prior to version 7 were released under the terms | ||
| 18 | + * of version 2.0 of the Artistic License. At your option, you may | ||
| 19 | + * continue to consider qpdf to be licensed under those terms. Please | ||
| 20 | + * see the manual for additional information. | ||
| 21 | + */ | ||
| 22 | + | ||
| 23 | +#ifndef QPDF_VERSION_H | ||
| 24 | +#define QPDF_VERSION_H | ||
| 25 | + | ||
| 26 | +/* The first version of qpdf to have these constants was 10.6.0. This | ||
| 27 | + * file is included by qpdf/DLL.h, which is included by everything | ||
| 28 | + * that adds to the public API, so you can test for these values | ||
| 29 | + * without explicitly including this file in code that has to work | ||
| 30 | + * with older qpdf than 10.6.0. | ||
| 31 | + */ | ||
| 32 | + | ||
| 33 | + | ||
| 34 | +#endif /* QPDF_VERSION_H */ |
libqpdf/QPDF.cc
| @@ -25,7 +25,7 @@ | @@ -25,7 +25,7 @@ | ||
| 25 | #include <qpdf/QPDF_Stream.hh> | 25 | #include <qpdf/QPDF_Stream.hh> |
| 26 | #include <qpdf/QPDF_Array.hh> | 26 | #include <qpdf/QPDF_Array.hh> |
| 27 | 27 | ||
| 28 | -std::string QPDF::qpdf_version = "10.5.0"; | 28 | +std::string QPDF::qpdf_version(QPDF_VERSION); |
| 29 | 29 | ||
| 30 | static char const* EMPTY_PDF = | 30 | static char const* EMPTY_PDF = |
| 31 | "%PDF-1.3\n" | 31 | "%PDF-1.3\n" |
make_dist
| @@ -121,16 +121,37 @@ sub get_version_from_configure | @@ -121,16 +121,37 @@ sub get_version_from_configure | ||
| 121 | 121 | ||
| 122 | sub get_version_from_source | 122 | sub get_version_from_source |
| 123 | { | 123 | { |
| 124 | - my $fh = safe_open("libqpdf/QPDF.cc"); | 124 | + my $fh = safe_open("include/qpdf/DLL.h"); |
| 125 | my $code_version = 'unknown'; | 125 | my $code_version = 'unknown'; |
| 126 | + my $major = ''; | ||
| 127 | + my $minor = ''; | ||
| 128 | + my $patch = ''; | ||
| 126 | while (<$fh>) | 129 | while (<$fh>) |
| 127 | { | 130 | { |
| 128 | - if (m/QPDF::qpdf_version = \"([^\"]+)\"/) | 131 | + if (m/QPDF_MAJOR_VERSION (\d+)/) |
| 132 | + { | ||
| 133 | + $major = $1; | ||
| 134 | + } | ||
| 135 | + elsif (m/QPDF_MINOR_VERSION (\d+)/) | ||
| 136 | + { | ||
| 137 | + $minor = $1; | ||
| 138 | + } | ||
| 139 | + elsif (m/QPDF_PATCH_VERSION (\d+)/) | ||
| 140 | + { | ||
| 141 | + $patch = $1; | ||
| 142 | + } | ||
| 143 | + elsif (m/QPDF_VERSION \"([^\"]+)\"/) | ||
| 129 | { | 144 | { |
| 130 | $code_version = $1; | 145 | $code_version = $1; |
| 131 | - last; | ||
| 132 | } | 146 | } |
| 133 | } | 147 | } |
| 148 | + my $t = sprintf("%s.%s.%s", $major, $minor, $patch); | ||
| 149 | + if ($t ne $code_version) | ||
| 150 | + { | ||
| 151 | + die "$whoami: version is inconsistent in DLL.h:" . | ||
| 152 | + " $t vs $code_version\n"; | ||
| 153 | + } | ||
| 154 | + | ||
| 134 | $fh->close(); | 155 | $fh->close(); |
| 135 | $code_version; | 156 | $code_version; |
| 136 | } | 157 | } |