diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b7e3f926..b4da47a33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ option(ODR_CLI "enable command line interface" ON) option(ODR_CLANG_TIDY "Run clang-tidy static analysis" OFF) option(WITH_PDF2HTMLEX "Build with pdf2htmlEX" ON) option(WITH_WVWARE "Build with wvWare" ON) +option(WITH_CUSTOM_TMPFILE "Build with custom temporary file implementation" OFF) # TODO defining global compiler flags seems to be bad practice with conan # TODO consider using conan profiles @@ -247,6 +248,17 @@ if (WITH_WVWARE) ODR_WITH_WVWARE ) endif () +if (WITH_CUSTOM_TMPFILE) + find_package(tmpfile REQUIRED CONFIG) + target_link_libraries(odr + PRIVATE + tmpfile::tmpfile + ) + target_compile_definitions(odr + PRIVATE + ODR_WITH_CUSTOM_TMPFILE + ) +endif () if (EXISTS "${PROJECT_SOURCE_DIR}/.git") add_dependencies(odr check_git) diff --git a/conanfile.py b/conanfile.py index 738ec7cf6..19c7c326d 100644 --- a/conanfile.py +++ b/conanfile.py @@ -19,12 +19,14 @@ class OpenDocumentCoreConan(ConanFile): "fPIC": [True, False], "with_pdf2htmlEX": [True, False], "with_wvWare": [True, False], + "with_tmpfile_hack": [True, False], } default_options = { "shared": False, "fPIC": True, "with_pdf2htmlEX": True, "with_wvWare": True, + "with_tmpfile_hack": True, } exports_sources = ["cli/*", "cmake/*", "resources/dist/*", "src/*", "CMakeLists.txt"] @@ -35,6 +37,9 @@ def config_options(self): del self.options.with_pdf2htmlEX del self.options.with_wvWare + if self.settings.os != "Android": + del self.options.with_tmpfile_hack + def requirements(self): self.requires("pugixml/1.14") self.requires("cryptopp/8.9.0") @@ -50,6 +55,9 @@ def requirements(self): self.requires("cpp-httplib/0.16.3") self.requires("argon2/20190702-odr") + if self.options.get_safe("with_tmpfile_hack", False): + self.requires("tmpfile/3.0.6") + def build_requirements(self): self.test_requires("gtest/1.14.0") diff --git a/src/odr/global_params.cpp b/src/odr/global_params.cpp index cd7f67ebb..f34af2cc9 100644 --- a/src/odr/global_params.cpp +++ b/src/odr/global_params.cpp @@ -6,6 +6,10 @@ #include #endif +#ifdef ODR_WITH_CUSTOM_TMPFILE +#include +#endif + namespace odr { GlobalParams &GlobalParams::instance() { @@ -41,6 +45,10 @@ const std::string &GlobalParams::pdf2htmlex_data_path() { return instance().m_pdf2htmlex_data_path; } +const std::string &GlobalParams::custom_tmpfile_path() { + return instance().m_custom_tmpfile_path; +} + void GlobalParams::set_odr_core_data_path(const std::string &path) { instance().m_odr_core_data_path = path; } @@ -62,6 +70,14 @@ void GlobalParams::set_pdf2htmlex_data_path(const std::string &path) { instance().m_pdf2htmlex_data_path = path; } +void GlobalParams::set_custom_tmpfile_path(const std::string &path) { +#ifdef ODR_WITH_CUSTOM_TMPFILE + set_tmpfile_directory(path.c_str()); +#endif + + instance().m_custom_tmpfile_path = path; +} + GlobalParams::GlobalParams() : m_odr_core_data_path{internal::project_info::odr_data_path()}, m_fontconfig_data_path{internal::project_info::fontconfig_data_path()}, diff --git a/src/odr/global_params.hpp b/src/odr/global_params.hpp index 9888be173..bc9c58a42 100644 --- a/src/odr/global_params.hpp +++ b/src/odr/global_params.hpp @@ -10,11 +10,13 @@ class GlobalParams { static const std::string &fontconfig_data_path(); static const std::string &poppler_data_path(); static const std::string &pdf2htmlex_data_path(); + static const std::string &custom_tmpfile_path(); static void set_odr_core_data_path(const std::string &path); static void set_fontconfig_data_path(const std::string &path); static void set_poppler_data_path(const std::string &path); static void set_pdf2htmlex_data_path(const std::string &path); + static void set_custom_tmpfile_path(const std::string &path); private: static GlobalParams &instance(); @@ -25,6 +27,7 @@ class GlobalParams { std::string m_fontconfig_data_path; std::string m_poppler_data_path; std::string m_pdf2htmlex_data_path; + std::string m_custom_tmpfile_path; }; } // namespace odr