fix compilation failure when using lensfun 0.2.x

Fixes #4085
This commit is contained in:
Alberto Griggio
2017-09-16 10:54:00 +02:00
parent 91fd578f49
commit a467246834
4 changed files with 63 additions and 1 deletions

View File

@@ -445,6 +445,19 @@ if(UNIX)
install(FILES rawtherapee.appdata.xml DESTINATION "${APPDATADIR}") install(FILES rawtherapee.appdata.xml DESTINATION "${APPDATADIR}")
endif() endif()
# check whether the used version of lensfun has lfDatabase::LoadDirectory
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${LENSFUN_INCLUDE_DIRS})
check_cxx_source_compiles(
"#include <lensfun.h>
int main()
{
lfDatabase *db = 0;
bool b = db->LoadDirectory(0);
return 0;
}" LENSFUN_HAS_LOAD_DIRECTORY)
add_subdirectory(rtexif) add_subdirectory(rtexif)
add_subdirectory(rtengine) add_subdirectory(rtengine)
add_subdirectory(rtgui) add_subdirectory(rtgui)

View File

@@ -113,6 +113,11 @@ set(RTENGINESOURCEFILES
rtlensfun.cc rtlensfun.cc
) )
if(LENSFUN_HAS_LOAD_DIRECTORY)
set_source_files_properties(rtlensfun.cc PROPERTIES COMPILE_DEFINITIONS RT_LENSFUN_HAS_LOAD_DIRECTORY)
endif()
if(NOT WITH_SYSTEM_KLT) if(NOT WITH_SYSTEM_KLT)
set(RTENGINESOURCEFILES ${RTENGINESOURCEFILES} set(RTENGINESOURCEFILES ${RTENGINESOURCEFILES}
klt/convolve.cc klt/convolve.cc

View File

@@ -267,7 +267,12 @@ bool LFDatabase::init(const Glib::ustring &dbdir)
std::cout << "..." << std::flush; std::cout << "..." << std::flush;
} }
bool ok = dbdir.empty() ? (instance_.data_->Load() == LF_NO_ERROR) : instance_.data_->LoadDirectory(dbdir.c_str()); bool ok = false;
if (dbdir.empty()) {
ok = (instance_.data_->Load() == LF_NO_ERROR);
} else {
ok = instance_.LoadDirectory(dbdir.c_str());
}
if (settings->verbose) { if (settings->verbose) {
std::cout << (ok ? "OK" : "FAIL") << std::endl; std::cout << (ok ? "OK" : "FAIL") << std::endl;
@@ -277,6 +282,43 @@ bool LFDatabase::init(const Glib::ustring &dbdir)
} }
bool LFDatabase::LoadDirectory(const char *dirname)
{
#if RT_LENSFUN_HAS_LOAD_DIRECTORY
instance_.data_->LoadDirectory(dirname);
#else
// backported from lensfun 0.3.x
bool database_found = false;
GDir *dir = g_dir_open (dirname, 0, NULL);
if (dir)
{
GPatternSpec *ps = g_pattern_spec_new ("*.xml");
if (ps)
{
const gchar *fn;
while ((fn = g_dir_read_name (dir)))
{
size_t sl = strlen (fn);
if (g_pattern_match (ps, sl, fn, NULL))
{
gchar *ffn = g_build_filename (dirname, fn, NULL);
/* Ignore errors */
if (data_->Load (ffn) == LF_NO_ERROR)
database_found = true;
g_free (ffn);
}
}
g_pattern_spec_free (ps);
}
g_dir_close (dir);
}
return database_found;
#endif
}
LFDatabase::LFDatabase(): LFDatabase::LFDatabase():
data_(nullptr) data_(nullptr)
{ {

View File

@@ -117,6 +117,8 @@ private:
float focalLen, float aperture, float focusDist, float focalLen, float aperture, float focusDist,
int width, int height, bool swap_xy) const; int width, int height, bool swap_xy) const;
LFDatabase(); LFDatabase();
bool LoadDirectory(const char *dirname);
static LFDatabase instance_; static LFDatabase instance_;
lfDatabase *data_; lfDatabase *data_;
}; };