Commit 515d16fe by Maarten L. Hekkelman

update for configure

parent 896a8ebb
...@@ -30,8 +30,7 @@ firstTarget: all ...@@ -30,8 +30,7 @@ firstTarget: all
CXX = @CXX@ CXX = @CXX@
CXXFLAGS = @CXXFLAGS@ @BOOST_CPPFLAGS@ @LIBBZ2_CPPFLAGS@ CXXFLAGS = @CXXFLAGS@ @BOOST_CPPFLAGS@ @LIBBZ2_CPPFLAGS@
LDFLAGS = @LDFLAGS@ @LIBS@ @BOOST_LDFLAGS@ @LIBBZ2_LDFLAGS@ LDFLAGS = @LDFLAGS@ @LIBS@ @BOOST_LDFLAGS@ @LIBBZ2_LDFLAGS@
LIBS = @BOOST_IOSTREAMS_LIB@ \ LIBS = @LIBS@
@LIBS@
prefix = @prefix@ prefix = @prefix@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@
......
...@@ -33,20 +33,9 @@ AC_CHECK_HEADER_STDBOOL ...@@ -33,20 +33,9 @@ AC_CHECK_HEADER_STDBOOL
AC_CHECK_TYPES([ptrdiff_t]) AC_CHECK_TYPES([ptrdiff_t])
AC_PROG_MAKE_SET AC_PROG_MAKE_SET
AC_ARG_VAR([USE_RSRC], [Use resources to store internal data, requires mrc]) AX_BOOST_BASE([1.71], [], [
AC_ARG_VAR([MRC], [Specify a location for the mrc executable]) AC_MSG_ERROR([Sorry, your boost is not found or not up-to-date.])
])
dnl We really like to use mrc
if test "x$MRC" = "x"; then
AC_PATH_PROG([MRC], [mrc])
fi
if test "x$MRC" = "x"; then
AC_MSG_WARN([mrc not found, building without support for resources.])
else
USE_RSRC=1
fi
AX_BOOST_BASE([1.71])
AX_BOOST_REGEX AX_BOOST_REGEX
AX_CHECK_LIBRARY([LIBZ], [zlib.h], [z], [], AX_CHECK_LIBRARY([LIBZ], [zlib.h], [z], [],
......
...@@ -252,10 +252,10 @@ class rsrc_loader ...@@ -252,10 +252,10 @@ class rsrc_loader
static void init(std::initializer_list<rsrc_loader_info> loaders = static void init(std::initializer_list<rsrc_loader_info> loaders =
{ {
{ rsrc_loader_type::file, "." },
#if USE_RSRC #if USE_RSRC
{ rsrc_loader_type::mrsrc, "", { gResourceIndex, gResourceData, gResourceName } }, { rsrc_loader_type::mrsrc, "", { gResourceIndex, gResourceData, gResourceName } }
#endif #endif
{ rsrc_loader_type::file, "." }
}) })
{ {
assert(not s_instance); assert(not s_instance);
......
/*- /* include/cif++/Config.hpp.in. Generated from configure.ac by autoheader. */
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#if defined(_MSC_VER)
// These are Microsoft Visual C++ special settings
// the iso646 file contains the C++ keywords that are
// otherwise not recognized.
#include <ciso646>
#define snprintf _snprintf
// Disable some warnings
#pragma warning (disable : 4996)
#pragma warning (disable : 4355)
#endif
/* define if the Boost library is available */ /* define if the Boost library is available */
#undef HAVE_BOOST #undef HAVE_BOOST
/* define if the Boost::IOStreams library is available */
#undef HAVE_BOOST_IOSTREAMS
/* define if the Boost::Regex library is available */ /* define if the Boost::Regex library is available */
#undef HAVE_BOOST_REGEX #undef HAVE_BOOST_REGEX
/* define if the Boost::Thread library is available */
#undef HAVE_BOOST_THREAD
/* define if the compiler supports basic C++17 syntax */ /* define if the compiler supports basic C++17 syntax */
#undef HAVE_CXX17 #undef HAVE_CXX17
...@@ -69,10 +24,6 @@ ...@@ -69,10 +24,6 @@
/* Define to 1 if LIBZ is found */ /* Define to 1 if LIBZ is found */
#undef HAVE_LIBZ #undef HAVE_LIBZ
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
to 0 otherwise. */
#undef HAVE_MALLOC
/* Define to 1 if you have the <memory.h> header file. */ /* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H #undef HAVE_MEMORY_H
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include <atomic> #include <atomic>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
#include <filesystem>
#include <fstream>
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define TERM_WIDTH 80 #define TERM_WIDTH 80
...@@ -48,6 +50,7 @@ ...@@ -48,6 +50,7 @@
#include "cif++/CifUtils.hpp" #include "cif++/CifUtils.hpp"
namespace ba = boost::algorithm; namespace ba = boost::algorithm;
namespace fs = std::filesystem;
namespace cif namespace cif
{ {
...@@ -732,6 +735,58 @@ rsrc mrsrc_rsrc_loader_impl::load(const std::string& path) const ...@@ -732,6 +735,58 @@ rsrc mrsrc_rsrc_loader_impl::load(const std::string& path) const
return { m_data + node->m_data, node->m_size }; return { m_data + node->m_data, node->m_size };
} }
struct mrsrc_file_loader_impl : public rsrc_loader_impl
{
mrsrc_file_loader_impl(const rsrc_loader_info& info);
virtual rsrc load(const std::string& path) const;
fs::path m_rsrc_dir;
mutable std::mutex m_mutex;
mutable std::map<fs::path,std::string> m_cache;
};
mrsrc_file_loader_impl::mrsrc_file_loader_impl(const rsrc_loader_info& info)
: m_rsrc_dir(info.info)
{
if (not fs::is_directory(m_rsrc_dir))
{
std::cerr << "The directory " << info.info << " does not exist" << std::endl
<< "Loading dictionaries will most likely fail" << std::endl;
}
}
rsrc mrsrc_file_loader_impl::load(const std::string& path) const
{
std::unique_lock lock(m_mutex);
fs::path p = m_rsrc_dir / path;
if (fs::exists(p))
{
auto i = m_cache.find(p);
if (i == m_cache.end())
{
std::ostringstream s;
std::ifstream f(p);
if (not f.is_open())
throw std::runtime_error("Could not open " + p.string());
std::string line;
while (std::getline(f, line))
s << line << std::endl;
std::string data = s.str();
std::tie(i, std::ignore) = m_cache.emplace(p, data);
}
return { i->second.c_str(), i->second.length() };
}
return {};
}
rsrc_loader::rsrc_loader(const std::initializer_list<rsrc_loader_info>& loaders) rsrc_loader::rsrc_loader(const std::initializer_list<rsrc_loader_info>& loaders)
{ {
for (auto& l: loaders) for (auto& l: loaders)
...@@ -741,6 +796,7 @@ rsrc_loader::rsrc_loader(const std::initializer_list<rsrc_loader_info>& loaders) ...@@ -741,6 +796,7 @@ rsrc_loader::rsrc_loader(const std::initializer_list<rsrc_loader_info>& loaders)
switch (l.type) switch (l.type)
{ {
case rsrc_loader_type::file: case rsrc_loader_type::file:
m_loaders.push_back(new mrsrc_file_loader_impl(l));
break; break;
case rsrc_loader_type::mrsrc: case rsrc_loader_type::mrsrc:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment