Skip to content

Commit 0e3e273

Browse files
committed
check TessAPI
1 parent 7d42b28 commit 0e3e273

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

.github/workflows/clang19.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
pull_request:
55
branches: [main, master]
66

7-
name: "clang 19"
7+
name: "clang19-rhub"
88

99
jobs:
1010
check:

.github/workflows/gcc14.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
on:
2+
push:
3+
branches: [main, master]
4+
pull_request:
5+
branches: [main, master]
6+
7+
name: "gcc14-rhub"
8+
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
container:
13+
image: ghcr.io/r-hub/containers/gcc14:latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Install dependencies
19+
run: |
20+
R -q -e 'pak::pkg_install(c("deps::.", "any::rcmdcheck"), dependencies = TRUE)'
21+
22+
- uses: r-lib/actions/check-r-package@v2

configure

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,27 @@ else
6565
CXX11CPP=`${R_HOME}/bin/R CMD config CXXCPP`
6666
fi
6767

68-
# Create a temporary C++ file to test the compatibility with Tesseract
68+
# Create temporary C++ files to test the compatibility with Tesseract
69+
cat <<EOF > conftest.cpp
70+
#include <tesseract/baseapi.h>
71+
#include <string>
72+
73+
int main() {
74+
tesseract::TessBaseAPI api;
75+
std::string val;
76+
// This fails to link on older Tesseract
77+
api.GetVariableAsString("test", &val);
78+
return 0;
79+
}
80+
EOF
81+
82+
if ${CXX11} -std=gnu++11 -c conftest.cpp -o conftest.o ${PKG_CFLAGS}; then
83+
CXXFLAGS="$CXXFLAGS -DTESSERACT_HAS_GETVARIABLEASSTRING"
84+
echo "Using GetVariableAsString()"
85+
else
86+
echo "Using GetStringVariable()"
87+
fi
88+
6989
cat <<EOF > conftest.cpp
7090
#include <tesseract/baseapi.h>
7191
#include <allheaders.h>

src/cpp11tesseract.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ tesseract::TessBaseAPI *get_engine(TessPtr engine) {
124124
writable::logicals out(params.size());
125125
STRING str;
126126
for (int i = 0; i < params.size(); i++) {
127-
#if TESSERACT_MAJOR_VERSION >= 5
127+
#if defined(TESSERACT_HAS_GETVARIABLEASSTRING)
128+
// Use the newer API
128129
out[i] = api->GetVariableAsString(std::string(params.at(i)).c_str(), &str);
129130
#else
130131
const char *value =
@@ -175,7 +176,8 @@ tesseract::TessBaseAPI *get_engine(TessPtr engine) {
175176
std::vector<std::string> values;
176177
for (int i = 0; i < params.size(); ++i) {
177178
STRING str;
178-
#if TESSERACT_MAJOR_VERSION >= 5
179+
#if defined(TESSERACT_HAS_GETVARIABLEASSTRING)
180+
// Use the newer API
179181
if (api->GetVariableAsString(std::string(params.at(i)).c_str(), &str)) {
180182
values.push_back(str);
181183
#else

0 commit comments

Comments
 (0)