From cf4e4272f72346c39964b128f78b2297f04dba55 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 17 Mar 2021 11:53:28 +0100 Subject: Tidy how we're finding the tags and xsd directories. --- src/util.cc | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'src/util.cc') 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 #include #include -#include #include +#if BOOST_VERSION >= 106100 +#include +#endif +#include #include #include #include @@ -192,12 +195,7 @@ dcp::init (optional 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 +} + + -- cgit v1.2.3