Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
vigri authored Apr 23, 2022
2 parents 8d4e15f + 155807e commit 70d87e4
Show file tree
Hide file tree
Showing 92 changed files with 880 additions and 628 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
build/
CMakeLists.txt.user
build/

119 changes: 83 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ if (NOT DEFAULT_COMPILER_FLAGS_IS_SET)
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Werror=return-type -Wno-unused")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror=return-type -Wno-unused")
add_compile_options("$<$<CONFIG:RELEASE>:-march=native;-mtune=native>")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}"
Expand Down Expand Up @@ -106,7 +107,7 @@ if (WIN32)
set(ZLIB_INSTALL_PREFIX "${zlib_dir_assumed}" CACHE PATH "Prefix where zlib is installed")
set(PNG_INSTALL_PREFIX "${png_dir_assumed}" CACHE PATH "Prefix where png is installed")
set(TIFF_INSTALL_PREFIX "${tiff_dir_assumed}" CACHE PATH "Prefix where tiff is installed")
set(QT_INSTALL_PREFIX "${qt_dir_assumed}" CACHE PATH "Prefix where Qt5 is installed")
set(QT_INSTALL_PREFIX "${qt_dir_assumed}" CACHE PATH "Prefix where Qt is installed")
set(BOOST_ROOT "${boost_dir_assumed}" CACHE PATH "Prefix where Boost is installed")

macro(list_append_existing_path Var Path)
Expand All @@ -131,7 +132,7 @@ endif()
find_package(JPEG REQUIRED)

if (WIN32)
add_dynamic_library_locations(JPEG::JPEG)
add_dynamic_library_locations(JPEG::JPEG "libjpeg-62.dll")
endif()

#=================================== ZLIB ===================================#
Expand All @@ -147,7 +148,7 @@ endif()
find_package(PNG REQUIRED)

if (WIN32)
add_dynamic_library_locations(PNG::PNG)
add_dynamic_library_locations(PNG::PNG "libpng16.dll")
endif()

#=================================== TIFF ===================================#
Expand All @@ -163,6 +164,8 @@ endif()

#================================= Boost ================================#

#set(Boost_NO_WARN_NEW_VERSIONS ON)

if (WIN32)
if (MINGW)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
Expand All @@ -172,10 +175,11 @@ if (WIN32)
endif()
set(Boost_ARCHITECTURE ${_boost_architecture} CACHE STRING "")

#set(Boost_DEBUG ON)
string(REGEX MATCHALL "[0-9]+" _boost_compiler_version ${CMAKE_CXX_COMPILER_VERSION})
list(GET _boost_compiler_version 0 _boost_compiler_version_major)
list(GET _boost_compiler_version 1 _boost_compiler_version_minor)
set(Boost_COMPILER "mgw${_boost_compiler_version_major}${_boost_compiler_version_minor}" CACHE STRING "")
set(Boost_COMPILER "-mgw${_boost_compiler_version_major}" CACHE STRING "")
endif()

real_path_find_glob(boost_include_dir_hints "${BOOST_ROOT}/include/boost-[_0-9]*/boost")
Expand All @@ -202,11 +206,40 @@ endif()

#=================================== Qt ===================================#

set(qt_min_version 5.6)
set(qt_min_version 5.9)

find_package(
Qt5 ${qt_min_version}
Qt6
COMPONENTS Core Gui Widgets Xml Network LinguistTools OpenGL Svg OpenGLWidgets
CONFIG)
if (Qt6_FOUND)
set(QT_BINDIR "${QT6_INSTALL_PREFIX}/bin")
else()
find_package(Qt5 ${qt_min_version}
COMPONENTS Core Gui Widgets Xml Network LinguistTools OpenGL Svg
CONFIG REQUIRED)
set(QT_BINDIR "${QT5_INSTALL_PREFIX}/bin")
endif()

if(Qt6_FOUND)
set(Qt_Core_lib Qt::Core)
set(Qt_Gui_lib Qt::Gui)
set(Qt_Network_lib Qt::Network)
set(Qt_OpenGL_lib Qt::OpenGL)
set(Qt_Svg_lib Qt::Svg)
set(Qt_Widgets_lib Qt::Widgets)
set(Qt_Xml_lib Qt::Xml)
set(Qt_OpenGLWidgets_lib Qt::OpenGLWidgets)
else()
set(Qt_Core_lib Qt5::Core)
set(Qt_Gui_lib Qt5::Gui)
set(Qt_Network_lib Qt5::Network)
set(Qt_OpenGL_lib Qt5::OpenGL)
set(Qt_Svg_lib Qt5::Svg)
set(Qt_Widgets_lib Qt5::Widgets)
set(Qt_Xml_lib Qt5::Xml)
endif()


#=================================== Threads ===================================#

Expand Down Expand Up @@ -293,7 +326,11 @@ finalize_translations(scantailor ${translation_files})
update_translations_target(update_translations scantailor)

list(FILTER translation_files EXCLUDE REGEX ".*untranslated.ts")
qt5_add_translation(qm_files ${translation_files})
if(Qt6_FOUND)
Qt_add_translation(qm_files ${translation_files})
else()
Qt5_add_translation(qm_files ${translation_files})
endif()
add_custom_target(compile_translations ALL DEPENDS ${qm_files})
if (WIN32)
install(FILES ${qm_files} DESTINATION "${CMAKE_INSTALL_BINDIR}/translations")
Expand Down Expand Up @@ -324,10 +361,17 @@ if (WIN32)
endmacro()

# Install the DLLs of the dependencies.
set(dep_libs
JPEG::JPEG PNG::PNG ZLIB::ZLIB TIFF::TIFF
Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Xml
Qt5::Network Qt5::OpenGL Qt5::Svg)
if(Qt6_FOUND)
set(dep_libs
JPEG::JPEG PNG::PNG ZLIB::ZLIB TIFF::TIFF
Qt::Core Qt::Gui Qt::Widgets Qt::Xml
Qt::Network Qt::OpenGL Qt::Svg Qt6::OpenGLWidgets)
else()
set(dep_libs
JPEG::JPEG PNG::PNG ZLIB::ZLIB TIFF::TIFF
Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Xml
Qt5::Network Qt5::OpenGL Qt5::Svg)
endif()

foreach (_target ${dep_libs})
get_target_property(target_type ${_target} TYPE)
Expand All @@ -346,34 +390,37 @@ if (WIN32)
add_runtime_libs_to_install(DEBUG "${debug_loc}")
endforeach()

# Install Qt's plugins.
macro (install_qt_plugin SubDir Target)
if (TARGET ${Target})
get_target_property(target_type ${Target} TYPE)
if (target_type STREQUAL "MODULE_LIBRARY")
get_target_property(release_loc ${Target} LOCATION_RELEASE)
get_target_property(debug_loc ${Target} LOCATION_DEBUG)
set_if_undefined(debug_loc "${release_loc}")

copy_to_build_dir("${release_loc}" SUBDIR ${SubDir} CONFIGURATIONS Release MinSizeRel RelWithDebInfo)
install(PROGRAMS "${release_loc}"
CONFIGURATIONS Release MinSizeRel RelWithDebInfo
#with Qt6, winqtdeploy is used to deploy plugins; the method below does not work anymore.
if (NOT Qt6_FOUND)
# Install Qt plugins.
macro (install_qt_plugin SubDir Target)
if (TARGET ${Target})
get_target_property(target_type ${Target} TYPE)
if (target_type STREQUAL "MODULE_LIBRARY")
get_target_property(release_loc ${Target} LOCATION_RELEASE)
get_target_property(debug_loc ${Target} LOCATION_DEBUG)
set_if_undefined(debug_loc "${release_loc}")

copy_to_build_dir("${release_loc}" SUBDIR ${SubDir} CONFIGURATIONS Release MinSizeRel RelWithDebInfo)
install(PROGRAMS "${release_loc}"
CONFIGURATIONS Release MinSizeRel RelWithDebInfo
DESTINATION "${CMAKE_INSTALL_BINDIR}/${SubDir}")
copy_to_build_dir("${debug_loc}" SUBDIR ${SubDir} CONFIGURATIONS Debug)
install(PROGRAMS "${debug_loc}"
CONFIGURATIONS Debug
copy_to_build_dir("${debug_loc}" SUBDIR ${SubDir} CONFIGURATIONS Debug)
install(PROGRAMS "${debug_loc}"
CONFIGURATIONS Debug
DESTINATION "${CMAKE_INSTALL_BINDIR}/${SubDir}")
endif()
endif()
endif()
endmacro()
endmacro()

install_qt_plugin("platforms" Qt::QWindowsIntegrationPlugin)
install_qt_plugin("styles" Qt::QWindowsVistaStylePlugin)
install_qt_plugin("imageformats" Qt::QJpegPlugin)
install_qt_plugin("accessible" Qt::QAccessiblePlugin)
install_qt_plugin("iconengines" Qt::QSvgIconPlugin)
install_qt_plugin("imageformats" Qt::QSvgPlugin)
endif()

install_qt_plugin("platforms" Qt5::QWindowsIntegrationPlugin)
install_qt_plugin("styles" Qt5::QWindowsVistaStylePlugin)
install_qt_plugin("imageformats" Qt5::QJpegPlugin)
install_qt_plugin("accessible" Qt5::QAccessiblePlugin)
install_qt_plugin("iconengines" Qt5::QSvgIconPlugin)
install_qt_plugin("imageformats" Qt5::QSvgPlugin)

# Install MinGW runtime components.
if (MINGW)
get_filename_component(_mingw_path ${CMAKE_CXX_COMPILER} PATH)
Expand Down Expand Up @@ -453,4 +500,4 @@ if (NOT TARGET uninstall)
add_custom_target(
uninstall
COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake")
endif()
endif()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,4 @@ has't been moved due to dirty realization. Their functionality is fully covered
Building
----------

Go to [this repository](https://github.com/4lex4/scantailor-libs-build) and follow the instructions given there.
Go to [this repository](https://github.com/vigri/scantailor-libs-build) and follow the instructions given there.
13 changes: 10 additions & 3 deletions cmake/AddDynamicLibraryLocations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# appropriate <prefix name>_DYNAMIC_LIBRARY_<Config> cache variables should be set
# or the locations should be added to CMAKE_PROGRAM_PATH or CMAKE_PREFIX_PATH variables.
#
# An optional argument can be used to specify a non-standard name for the dynamic library.

function(add_dynamic_library_locations Targets)
foreach(_target ${Targets})
Expand All @@ -38,10 +39,16 @@ function(add_dynamic_library_locations Targets)
get_filename_component(imp_loc_ext ${imp_loc} EXT)
if (imp_loc_ext STREQUAL CMAKE_IMPORT_LIBRARY_SUFFIX)
get_filename_component(lib_name_we ${imp_loc} NAME_WE)
set(candidate_names
"${lib_name_we}${CMAKE_SHARED_LIBRARY_SUFFIX}")
if(DEFINED ARGV1)
list(APPEND candidate_names ${ARGV1})
endif()
find_program(
${_target}_${dynamic_lib}
NAMES ${lib_name_we}${CMAKE_SHARED_LIBRARY_SUFFIX}
DOC Path to the dynamic library of the shared target \(skip it if the target is not shared\).)
NAMES ${candidate_names}
DOC Path to the dynamic library of the shared target \(skip it if the target is not shared\).
NO_CACHE)
if (${_target}_${dynamic_lib})
set_target_properties(
${_target} PROPERTIES
Expand All @@ -50,4 +57,4 @@ function(add_dynamic_library_locations Targets)
endif()
endforeach()
endforeach()
endfunction()
endfunction()
2 changes: 1 addition & 1 deletion cmake/UpdateTranslations.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ macro (update_translations_target _update_target) #, _targets
set(_commands "")
foreach (_target ${ARGN})
list(
APPEND _commands COMMAND Qt5::lupdate -locations absolute -no-obsolete
APPEND _commands COMMAND Qt6::lupdate -locations absolute -no-obsolete
-pro "${CMAKE_BINARY_DIR}/update_translations_${_target}.pro")
endforeach()

Expand Down
13 changes: 12 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,15 @@ target_include_directories(
"$<TARGET_PROPERTY:TIFF::TIFF,INTERFACE_INCLUDE_DIRECTORIES>")
install(TARGETS scantailor RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

translation_sources(scantailor ${gui_only_sources} ${gui_only_ui_files})
if (Qt6_FOUND AND WIN32)
#manage plugins with windeployqt.
add_custom_command(
TARGET scantailor
POST_BUILD
COMMAND ${QT_BINDIR}/windeployqt $<TARGET_FILE:scantailor>
COMMENT "deploy qt files alongside binary (e.g. plugins)"
)
install(CODE "execute_process(COMMAND \"${QT_BINDIR}/windeployqt\" \"\$\{CMAKE_INSTALL_PREFIX\}\")")
endif()

translation_sources(scantailor ${gui_only_sources} ${gui_only_ui_files})
1 change: 1 addition & 0 deletions src/app/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QSortFilterProxyModel>
#include <QStackedLayout>
#include <QtWidgets/QInputDialog>
#include <QActionGroup>
#include <boost/lambda/lambda.hpp>
#include <memory>

Expand Down
1 change: 1 addition & 0 deletions src/app/ProjectFilesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QMessageBox>
#include <QSettings>
#include <QSortFilterProxyModel>
#include <QVector>
#include <deque>

#include "ImageMetadataLoader.h"
Expand Down
12 changes: 8 additions & 4 deletions src/app/RelinkablePathVisualization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include <QPaintEvent>
#include <QPushButton>
#include <QStyle>
#include <QFile>
#include <QStyleOption>
#include <QStylePainter>
#include <boost/bind.hpp>
#include <boost/bind/bind.hpp>

#include "ColorSchemeManager.h"
#include "RelinkablePath.h"
Expand Down Expand Up @@ -38,7 +39,6 @@ class RelinkablePathVisualization::ComponentButton : public QPushButton {
RelinkablePathVisualization::RelinkablePathVisualization(QWidget* parent)
: QWidget(parent), m_layout(new QHBoxLayout(this)) {
m_layout->setSpacing(0);
m_layout->setMargin(0);
}

void RelinkablePathVisualization::clear() {
Expand All @@ -53,8 +53,12 @@ void RelinkablePathVisualization::clear() {

void RelinkablePathVisualization::setPath(const RelinkablePath& path, bool clickable) {
clear();

QStringList components(path.normalizedPath().split(QChar('/'), QString::SkipEmptyParts));
#if QT_VERSION_MAJOR == 5 and QT_VERSION_MINOR < 14
auto opt = QString::SkipEmptyParts;
#else
auto opt = Qt::SkipEmptyParts;
#endif
QStringList components(path.normalizedPath().split(QChar('/'), opt));
if (components.empty()) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
#include "MainWindow.h"

int main(int argc, char* argv[]) {
#if QT_VERSION_MAJOR == 5
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);

#endif
Application app(argc, argv);

#ifdef _WIN32
Expand Down
7 changes: 6 additions & 1 deletion src/core/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ std::list<QString> Application::getLanguagesList() const {
}

void Application::initTranslations() {
const QStringList translationDirs(QString::fromUtf8(TRANSLATION_DIRS).split(QChar(':'), QString::SkipEmptyParts));
#if QT_VERSION_MAJOR == 5 and QT_VERSION_MINOR < 14
auto opt = QString::SkipEmptyParts;
#else
auto opt = Qt::SkipEmptyParts;
#endif
const QStringList translationDirs(QString::fromUtf8(TRANSLATION_DIRS).split(QChar(':'), opt));

const QStringList languageFileFilter("scantailor_*.qm");
for (const QString& path : translationDirs) {
Expand Down
18 changes: 15 additions & 3 deletions src/core/BackgroundTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ class BackgroundTask : public AbstractCommand<FilterResultPtr>, public TaskStatu

Type type() const { return m_type; }

void cancel() override { m_cancelFlag.store(1); }

bool isCancelled() const override { return m_cancelFlag.load() != 0; }
void cancel() override {
#if QT_VERSION_MAJOR == 5 and QT_VERSION_MINOR < 14
m_cancelFlag.store(1);
#else
m_cancelFlag.storeRelaxed(1);
#endif
}

bool isCancelled() const override {
#if QT_VERSION_MAJOR == 5 and QT_VERSION_MINOR < 14
return m_cancelFlag.load() != 0;
#else
return m_cancelFlag.loadRelaxed() != 0;
#endif
}

/**
* \brief If cancelled, throws CancelledException.
Expand Down
2 changes: 2 additions & 0 deletions src/core/BlackOnWhiteEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "BlackOnWhiteEstimator.h"

#include <stdexcept>

#include <imageproc/Binarize.h>
#include <imageproc/Grayscale.h>
#include <imageproc/Morphology.h>
Expand Down
Loading

0 comments on commit 70d87e4

Please sign in to comment.