From cb8041c928d4d8c58b7e2bf3b712c0ca234b6d3b Mon Sep 17 00:00:00 2001 From: leca Date: Mon, 17 Mar 2025 22:55:36 +0300 Subject: [PATCH] divide ways of input in CMakeLists --- CMakeLists.txt | 143 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 96 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fb9e6b..1463ffd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,28 @@ cmake_minimum_required(VERSION 3.10) project(checks-parser VERSION 0.1 LANGUAGES CXX) option(BUILD_TRANSLATIONS "Build translations?" ON) +option(BUILD_EMAIL_TO_TEXT_MODE "Build email-to-text mode?" ON) +option(BUILD_OCR_MODE "Build OCR mode?" ON) +option(BUILD_OFD_LOCAL_QR_SCAN "Build OFDs' local qr scanner?" ON) +option(BUILD_OFD_BINARYEYE_SCAN "Build OFDs' binaryeye scanner?" ON) + +if (NOT (BUILD_EMAIL_TO_TEXT_MODE OR BUILD_OCR_MODE OR BUILD_OFD_LOCAL_QR_SCAN OR BUILD_OFD_BINARYEYE_SCAN)) + message(FATAL_ERROR "You must specify at least one of the modes of data input!") + return() +endif() + +if (BUILD_EMAIL_TO_TEXT_MODE) + add_compile_definitions(BUILD_EMAIL_TO_TEXT_MODE) +endif() +if (BUILD_OCR_MODE) + add_compile_definitions(BUILD_OCR_MODE) +endif() +if (BUILD_OFD_LOCAL_QR_SCAN) + add_compile_definitions(BUILD_OFD_LOCAL_QR_SCAN) +endif() +if (BUILD_OFD_BINARYEYE_SCAN) + add_compile_definitions(BUILD_OFD_BINARYEYE_SCAN) +endif() include(FetchContent) @@ -18,15 +40,38 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt5Core REQUIRED) -find_package(Qt5 REQUIRED COMPONENTS LinguistTools) +if (BUILD_TRANSLATIONS) + find_package(Qt5 REQUIRED COMPONENTS LinguistTools) +endif() find_package(Qt5Gui REQUIRED) find_package(Qt5Widgets REQUIRED) find_package(Qt5UiTools REQUIRED) -set(PROJECT_SOURCES +set(TRANSLATION_SOURCES main.cpp - mainwindow.h mainwindow.cpp scenes/mainwindow.ui + mainwindow.cpp mainwindow.h scenes/mainwindow.ui + outputdialog.h outputdialog.cpp scenes/outputdialog.ui +) +if (BUILD_EMAIL_TO_TEXT_MODE) + list(APPEND TRANSLATION_SOURCES emailtextscene.cpp emailtextscene.h scenes/emailtextscene.ui) +endif() +if (BUILD_OCR_MODE) + list(APPEND TRANSLATION_SOURCES ocrscene.cpp ocrscene.h scenes/ocrscene.ui) +endif() +if (BUILD_OFD_LOCAL_QR_SCAN) + list(APPEND TRANSLATION_SOURCES adjustpicturedialog.h adjustpicturedialog.cpp scenes/adjustpicturedialog.ui) +endif() + +if (BUILD_OFD_LOCAL_QR_SCAN OR BUILD_OFD_BINARYEYE_SCAN) + list(APPEND TRANSLATION_SOURCES solvecaptchadialog.h solvecaptchadialog.cpp scenes/solvecaptchadialog.ui) + list(APPEND TRANSLATION_SOURCES ofdscene.cpp ofdscene.h scenes/ofdscene.ui) +endif() + +message(STATUS ${TRANSLATION_SOURCES}) + + +set(PROJECT_SOURCES goods/goods.h goods/goods.cpp check/check.h check/check.cpp parser/parser.h parser/parser.cpp @@ -35,37 +80,29 @@ set(PROJECT_SOURCES output/output_options.h output/output_options.cpp utils/utils.h utils/utils.cpp - image/checkimage.h image/checkimage.cpp + net/net.h net/net.cpp settings/settings.h settings/settings.cpp - exceptions/ofdrequestexception.h exceptions/ofdrequestexception.cpp - emailtextscene.h emailtextscene.cpp scenes/emailtextscene.ui - ocrscene.h ocrscene.cpp scenes/ocrscene.ui - ofdscene.h ofdscene.cpp scenes/ofdscene.ui - outputdialog.h outputdialog.cpp scenes/outputdialog.ui - adjustpicturedialog.h adjustpicturedialog.cpp scenes/adjustpicturedialog.ui - image_redactor/imageredactor.h image_redactor/imageredactor.cpp - solvecaptchadialog.h solvecaptchadialog.cpp scenes/solvecaptchadialog.ui + ${TRANSLATION_SOURCES} ) -set(TRANSLATION_SOURCES - main.cpp - mainwindow.cpp mainwindow.h scenes/mainwindow.ui - emailtextscene.cpp emailtextscene.h scenes/emailtextscene.ui - ocrscene.cpp ocrscene.h scenes/ocrscene.ui - ofdscene.cpp ofdscene.h scenes/ofdscene.ui - outputdialog.h outputdialog.cpp scenes/outputdialog.ui - adjustpicturedialog.h adjustpicturedialog.cpp scenes/adjustpicturedialog.ui - solvecaptchadialog.h solvecaptchadialog.cpp scenes/solvecaptchadialog.ui -) +if (BUILD_OCR_MODE) + list(APPEND PROJECT_SOURCES image/checkimage.h image/checkimage.cpp) + list(APPEND PROJECT_SOURCES image_redactor/imageredactor.h image_redactor/imageredactor.cpp) +endif() -set(TS_FILES - translations/en_US.ts - translations/ru_RU.ts -) +if (BUILD_OFD_BINARYEYE_SCAN OR BUILD_OFD_LOCAL_QR_SCAN) + list(APPEND PROJECT_SOURCES exceptions/ofdrequestexception.h exceptions/ofdrequestexception.cpp) +endif() if (BUILD_TRANSLATIONS) + + set(TS_FILES + translations/en_US.ts + translations/ru_RU.ts + ) + qt5_create_translation(QM_FILES "${TRANSLATION_SOURCES}" ${TS_FILES}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/translations.qrc ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc COPYONLY) qt5_add_resources(TRANSLATIONQRC ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc) @@ -109,7 +146,9 @@ endif() target_link_libraries(checks-parser PRIVATE Qt5::Widgets Qt5::UiTools) -target_include_directories(checks-parser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/image_redactor) +# if (BUILD_OFD_LOCAL_QR_SCAN) + target_include_directories(checks-parser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/image_redactor) +# endif() set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER org.foxarmy.checks-parser) @@ -133,29 +172,39 @@ if(WIN32) set(OpenCV_DIR /usr/local/lib/cmake/opencv4) endif() -FetchContent_Declare(httplib SYSTEM - GIT_REPOSITORY https://github.com/yhirose/cpp-httplib - GIT_TAG 787a34ad7f01f20922a237d5142aae469828be72 - GIT_SHALLOW TRUE) -FetchContent_MakeAvailable(httplib) +if (BUILD_OFD_BINARYEYE_SCAN) + find_package(PkgConfig) + pkg_check_modules(QRENCODE REQUIRED libqrencode) + include_directories(${QRENCODE_INCLUDE_DIRS}) + link_directories(${QRENCODE_LIBRARY_DIRS}) + target_link_libraries(checks-parser PRIVATE ${QRENCODE_LIBRARIES}) +endif() +if (BUILD_OFD_LOCAL_QR_SCAN) + target_link_libraries(checks-parser PRIVATE -lzbar) +endif() -find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs) +if (BUILD_OCR_MODE) + target_link_libraries(checks-parser PRIVATE -ltesseract) +endif() +if (BUILD_OFD_BINARYEYE_SCAN OR BUILD_OFD_LOCAL_QR_SCAN) + target_link_libraries(checks-parser PRIVATE -lcurl) +endif() -find_package(PkgConfig) -pkg_check_modules(QRENCODE REQUIRED libqrencode) -include_directories(${QRENCODE_INCLUDE_DIRS}) -link_directories(${QRENCODE_LIBRARY_DIRS}) -target_link_libraries(checks-parser PRIVATE ${QRENCODE_LIBRARIES}) - -include_directories( ${OpenCV_INCLUDE_DIRS} ) -target_include_directories(checks-parser PUBLIC ${OpenCV_INCLUDE_DIRS}) - -target_link_libraries(checks-parser PRIVATE -lzbar) -target_link_libraries(checks-parser PRIVATE -ltesseract) -target_link_libraries(checks-parser PRIVATE -lcurl) -target_link_libraries(checks-parser PRIVATE ${OpenCV_LIBS}) -target_link_libraries(checks-parser PRIVATE httplib) +if (BUILD_OCR_MODE OR BUILD_OFD_LOCAL_QR_SCAN OR BUILD_OFD_BINARYEYE_SCAN) + find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs) + target_link_libraries(checks-parser PRIVATE ${OpenCV_LIBS}) + target_include_directories(checks-parser PUBLIC ${OpenCV_INCLUDE_DIRS}) + include_directories( ${OpenCV_INCLUDE_DIRS} ) +endif() +if(BUILD_OFD_BINARYEYE_SCAN) + FetchContent_Declare(httplib SYSTEM + GIT_REPOSITORY https://github.com/yhirose/cpp-httplib + GIT_TAG 787a34ad7f01f20922a237d5142aae469828be72 + GIT_SHALLOW TRUE) + FetchContent_MakeAvailable(httplib) + target_link_libraries(checks-parser PRIVATE httplib) +endif() if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8) target_link_libraries(checks-parser PRIVATE -lstdc++fs) endif()