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
|
|
|
|
|
|
|
# Experimental Cmake build only supposed to be used by dev
|
|
|
|
# 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)
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
include(FeatureSummary)
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
project(goldendict
|
|
|
|
VERSION 22.11.20
|
|
|
|
LANGUAGES CXX C)
|
|
|
|
|
|
|
|
set(CMAKE_AUTOUIC ON)
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
|
|
set(CMAKE_AUTORCC ON)
|
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
if (APPLE)
|
|
|
|
if (WITH_EPWING_SUPPORT)
|
|
|
|
add_subdirectory(thirdparty/eb)
|
|
|
|
endif ()
|
|
|
|
include_directories(/usr/local/include /opt/homebrew/include)
|
|
|
|
endif ()
|
|
|
|
|
2022-11-26 03:23:08 +00:00
|
|
|
#### 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
|
|
|
)
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
|
2022-11-26 03:23:08 +00:00
|
|
|
if (APPLE)
|
|
|
|
find_library(CARBON_LIBRARY Carbon REQUIRED)
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (UNIX)
|
|
|
|
# Provided by Cmake
|
|
|
|
find_package(ZLIB REQUIRED)
|
|
|
|
find_package(BZip2 REQUIRED)
|
2023-04-18 04:43:15 +00:00
|
|
|
find_package(Iconv REQUIRED)
|
|
|
|
if (WITH_XAPIAN)
|
|
|
|
find_package(Xapian REQUIRED) # https://github.com/xapian/xapian/tree/master/xapian-core/cmake
|
|
|
|
endif ()
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
# PkgConfig only packages
|
2023-04-18 04:43:15 +00:00
|
|
|
find_package(PkgConfig REQUIRED)
|
|
|
|
pkg_check_modules(PKGCONFIG_DEPS IMPORTED_TARGET
|
2022-11-26 03:23:08 +00:00
|
|
|
hunspell
|
|
|
|
lzo2
|
|
|
|
opencc
|
|
|
|
vorbis # .ogg
|
|
|
|
vorbisfile
|
2022-11-29 05:37:24 +00:00
|
|
|
liblzma
|
|
|
|
libzstd
|
2022-11-26 03:23:08 +00:00
|
|
|
)
|
|
|
|
if (WITH_FFMPEG_PLAYER)
|
|
|
|
pkg_check_modules(FFMPEG REQUIRED IMPORTED_TARGET
|
|
|
|
libavcodec
|
|
|
|
libavformat
|
|
|
|
libavutil
|
|
|
|
libswresample
|
|
|
|
)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
if (LINUX)
|
2022-11-26 03:23:08 +00:00
|
|
|
find_package(X11 REQUIRED)
|
2023-04-18 04:43:15 +00:00
|
|
|
pkg_check_modules(LIBXTST IMPORTED_TARGET xtst)
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
if (WITH_EPWING_SUPPORT)
|
2022-12-06 01:45:58 +00:00
|
|
|
add_subdirectory(thirdparty/eb EXCLUDE_FROM_ALL)
|
2023-04-18 04:43:15 +00:00
|
|
|
endif ()
|
2022-12-06 01:45:58 +00:00
|
|
|
# add_library(libeb SHARED IMPORTED)
|
|
|
|
# set_target_properties(libeb PROPERTIES IMPORTED_LOCATION /usr/lib/libeb.so)
|
|
|
|
# set_target_properties(libeb PROPERTIES INCLUDE_DIRECTORIES /usr/include/)
|
2023-04-18 04:43:15 +00:00
|
|
|
endif ()
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
#### Compile time files and preprocessor flags
|
|
|
|
|
|
|
|
# Obtain git commit hash
|
|
|
|
execute_process(
|
|
|
|
COMMAND git rev-parse --short=8 HEAD
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
|
|
OUTPUT_VARIABLE GIT_HASH
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
|
|
|
string(TIMESTAMP date_for_version_file) # note: this variable is cached for every run, but for user installation, this doesn't matter much
|
|
|
|
configure_file(version.txt.in ${CMAKE_SOURCE_DIR}/version.txt)
|
|
|
|
|
|
|
|
#### 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
|
|
|
|
|
|
|
qt_add_executable(${CMAKE_PROJECT_NAME}
|
|
|
|
MANUAL_FINALIZATION
|
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-04-18 04:43:15 +00:00
|
|
|
### Common parts amount all platforms
|
2022-12-14 10:00:15 +00:00
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
# hack -> this string will be compared with another string, thus having surrounding " "
|
|
|
|
add_compile_definitions(PROGRAM_VERSION="${PROJECT_VERSION}")
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
|
|
|
|
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-04-18 04:43:15 +00:00
|
|
|
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC
|
|
|
|
CMAKE_USED_HACK # temporal hack to avoid breaking qmake build
|
|
|
|
USE_ICONV
|
|
|
|
MAKE_ZIM_SUPPORT
|
|
|
|
MAKE_QTMULTIMEDIA_PLAYER
|
|
|
|
MAKE_CHINESE_CONVERSION_SUPPORT)
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
|
|
|
|
${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
|
|
|
|
${PROJECT_SOURCE_DIR}/thirdparty/tomlplusplus
|
|
|
|
)
|
2023-04-18 04:43:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (WITH_FFMPEG_PLAYER)
|
|
|
|
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC MAKE_FFMPEG_PLAYER)
|
|
|
|
if (UNIX)
|
|
|
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE PkgConfig::FFMPEG)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
|
|
if (NOT WITH_EPWING_SUPPORT)
|
|
|
|
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC NO_EPWING_SUPPORT)
|
|
|
|
endif ()
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
if (WITH_XAPIAN)
|
|
|
|
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC USE_XAPIAN)
|
2022-11-26 03:23:08 +00:00
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
if (UNIX)
|
|
|
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${XAPIAN_LIBRARIES})
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
|
|
### Parts where different platforms disagree
|
|
|
|
|
|
|
|
if (LINUX)
|
|
|
|
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC HAVE_X11)
|
2022-12-06 01:45:58 +00:00
|
|
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE X11 PkgConfig::LIBXTST)
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
if (WITH_EPWING_SUPPORT)
|
|
|
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE eb)
|
|
|
|
endif ()
|
|
|
|
|
2022-11-26 03:23:08 +00:00
|
|
|
endif ()
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
if (MSVC)
|
|
|
|
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC
|
|
|
|
__WIN32
|
|
|
|
NO_EPWING_SUPPORT
|
|
|
|
INCLUDE_LIBRARY_PATH
|
|
|
|
)
|
|
|
|
|
|
|
|
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
|
|
|
|
${CMAKE_SOURCE_DIR}/winlibs/include/
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY
|
|
|
|
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
|
|
|
|
|
|
|
file(GLOB WINLIBS_FILES "${CMAKE_SOURCE_DIR}/winlibs/lib/msvc/*.lib")
|
|
|
|
foreach (A_WIN_LIB ${WINLIBS_FILES})
|
|
|
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${A_WIN_LIB})
|
|
|
|
endforeach ()
|
|
|
|
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
|
|
if (APPLE)
|
2022-11-26 03:23:08 +00:00
|
|
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${CARBON_LIBRARY})
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
if (WITH_EPWING_SUPPORT)
|
|
|
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE eb)
|
2022-11-26 03:23:08 +00:00
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
2023-04-18 04:43:15 +00:00
|
|
|
if (UNIX)
|
|
|
|
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
|
|
|
|
${PROJECT_SOURCE_DIR}/thirdparty)
|
|
|
|
|
|
|
|
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
|
|
|
|
# pkg-config packages need manually link
|
|
|
|
PkgConfig::PKGCONFIG_DEPS
|
|
|
|
BZip2::BZip2
|
|
|
|
ZLIB::ZLIB #hidden requirement of dsl_details.cc and more?
|
|
|
|
Iconv::Iconv
|
|
|
|
)
|
|
|
|
endif ()
|
|
|
|
|
2022-11-26 03:23:08 +00:00
|
|
|
set_target_properties(${CMAKE_PROJECT_NAME} 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
|
2023-04-20 01:03:31 +00:00
|
|
|
# WIN32_EXECUTABLE TRUE # TODO: this will prevent any qDebug() from showing up.
|
2022-11-26 03:23:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
install(TARGETS ${CMAKE_PROJECT_NAME}
|
|
|
|
BUNDLE DESTINATION .
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
|
|
|
|
# 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
|
|
|
|
qt_add_translations(${CMAKE_PROJECT_NAME} TS_FILES ${TRANS_FILES}
|
|
|
|
QM_FILES_OUTPUT_VARIABLE qm_files)
|
|
|
|
|
|
|
|
qt_finalize_target(${CMAKE_PROJECT_NAME})
|
|
|
|
|
|
|
|
if (LINUX)
|
|
|
|
install(FILES ${CMAKE_SOURCE_DIR}/redist/org.goldendict.GoldenDict.desktop DESTINATION share/applications)
|
|
|
|
install(FILES ${CMAKE_SOURCE_DIR}/redist/org.goldendict.GoldenDict.metainfo.xml DESTINATION share/metainfo)
|
|
|
|
|
|
|
|
install(FILES ${CMAKE_SOURCE_DIR}/redist/icons/goldendict.png DESTINATION share/pixmaps)
|
|
|
|
|
|
|
|
install(FILES ${qm_files} DESTINATION share/goldendict/locale)
|
2023-04-18 04:43:15 +00:00
|
|
|
endif ()
|
2022-11-26 03:23:08 +00:00
|
|
|
|
|
|
|
# Copy .dlls to output dir
|
2023-04-18 04:43:15 +00:00
|
|
|
if (MSVC)
|
2022-11-26 03:23:08 +00:00
|
|
|
file(GLOB DLL_FILES LIST_DIRECTORIES false "${CMAKE_SOURCE_DIR}/winlibs/lib/msvc/*.dll")
|
2023-04-18 04:43:15 +00:00
|
|
|
foreach (A_DLL_FILE ${DLL_FILES})
|
2022-11-26 03:23:08 +00:00
|
|
|
get_filename_component(TEMP_VAR_HOLDING_DLL_FILENAME ${A_DLL_FILE} NAME)
|
|
|
|
configure_file("${A_DLL_FILE}" "${CMAKE_BINARY_DIR}/${TEMP_VAR_HOLDING_DLL_FILENAME}" COPYONLY)
|
2023-04-18 04:43:15 +00:00
|
|
|
endforeach ()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
feature_summary(WHAT ALL DESCRIPTION "Build configuration:")
|