Skip to content

Commit b5bcee7

Browse files
authored
add tmpfile android hack (#443)
1 parent c30ba74 commit b5bcee7

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ option(ODR_CLI "enable command line interface" ON)
1616
option(ODR_CLANG_TIDY "Run clang-tidy static analysis" OFF)
1717
option(WITH_PDF2HTMLEX "Build with pdf2htmlEX" ON)
1818
option(WITH_WVWARE "Build with wvWare" ON)
19+
option(WITH_CUSTOM_TMPFILE "Build with custom temporary file implementation" OFF)
1920

2021
# TODO defining global compiler flags seems to be bad practice with conan
2122
# TODO consider using conan profiles
@@ -247,6 +248,17 @@ if (WITH_WVWARE)
247248
ODR_WITH_WVWARE
248249
)
249250
endif ()
251+
if (WITH_CUSTOM_TMPFILE)
252+
find_package(tmpfile REQUIRED CONFIG)
253+
target_link_libraries(odr
254+
PRIVATE
255+
tmpfile::tmpfile
256+
)
257+
target_compile_definitions(odr
258+
PRIVATE
259+
ODR_WITH_CUSTOM_TMPFILE
260+
)
261+
endif ()
250262

251263
if (EXISTS "${PROJECT_SOURCE_DIR}/.git")
252264
add_dependencies(odr check_git)

conanfile.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ class OpenDocumentCoreConan(ConanFile):
1919
"fPIC": [True, False],
2020
"with_pdf2htmlEX": [True, False],
2121
"with_wvWare": [True, False],
22+
"with_tmpfile_hack": [True, False],
2223
}
2324
default_options = {
2425
"shared": False,
2526
"fPIC": True,
2627
"with_pdf2htmlEX": True,
2728
"with_wvWare": True,
29+
"with_tmpfile_hack": True,
2830
}
2931

3032
exports_sources = ["cli/*", "cmake/*", "resources/dist/*", "src/*", "CMakeLists.txt"]
@@ -35,6 +37,9 @@ def config_options(self):
3537
del self.options.with_pdf2htmlEX
3638
del self.options.with_wvWare
3739

40+
if self.settings.os != "Android":
41+
del self.options.with_tmpfile_hack
42+
3843
def requirements(self):
3944
self.requires("pugixml/1.14")
4045
self.requires("cryptopp/8.9.0")
@@ -50,6 +55,9 @@ def requirements(self):
5055
self.requires("cpp-httplib/0.16.3")
5156
self.requires("argon2/20190702-odr")
5257

58+
if self.options.get_safe("with_tmpfile_hack", False):
59+
self.requires("tmpfile/3.0.6")
60+
5361
def build_requirements(self):
5462
self.test_requires("gtest/1.14.0")
5563

src/odr/global_params.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <poppler/GlobalParams.h>
77
#endif
88

9+
#ifdef ODR_WITH_CUSTOM_TMPFILE
10+
#include <tmpfile.h>
11+
#endif
12+
913
namespace odr {
1014

1115
GlobalParams &GlobalParams::instance() {
@@ -41,6 +45,10 @@ const std::string &GlobalParams::pdf2htmlex_data_path() {
4145
return instance().m_pdf2htmlex_data_path;
4246
}
4347

48+
const std::string &GlobalParams::custom_tmpfile_path() {
49+
return instance().m_custom_tmpfile_path;
50+
}
51+
4452
void GlobalParams::set_odr_core_data_path(const std::string &path) {
4553
instance().m_odr_core_data_path = path;
4654
}
@@ -62,6 +70,14 @@ void GlobalParams::set_pdf2htmlex_data_path(const std::string &path) {
6270
instance().m_pdf2htmlex_data_path = path;
6371
}
6472

73+
void GlobalParams::set_custom_tmpfile_path(const std::string &path) {
74+
#ifdef ODR_WITH_CUSTOM_TMPFILE
75+
set_tmpfile_directory(path.c_str());
76+
#endif
77+
78+
instance().m_custom_tmpfile_path = path;
79+
}
80+
6581
GlobalParams::GlobalParams()
6682
: m_odr_core_data_path{internal::project_info::odr_data_path()},
6783
m_fontconfig_data_path{internal::project_info::fontconfig_data_path()},

src/odr/global_params.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ class GlobalParams {
1010
static const std::string &fontconfig_data_path();
1111
static const std::string &poppler_data_path();
1212
static const std::string &pdf2htmlex_data_path();
13+
static const std::string &custom_tmpfile_path();
1314

1415
static void set_odr_core_data_path(const std::string &path);
1516
static void set_fontconfig_data_path(const std::string &path);
1617
static void set_poppler_data_path(const std::string &path);
1718
static void set_pdf2htmlex_data_path(const std::string &path);
19+
static void set_custom_tmpfile_path(const std::string &path);
1820

1921
private:
2022
static GlobalParams &instance();
@@ -25,6 +27,7 @@ class GlobalParams {
2527
std::string m_fontconfig_data_path;
2628
std::string m_poppler_data_path;
2729
std::string m_pdf2htmlex_data_path;
30+
std::string m_custom_tmpfile_path;
2831
};
2932

3033
} // namespace odr

0 commit comments

Comments
 (0)