2024-11-22 21:50:55 +00:00
cmake_minimum_required ( VERSION 3.25 ) # Debian 11 Ubuntu 24.04 Fedora 36
2022-11-26 03:23:08 +00:00
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-05-27 04:12:16 +00:00
option ( WITH_ZIM "enable zim support" ON )
2024-07-12 09:25:52 +00:00
option ( WITH_TTS "enable QTexttoSpeech support" OFF )
2023-05-27 04:12:16 +00:00
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
2024-11-22 21:50:55 +00:00
## This should be avoided because of small regressions, as some scripts and icons themes assume the binary name and resources folder to be `goldendict`
option ( USE_ALTERNATIVE_NAME "For Linux, change the binary name and resource folder to goldendict-ng to parallel install with the original GD" OFF )
2024-07-11 07:05:10 +00:00
# vcpkg handling code, must be placed before project()
if ( WIN32 )
2024-11-22 21:50:55 +00:00
option ( WITH_VCPKG_BREAKPAD "build with Breakpad support for VCPKG build only" OFF )
2024-07-11 07:05:10 +00:00
if ( DEFINED CMAKE_TOOLCHAIN_FILE )
message ( STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}" )
else ( )
message ( STATUS "CMAKE_TOOLCHAIN_FILE is not set. Try fetching cached vcpkg." )
include ( FetchContent )
FetchContent_Declare (
v c p k g - e x p o r t
U R L h t t p s : / / g i t h u b . c o m / x i a o y i f a n g / g o l d e n d i c t - n g / r e l e a s e s / d o w n l o a d / v c p k g _ 2 4 0 7 1 1 _ 3 d 7 2 d 8 c 9 3 0 e 1 b 6 a 1 b 2 4 3 2 b 2 6 2 c 6 1 a f 7 d 3 2 8 7 d c d 0 / g o l d e n d i c t - n g - v c p k g - e x p o r t . t a r . z s t
U R L _ H A S H S H A 5 1 2 = C B 7 A B 2 0 F 0 3 C E 1 B B 1 D 4 6 F E 5 D F 2 5 C 9 B 9 F 4 E 3 6 5 B 7 2 C E 0 A 8 1 7 B 3 C 9 E 3 9 B D 0 C 8 5 D C 5 7 1 F 9 9 2 3 6 3 A 1 A 5 E 8 D D 1 E 3 1 C 4 4 F F 8 8 C 5 1 E 9 A 8 8 A 5 3 7 6 8 8 C 6 0 7 0 B 4 E 5 8 F F 8 F A 2 5 8 5 E A B 7
)
FetchContent_MakeAvailable ( vcpkg-export )
set ( VCPKG_MANIFEST_MODE OFF CACHE BOOL "disable existing manifest mode caused by the existrance of vcpkg.json" FORCE )
set ( CMAKE_TOOLCHAIN_FILE "${CMAKE_BINARY_DIR}/_deps/vcpkg-export-src/scripts/buildsystems/vcpkg.cmake" )
endif ( )
2024-11-22 21:50:55 +00:00
if ( WITH_VCPKG_BREAKPAD )
list ( APPEND VCPKG_MANIFEST_FEATURES "breakpad" )
endif ( )
2024-07-11 07:05:10 +00:00
endif ( )
2024-07-02 20:55:12 +00:00
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
2024-09-13 23:11:08 +00:00
V E R S I O N 2 4 . 1 1 . 0
2022-11-26 03:23:08 +00:00
L A N G U A G E S C X X C )
2024-11-22 21:50:55 +00:00
2024-10-09 01:42:54 +00:00
if ( APPLE )
enable_language ( OBJCXX )
set ( CMAKE_OBJCXX_STANDARD 17 )
endif ( )
set ( CMAKE_C_STANDARD 17 )
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
2022-11-26 03:23:08 +00:00
2024-05-03 20:14:27 +00:00
set ( GOLDENDICT "goldendict" ) # binary/executable name
2024-11-22 21:50:55 +00:00
if ( USE_ALTERNATIVE_NAME )
2023-08-05 04:50:00 +00:00
set ( GOLDENDICT "goldendict-ng" )
endif ( )
2024-05-05 07:45:19 +00:00
if ( APPLE )
2024-05-05 07:54:59 +00:00
set ( GOLDENDICT "GoldenDict-ng" )
2024-11-22 21:50:55 +00:00
endif ( )
2022-11-26 03:23:08 +00:00
2023-08-06 11:16:53 +00:00
#### Qt
2022-11-26 03:23:08 +00:00
2024-03-20 03:08:17 +00:00
set ( GD_QT_COMPONENTS Concurrent Core5Compat LinguistTools Multimedia PrintSupport WebEngineWidgets Widgets Svg Xml )
if ( WITH_TTS )
list ( APPEND GD_QT_COMPONENTS TextToSpeech )
endif ( )
find_package ( Qt6 REQUIRED COMPONENTS ${ GD_QT_COMPONENTS } )
2022-11-26 03:23:08 +00:00
2024-11-22 21:50:55 +00:00
qt_standard_project_setup ( )
2023-08-06 11:16:53 +00:00
set ( CMAKE_AUTORCC ON ) # not included in the qt_standard_project_setup
#### Things required during configuration
2023-07-30 05:21:14 +00:00
block ( ) # generate version.txt
2024-04-01 22:40:01 +00:00
string ( TIMESTAMP build_time UTC )
2023-07-30 05:21:14 +00:00
find_package ( Git )
if ( EXISTS "${CMAKE_SOURCE_DIR}/.git" AND GIT_FOUND )
execute_process (
C O M M A N D $ { G I T _ E X E C U T A B L E } - C " $ { C M A K E _ S O U R C E _ D I R } " r e v - p a r s e - - s h o r t H E A D
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
O U T P U T _ V A R I A B L E G I T _ H A S H )
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
2023-08-06 11:16:53 +00:00
if ( WIN32 )
# Binaries output dir for windows. The default ${CMAKE_BINARY_DIR} is too messy, use subfolder instead
# So that we can directly use windeployqt inside the output folder and obtain a redistributable GD
set ( GD_WIN_OUTPUT_DIR ${ CMAKE_BINARY_DIR } / ${ GOLDENDICT } )
endif ( )
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.
2024-07-15 01:23:23 +00:00
file ( GLOB_RECURSE ALL_SOURCE_FILES CONFIGURE_DEPENDS src/*.cc src/*.hh src/*.ui 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 )
2024-05-03 20:14:27 +00:00
set ( MACOS_APP_ICON ${ CMAKE_SOURCE_DIR } /icons/macicon.icns )
set_source_files_properties ( ${ MACOS_APP_ICON } PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" )
2022-11-26 03:23:08 +00:00
endif ( )
2023-08-06 11:16:53 +00:00
if ( WIN32 )
set ( WINDOWS_ICON_RC icons/programicon.rc )
endif ( )
2023-04-18 04:43:15 +00:00
set ( QSINGLEAPP_SOURCE_FILES
2022-11-26 03:23:08 +00:00
t h i r d p a r t y / q t s i n g l e a p p l i c a t i o n / s r c / q t l o c a l p e e r . c p p
t h i r d p a r t y / q t s i n g l e a p p l i c a t i o n / s r c / q t l o c a l p e e r . h
t h i r d p a r t y / q t s i n g l e a p p l i c a t i o n / s r c / q t s i n g l e a p p l i c a t i o n . c p p
t h i r d p a r t y / q t s i n g l e a p p l i c a t i o n / s r c / q t s i n g l e a p p l i c a t i o n . h
2023-08-06 11:16:53 +00:00
)
2022-11-26 03:23:08 +00:00
2023-08-06 11:16:53 +00:00
qt_add_executable ( ${ GOLDENDICT } )
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
i c o n s / f l a g s . q r c
r e s o u r c e s . q r c
s r c / s c r i p t s / s c r i p t s . q r c
s r c / s t y l e s h e e t s / c s s . q r c
$ { A L L _ S O U R C E _ F I L E S }
$ { M A C O S _ S O U R C E _ F I L E S }
2024-05-03 20:14:27 +00:00
$ { M A C O S _ A P P _ I C O N }
2023-08-06 11:16:53 +00:00
$ { Q S I N G L E A P P _ S O U R C E _ F I L E S }
$ { W I N D O W S _ I C O N _ R C }
)
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
Q t 6 : : X m l
Q t 6 : : C o n c u r r e n t
Q t 6 : : C o r e 5 C o m p a t
Q t 6 : : M u l t i m e d i a
2024-01-31 07:04:35 +00:00
Q t 6 : : P r i n t S u p p o r t
2022-11-26 03:23:08 +00:00
Q t 6 : : W e b E n g i n e W i d g e t s
Q t 6 : : W i d g e t s
Q t 6 : : S v g
2024-11-22 21:50:55 +00:00
$ < $ < B O O L : $ { W I T H _ T T S } > : Q t 6 : : T e x t T o S p e e c h >
)
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
$ { P R O J E C T _ S O U R C E _ D I R } / t h i r d p a r t y / q t s i n g l e a p p l i c a t i o n / s r c
$ { P R O J E C T _ S O U R C E _ D I R } / s r c /
$ { P R O J E C T _ S O U R C E _ D I R } / s r c / c o m m o n
$ { P R O J E C T _ S O U R C E _ D I R } / s r c / d i c t
2024-09-25 01:29:59 +00:00
$ { P R O J E C T _ S O U R C E _ D I R } / s r c / d i c t / u t i l s
2023-04-29 06:59:19 +00:00
$ { P R O J E C T _ S O U R C E _ D I R } / s r c / u i
2024-11-22 21:50:55 +00:00
)
2024-05-13 19:27:36 +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
2024-11-07 07:48:39 +00:00
# Disable deprecated staffs for Qt<=6.7 (Bump this if ever consider bump Qt version)
target_compile_definitions ( ${ GOLDENDICT } PRIVATE
Q T _ D I S A B L E _ D E P R E C A T E D _ U P _ T O = 0 x 0 6 0 7 0 0
Q T _ N O _ D E P R E C A T E D _ W A R N I N G S
)
2023-05-05 10:43:22 +00:00
target_compile_definitions ( ${ GOLDENDICT } PUBLIC
M A K E _ Q T M U L T I M E D I A _ P L A Y E R
M A K E _ C H I N E S E _ C O N V E R S I O N _ S U P P O R T
2024-11-22 21:50:55 +00:00
$ < $ < B O O L : $ { WIN32 } > : _ _ W I N 3 2 >
$ < $ < B O O L : $ { W I T H _ F F M P E G _ P L A Y E R } > : M A K E _ F F M P E G _ P L A Y E R >
$ < $ < B O O L : $ { W I T H _ T T S } > : T T S _ S U P P O R T >
$ < $ < B O O L : $ { W I T H _ E P W I N G _ S U P P O R T } > : E P W I N G _ S U P P O R T >
$ < $ < B O O L : $ { W I T H _ Z I M } > : M A K E _ Z I M _ S U P P O R T >
$ < $ < B O O L : $ { W I T H _ V C P K G _ B R E A K P A D } > : U S E _ B R E A K P A D >
)
2024-07-02 20:55:12 +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
2024-07-11 07:05:10 +00:00
if ( WIN32 )
2024-11-22 21:50:55 +00:00
include ( cmake/Deps_Vcpkg.cmake )
2023-05-05 10:43:22 +00:00
else ( )
2024-11-22 21:50:55 +00:00
include ( cmake/Deps_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
2022-11-26 03:23:08 +00:00
# include all *ts files under locale
file ( GLOB TRANS_FILES "locale/*.ts" )
2023-08-06 11:16:53 +00:00
if ( WIN32 )
# Put generated files to output dir's locale
set_source_files_properties ( ${ TRANS_FILES } PROPERTIES OUTPUT_LOCATION "${GD_WIN_OUTPUT_DIR}/locale" )
else ( )
set_source_files_properties ( ${ TRANS_FILES } PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/locale" )
endif ( )
2024-05-13 19:27:36 +00:00
2023-05-05 10:43:22 +00:00
qt_add_translations ( ${ GOLDENDICT } TS_FILES ${ TRANS_FILES }
2024-09-09 22:02:48 +00:00
Q M _ F I L E S _ O U T P U T _ V A R I A B L E q m _ f i l e s
L U P D A T E _ O P T I O N S " - n o - u i - l i n e s - l o c a t i o n s n o n e - n o - o b s o l e t e " )
2024-06-09 12:48:23 +00:00
add_dependencies ( ${ GOLDENDICT } "release_translations" )
2022-11-26 03:23:08 +00:00
2023-08-06 11:16:53 +00:00
#### installation or assemble redistribution
2023-05-05 10:43:22 +00:00
if ( APPLE )
2024-11-22 21:50:55 +00:00
include ( cmake/Package_macOS.cmake )
elseif ( LINUX OR BSD )
include ( cmake/Package_Linux.cmake )
elseif ( WIN32 )
include ( cmake/Package_Windows.cmake )
2023-08-06 11:16:53 +00:00
endif ( )
2023-04-18 04:43:15 +00:00
2023-05-17 23:56:17 +00:00
feature_summary ( WHAT ALL DESCRIPTION "Build configuration:" )