mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
feat: initial Vcpkg + CMake build for Windows. It don't need prebuilt binaries
This commit is contained in:
parent
e7c59679ce
commit
3856e1e8e8
|
@ -1,7 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.25) # ubuntu 23.04 Fedora 36
|
cmake_minimum_required(VERSION 3.25) # ubuntu 23.04 Fedora 36
|
||||||
|
|
||||||
# Qt6.4+ only
|
|
||||||
|
|
||||||
option(WITH_FFMPEG_PLAYER "Enable support for FFMPEG player" ON)
|
option(WITH_FFMPEG_PLAYER "Enable support for FFMPEG player" ON)
|
||||||
option(WITH_EPWING_SUPPORT "Enable epwing support" ON)
|
option(WITH_EPWING_SUPPORT "Enable epwing support" ON)
|
||||||
option(WITH_ZIM "enable zim support" ON)
|
option(WITH_ZIM "enable zim support" ON)
|
||||||
|
@ -11,6 +9,9 @@ option(WITH_TTS "enable QTexttoSpeech support" ON)
|
||||||
option(USE_SYSTEM_FMT "use system fmt instead of bundled one" OFF)
|
option(USE_SYSTEM_FMT "use system fmt instead of bundled one" OFF)
|
||||||
option(USE_SYSTEM_TOML "use system toml++ instead of bundled one" OFF)
|
option(USE_SYSTEM_TOML "use system toml++ instead of bundled one" OFF)
|
||||||
|
|
||||||
|
# vcpkg build - only tested on Windows, does not support FFMPEG
|
||||||
|
option(USE_VCPKG "uses VCPKG for providing dependencies" OFF)
|
||||||
|
|
||||||
## Change binary & resources folder to parallel install with original GD.
|
## Change binary & resources folder to parallel install with original GD.
|
||||||
## This flag should be avoided because it leads to small regressions:
|
## 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
|
## 1. There are personal scripts assuming the binary name to be "goldendict" -> require everyone to change the name in their script
|
||||||
|
@ -18,6 +19,8 @@ option(USE_SYSTEM_TOML "use system toml++ instead of bundled one" OFF)
|
||||||
## 3. There are dictionary packages that install files to "/usr/share/goldendict/content" -> nullify the auto dict discovery
|
## 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)
|
option(USE_ALTERNATIVE_NAME "Force the name goldendict-ng " OFF)
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") # to put staff in the ./cmake folder
|
||||||
|
|
||||||
include(FeatureSummary)
|
include(FeatureSummary)
|
||||||
|
|
||||||
project(goldendict-ng
|
project(goldendict-ng
|
||||||
|
@ -144,6 +147,10 @@ target_include_directories(${GOLDENDICT} PRIVATE
|
||||||
${PROJECT_SOURCE_DIR}/src/ui
|
${PROJECT_SOURCE_DIR}/src/ui
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
target_include_directories(${GOLDENDICT} PRIVATE ${PROJECT_SOURCE_DIR}/src/windows)
|
||||||
|
endif ()
|
||||||
|
|
||||||
if (NOT USE_SYSTEM_TOML)
|
if (NOT USE_SYSTEM_TOML)
|
||||||
target_include_directories(${GOLDENDICT} PRIVATE ${PROJECT_SOURCE_DIR}/thirdparty/tomlplusplus)
|
target_include_directories(${GOLDENDICT} PRIVATE ${PROJECT_SOURCE_DIR}/thirdparty/tomlplusplus)
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -161,6 +168,13 @@ target_compile_definitions(${GOLDENDICT} PUBLIC
|
||||||
MAKE_CHINESE_CONVERSION_SUPPORT
|
MAKE_CHINESE_CONVERSION_SUPPORT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
target_compile_definitions(${GOLDENDICT} PUBLIC
|
||||||
|
__WIN32
|
||||||
|
INCLUDE_LIBRARY_PATH
|
||||||
|
)
|
||||||
|
endif ()
|
||||||
|
|
||||||
if (WITH_FFMPEG_PLAYER)
|
if (WITH_FFMPEG_PLAYER)
|
||||||
target_compile_definitions(${GOLDENDICT} PUBLIC MAKE_FFMPEG_PLAYER)
|
target_compile_definitions(${GOLDENDICT} PUBLIC MAKE_FFMPEG_PLAYER)
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -180,10 +194,12 @@ endif ()
|
||||||
|
|
||||||
#### libraries linking && includes for Win or Unix
|
#### libraries linking && includes for Win or Unix
|
||||||
|
|
||||||
if (WIN32)
|
if (USE_VCPKG)
|
||||||
include(CMake_Win.cmake)
|
include(Deps_Vcpkg)
|
||||||
|
elseif (WIN32)
|
||||||
|
include(Deps_Win)
|
||||||
else ()
|
else ()
|
||||||
include(CMake_Unix.cmake)
|
include(Deps_Unix)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
#### add translations
|
#### add translations
|
||||||
|
@ -197,9 +213,12 @@ if (WIN32)
|
||||||
else ()
|
else ()
|
||||||
set_source_files_properties(${TRANS_FILES} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/locale")
|
set_source_files_properties(${TRANS_FILES} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/locale")
|
||||||
endif ()
|
endif ()
|
||||||
# a wrapper over qt_add_lupdate and qt_add_lrelease
|
|
||||||
qt_add_translations(${GOLDENDICT} TS_FILES ${TRANS_FILES}
|
qt_add_translations(${GOLDENDICT} TS_FILES ${TRANS_FILES}
|
||||||
QM_FILES_OUTPUT_VARIABLE qm_files)
|
QM_FILES_OUTPUT_VARIABLE qm_files)
|
||||||
|
if (WIN32) # TODO: check other OS
|
||||||
|
add_dependencies(${GOLDENDICT} "goldendict-ng_lrelease")
|
||||||
|
endif ()
|
||||||
|
|
||||||
#### installation or assemble redistribution
|
#### installation or assemble redistribution
|
||||||
|
|
||||||
|
@ -279,6 +298,7 @@ if (LINUX OR BSD)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|
||||||
set_target_properties(${GOLDENDICT}
|
set_target_properties(${GOLDENDICT}
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
WIN32_EXECUTABLE TRUE
|
WIN32_EXECUTABLE TRUE
|
||||||
|
@ -286,6 +306,7 @@ if (WIN32)
|
||||||
LIBRARY_OUTPUT_DIRECTORY "${GD_WIN_OUTPUT_DIR}"
|
LIBRARY_OUTPUT_DIRECTORY "${GD_WIN_OUTPUT_DIR}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (NOT USE_VCPKG)
|
||||||
add_custom_target(windeploy
|
add_custom_target(windeploy
|
||||||
COMMENT "Deploy everything to the output dir"
|
COMMENT "Deploy everything to the output dir"
|
||||||
DEPENDS ${GOLDENDICT} # build this target will check if Goldendict.exe is already built
|
DEPENDS ${GOLDENDICT} # build this target will check if Goldendict.exe is already built
|
||||||
|
@ -296,17 +317,41 @@ if (WIN32)
|
||||||
WORKING_DIRECTORY ${GD_WIN_OUTPUT_DIR}
|
WORKING_DIRECTORY ${GD_WIN_OUTPUT_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
# use CPack to make the output folder as NSIS installer
|
else () # VCPKG deploy
|
||||||
install(
|
set(CMAKE_INSTALL_PREFIX "${GD_WIN_OUTPUT_DIR}" CACHE PATH "If you see this message, don't change this unless you want look into CMake build script. If you are an expert, yes, this is wrong. Help welcomed." FORCE)
|
||||||
DIRECTORY "${GD_WIN_OUTPUT_DIR}/"
|
|
||||||
DESTINATION .
|
qt_generate_deploy_script(
|
||||||
|
TARGET ${GOLDENDICT}
|
||||||
|
OUTPUT_SCRIPT deploy_script
|
||||||
|
CONTENT "qt_deploy_runtime_dependencies(
|
||||||
|
EXECUTABLE \"${CMAKE_INSTALL_PREFIX}/goldendict.exe\"
|
||||||
|
BIN_DIR .
|
||||||
|
LIB_DIR .
|
||||||
|
)"
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CPACK_PACKAGE_FILE_NAME "${Qt6Widgets_VERSION}-${PROJECT_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
|
install(SCRIPT ${deploy_script})
|
||||||
|
install(DIRECTORY "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/share/opencc" DESTINATION .)
|
||||||
|
# TODO: do we really need to carry a copy of openSSL?
|
||||||
|
install(FILES "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin/libssl-3-x64.dll" DESTINATION .)
|
||||||
|
install(FILES "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin/libcrypto-3-x64.dll" DESTINATION .)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# trick CPack to make the output folder as NSIS installer
|
||||||
|
install(DIRECTORY "${GD_WIN_OUTPUT_DIR}/"
|
||||||
|
DESTINATION .
|
||||||
|
FILES_MATCHING
|
||||||
|
PATTERN "*"
|
||||||
|
PATTERN "*.pdb" EXCLUDE
|
||||||
|
PATTERN "*.ilk" EXCLUDE)
|
||||||
|
|
||||||
|
|
||||||
|
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-Qt${Qt6Widgets_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
set(CPACK_GENERATOR "7Z;NSIS")
|
set(CPACK_GENERATOR "7Z;NSIS")
|
||||||
set(CPACK_NSIS_MANIFEST_DPI_AWARE ON)
|
set(CPACK_NSIS_MANIFEST_DPI_AWARE ON)
|
||||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
|
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
|
||||||
include(CPack)
|
include(CPack)
|
||||||
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
feature_summary(WHAT ALL DESCRIPTION "Build configuration:")
|
feature_summary(WHAT ALL DESCRIPTION "Build configuration:")
|
||||||
|
|
35
cmake/Deps_Vcpkg.cmake
Normal file
35
cmake/Deps_Vcpkg.cmake
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
find_package(BZip2 REQUIRED)
|
||||||
|
find_package(Iconv REQUIRED)
|
||||||
|
find_package(LibLZMA REQUIRED)
|
||||||
|
find_package(Vorbis CONFIG REQUIRED)
|
||||||
|
find_package(ZLIB REQUIRED)
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(PKGCONFIG_DEPS IMPORTED_TARGET
|
||||||
|
hunspell
|
||||||
|
libzim
|
||||||
|
lzo2
|
||||||
|
opencc
|
||||||
|
xapian-core
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${GOLDENDICT}
|
||||||
|
PRIVATE
|
||||||
|
PkgConfig::PKGCONFIG_DEPS
|
||||||
|
BZip2::BZip2
|
||||||
|
Iconv::Iconv
|
||||||
|
LibLZMA::LibLZMA
|
||||||
|
Vorbis::vorbis
|
||||||
|
Vorbis::vorbisfile
|
||||||
|
ZLIB::ZLIB
|
||||||
|
)
|
||||||
|
|
||||||
|
if (WITH_EPWING_SUPPORT)
|
||||||
|
add_subdirectory(thirdparty/eb EXCLUDE_FROM_ALL)
|
||||||
|
target_include_directories(${GOLDENDICT} PRIVATE
|
||||||
|
thirdparty
|
||||||
|
)
|
||||||
|
target_link_libraries(${GOLDENDICT} PRIVATE eb)
|
||||||
|
|
||||||
|
set_target_properties(eb PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${GD_WIN_OUTPUT_DIR})
|
||||||
|
endif ()
|
|
@ -1,8 +1,3 @@
|
||||||
target_compile_definitions(${GOLDENDICT} PUBLIC
|
|
||||||
__WIN32
|
|
||||||
INCLUDE_LIBRARY_PATH # temporal hack to let singleapplication compile
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(${GOLDENDICT} PUBLIC
|
target_include_directories(${GOLDENDICT} PUBLIC
|
||||||
${CMAKE_SOURCE_DIR}/winlibs/include/
|
${CMAKE_SOURCE_DIR}/winlibs/include/
|
||||||
)
|
)
|
|
@ -166,7 +166,7 @@ win32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
RC_ICONS += icons/programicon.ico icons/programicon_old.ico
|
RC_ICONS += icons/programicon.ico icons/programicon_old.ico
|
||||||
INCLUDEPATH += winlibs/include
|
INCLUDEPATH += winlibs/include src/windows
|
||||||
|
|
||||||
# Enable console in Debug mode on Windows, with useful logging messages
|
# Enable console in Debug mode on Windows, with useful logging messages
|
||||||
Debug:CONFIG += console
|
Debug:CONFIG += console
|
||||||
|
|
14
vcpkg-configuration.json
Normal file
14
vcpkg-configuration.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"default-registry": {
|
||||||
|
"kind": "git",
|
||||||
|
"baseline": "a1212c93cabaa9c5c36c1ffdb4bddd59fdf31e43",
|
||||||
|
"repository": "https://github.com/microsoft/vcpkg"
|
||||||
|
},
|
||||||
|
"registries": [
|
||||||
|
{
|
||||||
|
"kind": "artifact",
|
||||||
|
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
|
||||||
|
"name": "microsoft"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
17
vcpkg.json
Normal file
17
vcpkg.json
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"name": "goldendict-ng",
|
||||||
|
"version": "24.5.5",
|
||||||
|
"dependencies": [
|
||||||
|
"bzip2",
|
||||||
|
"hunspell",
|
||||||
|
"libiconv",
|
||||||
|
"liblzma",
|
||||||
|
"libvorbis",
|
||||||
|
"libzim",
|
||||||
|
"lzo",
|
||||||
|
"opencc",
|
||||||
|
"xapian",
|
||||||
|
"zlib",
|
||||||
|
"openssl"
|
||||||
|
]
|
||||||
|
}
|
|
@ -64,21 +64,36 @@ Install Qt6(msvc) through the standard installer and pass Qt's path to CMake
|
||||||
```
|
```
|
||||||
-DCMAKE_PREFIX_PATH=F:\Qt\6.4.1\msvc2019_64
|
-DCMAKE_PREFIX_PATH=F:\Qt\6.4.1\msvc2019_64
|
||||||
```
|
```
|
||||||
|
|
||||||
The built artifacts will end up in `build_dir/goldendict`
|
The built artifacts will end up in `build_dir/goldendict`
|
||||||
|
|
||||||
To run the built `goldendict.exe` directly, you have to add `F:\Qt\6.5.2\msvc2019_64\bin` to your PATH environment variable
|
#### Using pre-built winlibs
|
||||||
|
|
||||||
To have a redistributable goldendict (runable on someone else's computer by just copying the folder), you can build the deployment target which will copy necessary files to the folder
|
Use `windeploy` target to copy necessary runtime files.
|
||||||
|
|
||||||
```
|
```
|
||||||
cmake --build . --target windeploy
|
cmake --build . --target windeploy
|
||||||
```
|
```
|
||||||
|
|
||||||
The `build_dir/goldendict` will be ready to share with others.
|
Or you can also manually run `windeployqt.exe {your_build_dir}/goldendict.exe` which will copy the qt related things to `build_dir`.
|
||||||
|
|
||||||
Use`windeployqt.exe {your_build_dir}/goldendict.exe` which will copy the qt related `.dll` and other necessary files automatically.
|
#### Using Vcpkg
|
||||||
|
|
||||||
|
The dependencies can be built via Vcpkg instead of using the pre-built ones.
|
||||||
|
|
||||||
|
Vcpkg CMake build utilize the "manifest mode", all you need to do is basically
|
||||||
|
set `CMAKE_TOOLCHAIN_FILE` as described [here](https://learn.microsoft.com/en-us/vcpkg/consume/manifest-mode?tabs=cmake%2Cbuild-MSBuild#2---integrate-vcpkg-with-your-build-system).
|
||||||
|
|
||||||
|
Add this to cmake command:
|
||||||
|
```sh
|
||||||
|
-DUSE_VCPKG=ON
|
||||||
|
```
|
||||||
|
|
||||||
|
Most `.dll` built by vcpkg will be automatically copied, but the Qt ones won't.
|
||||||
|
|
||||||
|
You can
|
||||||
|
* run `cmake --install .` (recommended)
|
||||||
|
* manually run windeployqt
|
||||||
|
* add `${Qt's install path}\Qt\6.5.2\msvc2019_64\bin` to your PATH environment variable
|
||||||
|
|
||||||
### macOS
|
### macOS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue