2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-29 00:10:54 +00:00

Add qpdf version macros to qpdf/DLL.h

This commit is contained in:
Jay Berkenbilt 2022-02-04 12:21:52 -05:00
parent abc300f05c
commit 8eab616d62
7 changed files with 76 additions and 8 deletions

View File

@ -1,5 +1,14 @@
2022-02-04 Jay Berkenbilt <ejb@ql.org> 2022-02-04 Jay Berkenbilt <ejb@ql.org>
* 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 * PointerHolder: deprecate getPointer() and getRefcount(). If you
don't want to disable deprecation warnings in general but are not don't want to disable deprecation warnings in general but are not
ready to tackle this change yet, you can define ready to tackle this change yet, you can define

3
TODO
View File

@ -3,9 +3,6 @@
* Close issue #556. * 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 * Add user-defined initializer `QPDFObjectHandle operator ""_qpdf` to
be like QPDFObjectHandle::parse: `auto oh = "<< /a (b) >>"_qpdf;` be like QPDFObjectHandle::parse: `auto oh = "<< /a (b) >>"_qpdf;`

View File

@ -23,6 +23,12 @@
#ifndef QPDF_DLL_HH #ifndef QPDF_DLL_HH
#define 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) #if (defined _WIN32 || defined __CYGWIN__) && defined(DLL_EXPORT)
# define QPDF_DLL __declspec(dllexport) # define QPDF_DLL __declspec(dllexport)
# define QPDF_DLL_CLASS # define QPDF_DLL_CLASS

View File

@ -52,7 +52,8 @@ class BitWriter;
class QPDF class QPDF
{ {
public: public:
// Get the current version of the QPDF software // Get the current version of the QPDF software. See also
// qpdf/Version.h
QPDF_DLL QPDF_DLL
static std::string const& QPDFVersion(); static std::string const& QPDFVersion();

34
include/qpdf/Version.h Normal file
View File

@ -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 */

View File

@ -25,7 +25,7 @@
#include <qpdf/QPDF_Stream.hh> #include <qpdf/QPDF_Stream.hh>
#include <qpdf/QPDF_Array.hh> #include <qpdf/QPDF_Array.hh>
std::string QPDF::qpdf_version = "10.5.0"; std::string QPDF::qpdf_version(QPDF_VERSION);
static char const* EMPTY_PDF = static char const* EMPTY_PDF =
"%PDF-1.3\n" "%PDF-1.3\n"

View File

@ -121,16 +121,37 @@ sub get_version_from_configure
sub get_version_from_source 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 $code_version = 'unknown';
my $major = '';
my $minor = '';
my $patch = '';
while (<$fh>) 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; $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(); $fh->close();
$code_version; $code_version;
} }