Skip to content

Commit

Permalink
option/cmakelists: make building with mecab optional
Browse files Browse the repository at this point in the history
Add option MECAB_SUPPORT that allows Memento to be built without MeCab.
This will ON by default for now, but when #210 is merged, it will be OFF
by default.
  • Loading branch information
ripose-jp committed Apr 14, 2024
1 parent a7aec83 commit 11f246b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ list(
"$<$<BOOL:${APPIMAGE}>:-DAPPIMAGE=1>"
"$<$<BOOL:${APPBUNDLE}>:-DAPPBUNDLE=1>"
"$<$<BOOL:${OCR_SUPPORT}>:-DOCR_SUPPORT=1>"
"$<$<BOOL:${MECAB_SUPPORT}>:-DMECAB_SUPPORT=1>"
)

# Set Qt preprocessor settings
Expand Down Expand Up @@ -134,7 +135,9 @@ endif()
# Dependencies
find_package(JsonC REQUIRED)
find_package(libzip REQUIRED)
find_package(MeCab REQUIRED)
if(MECAB_SUPPORT)
find_package(MeCab REQUIRED)
endif()
find_package(mpv REQUIRED)
find_package(SQLite3 REQUIRED)
if (UNIX AND NOT APPLE)
Expand Down
4 changes: 3 additions & 1 deletion option/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ if(UNIX AND NOT APPLE)
option(APPIMAGE "Toggle when building for AppImages" OFF)
endif()
option(MAC_CROSSCOMPILE_X86 "Enables ARM machines to cross compile for x86" OFF)
option(RELEASE_BUILD "Toggle to build with release settings" OFF)

option(OCR_SUPPORT "Support for OCR through MangaOCR" OFF)
option(RELEASE_BUILD "Toggle to build with release settings" OFF)
option(MECAB_SUPPORT "Support for deconjugation with MeCab" ON)
45 changes: 29 additions & 16 deletions src/dict/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,26 @@ target_link_libraries(
PUBLIC querygenerator
)

add_library(
mecabquerygenerator STATIC
mecabquerygenerator.cpp
mecabquerygenerator.h
)
target_compile_features(mecabquerygenerator PRIVATE cxx_std_17)
target_compile_options(mecabquerygenerator PRIVATE ${MEMENTO_COMPILER_FLAGS})
target_include_directories(mecabquerygenerator PRIVATE ${MEMENTO_INCLUDE_DIRS})
target_link_libraries(
mecabquerygenerator
PRIVATE utils
PUBLIC MeCab::MeCab
PUBLIC querygenerator
)
if(MECAB_SUPPORT)
add_library(
mecabquerygenerator STATIC
mecabquerygenerator.cpp
mecabquerygenerator.h
)
target_compile_features(mecabquerygenerator PRIVATE cxx_std_17)
target_compile_options(
mecabquerygenerator PRIVATE ${MEMENTO_COMPILER_FLAGS}
)
target_include_directories(
mecabquerygenerator PRIVATE ${MEMENTO_INCLUDE_DIRS}
)
target_link_libraries(
mecabquerygenerator
PRIVATE utils
PUBLIC MeCab::MeCab
PUBLIC querygenerator
)
endif()

add_library(
yomidbbuilder STATIC
Expand Down Expand Up @@ -76,13 +82,20 @@ add_library(
target_compile_features(dictionary_db PUBLIC cxx_std_17)
target_compile_options(dictionary_db PRIVATE ${MEMENTO_COMPILER_FLAGS})
target_include_directories(dictionary_db PRIVATE ${MEMENTO_INCLUDE_DIRS})
set(
DICTIONARY_DB_GENERATOR_LIBS
exactquerygenerator
)
if(MECAB_SUPPORT)
list(APPEND DICTIONARY_DB_GENERATOR_LIBS mecabquerygenerator)
endif()
target_link_libraries(
dictionary_db
PRIVATE exactquerygenerator
PRIVATE mecabquerygenerator
PRIVATE ${DICTIONARY_DB_GENERATOR_LIBS}
PRIVATE Qt6::Widgets
PRIVATE querygenerator
PRIVATE SQLite::SQLite3
PRIVATE yomidbbuilder
PUBLIC Qt6::Core
)
unset(DICTIONARY_DB_GENERATOR_LIBS)
6 changes: 6 additions & 0 deletions src/dict/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@

#include "databasemanager.h"
#include "exactquerygenerator.h"

#ifdef MECAB_SUPPORT
#include "mecabquerygenerator.h"
#endif // MECAB_SUPPORT

#include "util/constants.h"
#include "util/globalmediator.h"
Expand Down Expand Up @@ -72,6 +75,8 @@ void Dictionary::initDictionaryOrder()
void Dictionary::initQueryGenerators()
{
m_generators.emplace_back(std::make_unique<ExactQueryGenerator>());

#ifdef MECAB_SUPPORT
m_generators.emplace_back(std::make_unique<MeCabQueryGenerator>());
if (!m_generators.back()->valid())
{
Expand Down Expand Up @@ -100,6 +105,7 @@ void Dictionary::initQueryGenerators()
#endif
);
}
#endif // MECAB_SUPPORT
}

Dictionary::~Dictionary()
Expand Down

0 comments on commit 11f246b

Please sign in to comment.