Skip to content

Commit

Permalink
feat: add using exported vcpkg option
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlebantongying committed Jul 10, 2024
1 parent 3e7780c commit e9d56d5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/PR-check-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ jobs:
New-Item -Path './build_dir' -ItemType Directory
cmake -S . -B "./build_dir" `
-G Ninja `
-DUSE_CACHED_VCPKG=ON `
-DWITH_VCPKG_BREAKPAD=ON `
-DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" `
-DWITH_FFMPEG_PLAYER=OFF
cmake --build "./build_dir"
1 change: 0 additions & 1 deletion .github/workflows/release-windows-vcpkg-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ jobs:
-DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" `
-DCMAKE_BUILD_TYPE=RelWithDebInfo `
-DWITH_FFMPEG_PLAYER=OFF `
-DUSE_VCPKG=ON `
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake" `
-DWITH_VCPKG_BREAKPAD=ON
cmake --build "./build_dir"
Expand Down
81 changes: 45 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ option(WITH_TTS "enable QTexttoSpeech support" ON)
option(USE_SYSTEM_FMT "use system fmt 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)
option(USE_CACHED_VCPKG "use a cached vcpkg with binaries prebuilt" OFF)
option(WITH_VCPKG_BREAKPAD "build with Breakpad support for VCPKG build only" OFF)

## Change binary & resources folder to parallel install with original GD.
Expand All @@ -22,9 +21,34 @@ 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

if(WITH_VCPKG_BREAKPAD)
list(APPEND VCPKG_MANIFEST_FEATURES "breakpad")
endif()

# vcpkg handling code, must be placed before project()

if (WIN32)
if (NOT USE_CACHED_VCPKG)
message(FATAL_ERROR "\
GoldenDict-ng uses vcpkg for windows build.
CMAKE_TOOLCHAIN_FILE needs to be set.
Google `CMAKE_TOOLCHAIN_FILE vcpkg` will show how.
`USE_CACHED_VCPKG` can be used to fetch a cached version with binaries prebuilt.
")
else ()
include(FetchContent)
FetchContent_Declare(
goldendict-ng-vcpkg-export-cache
GIT_REPOSITORY "https://github.com/shenlebantongying/goldendict-ng-vcpkg-export-cache.git"
GIT_TAG 1c0641ef5746feb4552df40b3c0d6be047f797e8
)
FetchContent_MakeAvailable(goldendict-ng-vcpkg-export-cache)
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/goldendict-ng-vcpkg-export-cache-src/exports/goldendict/scripts/buildsystems/vcpkg.cmake")
endif ()
endif ()


if (WITH_VCPKG_BREAKPAD)
list(APPEND VCPKG_MANIFEST_FEATURES "breakpad")
endif ()

include(FeatureSummary)

Expand Down Expand Up @@ -203,10 +227,8 @@ endif ()

#### libraries linking && includes for Win or Unix

if (USE_VCPKG)
if (WIN32)
include(Deps_Vcpkg)
elseif (WIN32)
include(Deps_Win)
else ()
include(Deps_Unix)
endif ()
Expand Down Expand Up @@ -313,36 +335,23 @@ if (WIN32)
LIBRARY_OUTPUT_DIRECTORY "${GD_WIN_OUTPUT_DIR}"
)

if (NOT USE_VCPKG)
add_custom_target(windeploy
COMMENT "Deploy everything to the output dir"
DEPENDS ${GOLDENDICT} # build this target will check if Goldendict.exe is already built
COMMAND ${WINDEPLOYQT_EXECUTABLE} --no-quick-import "${GD_WIN_OUTPUT_DIR}/${GOLDENDICT}.exe" --plugindir "${GD_WIN_OUTPUT_DIR}/plugins"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/opencc" "${GD_WIN_OUTPUT_DIR}/opencc"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/LICENSE.txt" "${GD_WIN_OUTPUT_DIR}/LICENSE.txt"
COMMAND ${CMAKE_COMMAND} -E rm -f "${GD_WIN_OUTPUT_DIR}/goldendict.exe.manifest" "${GD_WIN_OUTPUT_DIR}/eb.dll.manifest"
WORKING_DIRECTORY ${GD_WIN_OUTPUT_DIR}
)

else () # VCPKG deploy
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)
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)

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 .
)"
)
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 .
)"
)

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 ()
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 .)

# trick CPack to make the output folder as NSIS installer
install(DIRECTORY "${GD_WIN_OUTPUT_DIR}/"
Expand Down
50 changes: 0 additions & 50 deletions cmake/Deps_Win.cmake

This file was deleted.

0 comments on commit e9d56d5

Please sign in to comment.