summaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-03-17 11:53:28 +0100
committerCarl Hetherington <cth@carlh.net>2021-03-18 23:30:48 +0100
commitcf4e4272f72346c39964b128f78b2297f04dba55 (patch)
tree380d760483d5bf2cec0e33db42e82207b387ecb4 /src/util.cc
parentb0b3c6f0cdc034ef515f72d72fd72fbb71d1ca63 (diff)
Tidy how we're finding the tags and xsd directories.
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/util.cc b/src/util.cc
index 7c21c889..0b011bf9 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -56,8 +56,11 @@
#include <libxml++/nodes/element.h>
#include <libxml++/document.h>
#include <openssl/sha.h>
-#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
+#if BOOST_VERSION >= 106100
+#include <boost/dll/runtime_symbol_info.hpp>
+#endif
+#include <boost/filesystem.hpp>
#include <stdexcept>
#include <iostream>
#include <iomanip>
@@ -192,12 +195,7 @@ dcp::init (optional<boost::filesystem::path> tags_directory)
asdcp_smpte_dict = &ASDCP::DefaultSMPTEDict();
if (!tags_directory) {
- char* prefix = getenv("LIBDCP_SHARE_PREFIX");
- if (prefix) {
- tags_directory = boost::filesystem::path(prefix) / "tags";
- } else {
- tags_directory = LIBDCP_SHARE_PREFIX "/tags";
- }
+ tags_directory = resources_directory() / "tags";
}
load_language_tag_lists (*tags_directory);
@@ -440,3 +438,33 @@ ASDCPErrorSuspender::~ASDCPErrorSuspender ()
delete _sink;
}
+
+boost::filesystem::path dcp::directory_containing_executable ()
+{
+#if BOOST_VERSION >= 106100
+ return boost::filesystem::canonical(boost::dll::program_location().parent_path());
+#else
+ char buffer[PATH_MAX];
+ ssize_t N = readlink ("/proc/self/exe", buffer, PATH_MAX);
+ return boost::filesystem::path(string(buffer, N)).parent_path();
+#endif
+}
+
+
+boost::filesystem::path dcp::resources_directory ()
+{
+#if defined(LIBDCP_OSX)
+ return directory_containing_executable().parent_path() / "Resources";
+#elif defined(LIBDCP_WINDOWS)
+ return directory_containing_executable().parent_path();
+#else
+ /* We need a way to specify the tags directory for running un-installed binaries */
+ char* prefix = getenv("LIBDCP_RESOURCES");
+ if (prefix) {
+ return prefix;
+ }
+ return directory_containing_executable().parent_path() / "share" / "libdcp";
+#endif
+}
+
+