2023-04-18 04:43:15 +00:00
|
|
|
cmake_minimum_required(VERSION 3.25) # ubuntu 23.04 Fedora 36
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
# Qt6.4+ only
|
|
|
|
|
|
|
|
option(WITH_FFMPEG_PLAYER "Enable support for FFMPEG player" ON)
|
2022-12-06 01:45:58 +00:00
|
|
|
option(WITH_EPWING_SUPPORT "Enable epwing support" ON)
|
2023-04-18 04:43:15 +00:00
|
|
|
option(WITH_XAPIAN "enable Xapian support" ON)
|
2023-05-27 04:12:16 +00:00
|
|
|
option(WITH_ZIM "enable zim support" ON)
|
|
|
|
|
2023-06-01 03:39:29 +00:00
|
|
|
# options for linux packaging
|
|
|
|
option(USE_SYSTEM_FMT "use system fmt instead of bundled one" OFF)
|
|
|
|
option(USE_SYSTEM_TOML "use system toml++ instead of bundled one" OFF)
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-08-05 04:50:00 +00:00
|
|
|
## Change binary & resources folder to parallel install with original GD.
|
|
|
|
## This flag should be avoided because it leads to small regressions:
|
|
|
|
## 1. There are personal scripts assuming the binary name to be "goldendict" -> require everyone to change the name in their script
|
|
|
|
## 2. There are icon themes that assuming the icon name to be "goldendict" -> invalidate the GD icon when using a icon theme
|
|
|
|
## 3. There are dictionary packages that install files to "/usr/share/goldendict/content" -> nullify the auto dict discovery
|
|
|
|
option(USE_ALTERNATIVE_NAME "Force the name goldendict-ng " OFF)
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
include(FeatureSummary)
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
project(goldendict-ng
|
2023-07-25 05:36:42 +00:00
|
|
|
VERSION 23.07.25
|
2022-11-26 03:23:08 +00:00
|
|
|
LANGUAGES CXX C)
|
|
|
|
|
2023-08-05 04:50:00 +00:00
|
|
|
if (NOT USE_ALTERNATIVE_NAME)
|
|
|
|
set(GOLDENDICT "goldendict") # binary/executable name
|
|
|
|
else ()
|
|
|
|
set(GOLDENDICT "goldendict-ng")
|
|
|
|
endif ()
|
2023-05-05 10:43:22 +00:00
|
|
|
|
2022-11-26 03:23:08 +00:00
|
|
|
set(CMAKE_AUTOUIC ON)
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
|
|
set(CMAKE_AUTORCC ON)
|
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
|
|
|
#### Importing Libraries
|
|
|
|
|
|
|
|
find_package(Qt6 REQUIRED COMPONENTS
|
|
|
|
Concurrent
|
|
|
|
Core5Compat
|
|
|
|
LinguistTools
|
|
|
|
Multimedia
|
|
|
|
WebEngineWidgets
|
|
|
|
Widgets
|
|
|
|
Svg
|
|
|
|
Xml
|
2022-07-31 01:19:50 +00:00
|
|
|
TextToSpeech
|
2022-11-26 03:23:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
#### Compile time files and preprocessor flags
|
|
|
|
|
2023-07-30 05:21:14 +00:00
|
|
|
block() # generate version.txt
|
|
|
|
string(TIMESTAMP build_time)
|
|
|
|
find_package(Git)
|
|
|
|
if (EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT_FOUND)
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${GIT_EXECUTABLE} -C "${CMAKE_SOURCE_DIR}" rev-parse --short HEAD
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
OUTPUT_VARIABLE GIT_HASH)
|
|
|
|
file(WRITE "${CMAKE_SOURCE_DIR}/version.txt" "${PROJECT_VERSION}.${GIT_HASH} at ${build_time}")
|
|
|
|
else () # not built in a git repo
|
|
|
|
file(WRITE "${CMAKE_SOURCE_DIR}/version.txt" "${PROJECT_VERSION} at ${build_time}")
|
|
|
|
endif ()
|
|
|
|
endblock()
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
#### Sources Files
|
|
|
|
|
2023-04-17 17:40:05 +00:00
|
|
|
# auto discovery of ui files https://cmake.org/cmake/help/v3.26/prop_tgt/AUTOUIC_SEARCH_PATHS.html
|
|
|
|
set(CMAKE_AUTOUIC_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/src/ui/")
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
# https://cmake.org/cmake/help/latest/command/file.html#filesystem
|
|
|
|
# ! Using GLOB_RECURSE is not recommended by cmake's documentation
|
|
|
|
# CONFIGURE_DEPENDS will trigger file tree recheck in every rebuilds.
|
|
|
|
file(GLOB_RECURSE ALL_SOURCE_FILES CONFIGURE_DEPENDS src/*.cc src/*.hh src/*.c)
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
if (APPLE)
|
2023-04-18 04:43:15 +00:00
|
|
|
file(GLOB_RECURSE MACOS_SOURCE_FILES CONFIGURE_DEPENDS src/macos/*.mm)
|
2022-11-26 03:23:08 +00:00
|
|
|
endif ()
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
set(QSINGLEAPP_SOURCE_FILES
|
2022-11-26 03:23:08 +00:00
|
|
|
thirdparty/qtsingleapplication/src/qtlocalpeer.cpp
|
|
|
|
thirdparty/qtsingleapplication/src/qtlocalpeer.h
|
|
|
|
thirdparty/qtsingleapplication/src/qtsingleapplication.cpp
|
|
|
|
thirdparty/qtsingleapplication/src/qtsingleapplication.h
|
2023-03-17 22:42:11 +00:00
|
|
|
)
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-08-06 02:28:01 +00:00
|
|
|
if(WIN32)
|
|
|
|
qt_add_executable(${GOLDENDICT} WIN32 MANUAL_FINALIZATION icons/programicon.rc)
|
|
|
|
else()
|
|
|
|
qt_add_executable(${GOLDENDICT} MANUAL_FINALIZATION)
|
|
|
|
endif()
|
2023-05-05 10:43:22 +00:00
|
|
|
|
2023-05-28 00:32:36 +00:00
|
|
|
target_sources(${GOLDENDICT} PRIVATE
|
2023-04-18 04:43:15 +00:00
|
|
|
icons/flags.qrc
|
|
|
|
resources.qrc
|
|
|
|
src/scripts/scripts.qrc
|
|
|
|
src/stylesheets/css.qrc
|
|
|
|
${ALL_SOURCE_FILES}
|
|
|
|
${MACOS_SOURCE_FILES}
|
|
|
|
${QSINGLEAPP_SOURCE_FILES})
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-06-01 03:39:29 +00:00
|
|
|
if (NOT USE_SYSTEM_FMT)
|
|
|
|
target_sources(${GOLDENDICT} PRIVATE thirdparty/fmt/format.cc)
|
|
|
|
endif ()
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
### Common parts amount all platforms
|
2022-12-14 10:00:15 +00:00
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
# Note: used as c++ string thus need surrounding " "
|
2023-04-18 04:43:15 +00:00
|
|
|
add_compile_definitions(PROGRAM_VERSION="${PROJECT_VERSION}")
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
target_link_libraries(${GOLDENDICT} PRIVATE
|
2022-11-26 03:23:08 +00:00
|
|
|
Qt6::Xml
|
|
|
|
Qt6::Concurrent
|
|
|
|
Qt6::Core5Compat
|
|
|
|
Qt6::Multimedia
|
|
|
|
Qt6::WebEngineWidgets
|
|
|
|
Qt6::Widgets
|
|
|
|
Qt6::Svg
|
2022-07-31 01:19:50 +00:00
|
|
|
Qt6::TextToSpeech
|
2022-11-26 03:23:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-28 00:32:36 +00:00
|
|
|
target_include_directories(${GOLDENDICT} PRIVATE
|
2023-04-18 04:43:15 +00:00
|
|
|
${PROJECT_SOURCE_DIR}/thirdparty/qtsingleapplication/src
|
|
|
|
${PROJECT_SOURCE_DIR}/src/
|
|
|
|
${PROJECT_SOURCE_DIR}/src/common
|
|
|
|
${PROJECT_SOURCE_DIR}/src/dict
|
2023-04-29 06:59:19 +00:00
|
|
|
${PROJECT_SOURCE_DIR}/src/ui
|
2023-05-05 10:43:22 +00:00
|
|
|
)
|
|
|
|
|
2023-06-01 03:39:29 +00:00
|
|
|
if (NOT USE_SYSTEM_TOML)
|
|
|
|
target_include_directories(${GOLDENDICT} PRIVATE ${PROJECT_SOURCE_DIR}/thirdparty/tomlplusplus)
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (NOT USE_SYSTEM_FMT)
|
|
|
|
target_include_directories(${GOLDENDICT} PRIVATE ${PROJECT_SOURCE_DIR}/thirdparty/fmt/include)
|
|
|
|
endif ()
|
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
#### Compile definitions
|
2023-04-18 04:43:15 +00:00
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
target_compile_definitions(${GOLDENDICT} PUBLIC
|
|
|
|
CMAKE_USED_HACK # temporal hack to avoid breaking qmake build
|
|
|
|
USE_ICONV
|
|
|
|
MAKE_QTMULTIMEDIA_PLAYER
|
|
|
|
MAKE_CHINESE_CONVERSION_SUPPORT
|
|
|
|
)
|
2023-04-18 04:43:15 +00:00
|
|
|
|
|
|
|
if (WITH_FFMPEG_PLAYER)
|
2023-05-05 10:43:22 +00:00
|
|
|
target_compile_definitions(${GOLDENDICT} PUBLIC MAKE_FFMPEG_PLAYER)
|
2023-04-18 04:43:15 +00:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
|
|
if (NOT WITH_EPWING_SUPPORT)
|
2023-05-05 10:43:22 +00:00
|
|
|
target_compile_definitions(${GOLDENDICT} PUBLIC NO_EPWING_SUPPORT)
|
2023-04-18 04:43:15 +00:00
|
|
|
endif ()
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
if (WITH_XAPIAN)
|
2023-05-05 10:43:22 +00:00
|
|
|
target_compile_definitions(${GOLDENDICT} PUBLIC USE_XAPIAN)
|
2022-11-26 03:23:08 +00:00
|
|
|
endif ()
|
|
|
|
|
2023-06-01 03:39:29 +00:00
|
|
|
if (WITH_ZIM)
|
|
|
|
target_compile_definitions(${GOLDENDICT} PUBLIC MAKE_ZIM_SUPPORT)
|
|
|
|
endif ()
|
2023-05-27 04:12:16 +00:00
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
#### libraries linking && includes for Win or Unix
|
2023-04-18 04:43:15 +00:00
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
if (WIN32)
|
|
|
|
include(CMake_Win.cmake)
|
|
|
|
else ()
|
|
|
|
include(CMake_Unix.cmake)
|
2023-04-18 04:43:15 +00:00
|
|
|
endif ()
|
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
#### add translations
|
2023-04-18 04:43:15 +00:00
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
install(TARGETS ${GOLDENDICT}
|
2022-11-26 03:23:08 +00:00
|
|
|
BUNDLE DESTINATION .
|
2023-05-05 10:43:22 +00:00
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/${GOLDENDICT})
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
# include all *ts files under locale
|
|
|
|
file(GLOB TRANS_FILES "locale/*.ts")
|
|
|
|
|
|
|
|
# Put generated files to output dir's locale
|
|
|
|
set_source_files_properties(${TRANS_FILES}
|
|
|
|
PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/locale")
|
|
|
|
|
|
|
|
# a wrapper over qt_add_lupdate and qt_add_lrelease
|
2023-05-05 10:43:22 +00:00
|
|
|
qt_add_translations(${GOLDENDICT} TS_FILES ${TRANS_FILES}
|
2022-11-26 03:23:08 +00:00
|
|
|
QM_FILES_OUTPUT_VARIABLE qm_files)
|
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
#### installation
|
|
|
|
|
|
|
|
if (APPLE)
|
|
|
|
set_target_properties(${GOLDENDICT} PROPERTIES
|
|
|
|
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
|
|
|
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
|
|
|
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
|
|
|
MACOSX_BUNDLE TRUE
|
|
|
|
)
|
|
|
|
endif ()
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
if (LINUX OR BSD)
|
2023-07-25 12:04:49 +00:00
|
|
|
install(FILES ${CMAKE_SOURCE_DIR}/redist/io.github.xiaoyifang.goldendict_ng.desktop DESTINATION share/applications)
|
|
|
|
install(FILES ${CMAKE_SOURCE_DIR}/redist/io.github.xiaoyifang.goldendict_ng.metainfo.xml DESTINATION share/metainfo)
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-08-05 04:50:00 +00:00
|
|
|
if (NOT USE_ALTERNATIVE_NAME)
|
|
|
|
# see: config.cc -> getProgramDataDir
|
|
|
|
add_compile_definitions(PROGRAM_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/goldendict")
|
|
|
|
install(FILES ${CMAKE_SOURCE_DIR}/redist/icons/goldendict.png DESTINATION share/pixmaps)
|
|
|
|
install(FILES ${qm_files} DESTINATION share/goldendict/locale)
|
|
|
|
else ()
|
|
|
|
add_compile_definitions(PROGRAM_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/goldendict-ng")
|
|
|
|
install(FILES ${CMAKE_SOURCE_DIR}/redist/icons/goldendict.png DESTINATION share/pixmaps
|
|
|
|
RENAME goldendict-ng.png)
|
|
|
|
install(FILES ${qm_files} DESTINATION share/goldendict-ng/locale)
|
|
|
|
|
|
|
|
block() # patch the desktop file to adapt the binary & icon file's name change
|
|
|
|
file(READ "${CMAKE_SOURCE_DIR}/redist/io.github.xiaoyifang.goldendict_ng.desktop" DESKTOP_FILE_CONTENT)
|
|
|
|
string(REGEX REPLACE "\nIcon=goldendict\n" "\nIcon=goldendict-ng\n" DESKTOP_FILE_CONTENT "${DESKTOP_FILE_CONTENT}")
|
|
|
|
string(REGEX REPLACE "\nExec=goldendict %u\n" "\nExec=goldendict-ng %u\n" DESKTOP_FILE_CONTENT "${DESKTOP_FILE_CONTENT}")
|
|
|
|
file(WRITE "${CMAKE_SOURCE_DIR}/redist/io.github.xiaoyifang.goldendict_ng.desktop" "${DESKTOP_FILE_CONTENT}")
|
|
|
|
endblock()
|
|
|
|
endif ()
|
2023-04-18 04:43:15 +00:00
|
|
|
endif ()
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-05-05 10:43:22 +00:00
|
|
|
qt_finalize_target(${GOLDENDICT})
|
2023-04-18 04:43:15 +00:00
|
|
|
|
2023-05-17 23:56:17 +00:00
|
|
|
feature_summary(WHAT ALL DESCRIPTION "Build configuration:")
|