From 89b9d91938c47a7d73c1ec70f08d45ab8014179e Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Fri, 17 Feb 2017 21:34:07 -0500 Subject: [PATCH] cmake: Introduce CMake-based build option Fixes #689. --- .gitignore | 12 ++--- CMakeLists.txt | 28 ++++++++++ assets/CMakeLists.txt | 17 ++++++ cmake/FindSQLite.cmake | 38 +++++++++++++ cmake/MacOSXBundleInfo.plist.in | 36 +++++++++++++ src/CMakeLists.txt | 31 +++++++++++ src/app/CMakeLists.txt | 45 ++++++++++++++++ src/app/versioninfo.rc.in | 56 ++++++++++++++++++++ src/libs/CMakeLists.txt | 4 ++ src/libs/core/CMakeLists.txt | 16 ++++++ src/libs/registry/CMakeLists.txt | 13 +++++ src/libs/ui/CMakeLists.txt | 25 +++++++++ src/libs/ui/qxtglobalshortcut/CMakeLists.txt | 41 ++++++++++++++ src/libs/util/CMakeLists.txt | 18 +++++++ 14 files changed, 374 insertions(+), 6 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 assets/CMakeLists.txt create mode 100644 cmake/FindSQLite.cmake create mode 100644 cmake/MacOSXBundleInfo.plist.in create mode 100644 src/CMakeLists.txt create mode 100644 src/app/CMakeLists.txt create mode 100644 src/app/versioninfo.rc.in create mode 100644 src/libs/CMakeLists.txt create mode 100644 src/libs/core/CMakeLists.txt create mode 100644 src/libs/registry/CMakeLists.txt create mode 100644 src/libs/ui/CMakeLists.txt create mode 100644 src/libs/ui/qxtglobalshortcut/CMakeLists.txt create mode 100644 src/libs/util/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 965f90d..6057690 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # C++ objects and libs - *.slo *.lo *.o @@ -10,8 +9,7 @@ *.dll *.dylib -# Qt-es - +# qmake /.qmake.cache /.qmake.stash *.pro.user @@ -23,10 +21,12 @@ ui_*.h Makefile* *-build-* -# QtCreator - +# Qt Creator *.autosave -#QtCtreator Qml +# Qt Ctreator QML *.qmlproject.user *.qmlproject.user.* + +# CMake +CMakeLists.txt.user diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4b09cd7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.5.1) +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") + +project(Zeal VERSION 0.3.1) + +# Project information. +if(APPLE) + set(PROJECT_OUTPUT_NAME "Zeal") +else() + set(PROJECT_OUTPUT_NAME "zeal") +endif() + +set(PROJECT_COMPANY_NAME "ZealDocs") + +# CMake <= 3.8.0 doesn't support Unicode on Windows: +# https://gitlab.kitware.com/cmake/cmake/commit/335a29cb07a8d014a9ed4d4dbf25e49da3a78b33 +# Comparing with 3.8.1 to catch 3.8.0-rc1: https://gitlab.kitware.com/cmake/cmake/issues/16656 +if(WIN32 AND CMAKE_VERSION VERSION_LESS 3.8.1) + string(TIMESTAMP PROJECT_COPYRIGHT "(C) 2015-%Y Oleg Shparber" UTC) +else() + string(TIMESTAMP PROJECT_COPYRIGHT "© 2015-%Y Oleg Shparber" UTC) +endif() + +set(PROJECT_DESCRIPTION "A simple documentation browser.") +set(PROJECT_URL "https://zealdocs.org") + +add_subdirectory(assets) +add_subdirectory(src) diff --git a/assets/CMakeLists.txt b/assets/CMakeLists.txt new file mode 100644 index 0000000..24790bb --- /dev/null +++ b/assets/CMakeLists.txt @@ -0,0 +1,17 @@ +if(UNIX AND NOT APPLE) + find_package(ECM REQUIRED NO_MODULE) + set(CMAKE_MODULE_PATH ${ECM_KDE_MODULE_DIR}) + include(KDEInstallDirs) + + foreach(_i 16 24 32 64 128) + install(FILES "freedesktop/appicons/${_i}/zeal.png" + DESTINATION "${KDE_INSTALL_ICONDIR}/hicolor/${_i}x${_i}/apps" + # TODO: Use `RENAME zeal.png` and get rid of subdirectories. + ) + endforeach() + + # TODO: Generate via zeal.desktop.in. + install(FILES "freedesktop/zeal.desktop" + DESTINATION ${KDE_INSTALL_APPDIR} + ) +endif() diff --git a/cmake/FindSQLite.cmake b/cmake/FindSQLite.cmake new file mode 100644 index 0000000..b781ce6 --- /dev/null +++ b/cmake/FindSQLite.cmake @@ -0,0 +1,38 @@ +# FindSQLite +# ---------- +# +# Finds SQLite headers and libraries. +# +# SQLite_FOUND - True if SQLite is found. +# SQLite_INCLUDE_DIR - Path to SQLite header files. +# SQLite_LIBRARY - SQLite library to link to. +# SQLite_VERSION_STRING - The version of SQLite found. + +# A simple fallback to pkg-config. +if(NOT WIN32) + find_package(PkgConfig QUIET) + pkg_search_module(PC_SQLITE QUIET sqlite3) +endif() + +find_path(SQLite_INCLUDE_DIR NAMES sqlite3.h + PATHS + ${PC_SQLITE_INCLUDEDIR} + ${PC_SQLITE_INCLUDE_DIRS} +) + +find_library(SQLite_LIBRARY NAMES sqlite3 + PATHS + ${PC_SQLITE_LIBDIR} + ${PC_SQLITE_LIBRARY_DIRS} +) + +# TODO: Set version when library is found not via pkg-config. +set(SQLite_VERSION_STRING ${PC_SQLITE_VERSION}) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLite + REQUIRED_VARS SQLite_LIBRARY SQLite_INCLUDE_DIR + VERSION_VAR SQLite_VERSION_STRING +) + +mark_as_advanced(SQLite_INCLUDE_DIR SQLite_LIBRARY) diff --git a/cmake/MacOSXBundleInfo.plist.in b/cmake/MacOSXBundleInfo.plist.in new file mode 100644 index 0000000..7cab291 --- /dev/null +++ b/cmake/MacOSXBundleInfo.plist.in @@ -0,0 +1,36 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${MACOSX_BUNDLE_EXECUTABLE_NAME} + CFBundleIconFile + ${MACOSX_BUNDLE_ICON_FILE} + CFBundleIdentifier + ${MACOSX_BUNDLE_GUI_IDENTIFIER} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleLongVersionString + ${MACOSX_BUNDLE_LONG_VERSION_STRING} + CFBundleName + ${MACOSX_BUNDLE_BUNDLE_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + ${MACOSX_BUNDLE_SHORT_VERSION_STRING} + CFBundleSignature + ???? + CFBundleVersion + ${MACOSX_BUNDLE_BUNDLE_VERSION} + CSResourcesFileMapped + + NSHumanReadableCopyright + ${MACOSX_BUNDLE_COPYRIGHT} + NSPrincipalClass + NSApplication + NSHighResolutionCapable + + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..59be454 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,31 @@ +# Only C++11 +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Find includes in corresponding build directories. +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +## Build options +option(ZEAL_PORTABLE_BUILD "Build portable version") +if(ZEAL_PORTABLE_BUILD) + add_definitions(-DPORTABLE_BUILD) +endif() + +## Macro +add_definitions(-DZEAL_VERSION="${Zeal_VERSION}") + +# QString options +add_definitions(-DQT_USE_QSTRINGBUILDER) +add_definitions(-DQT_RESTRICTED_CAST_FROM_ASCII) +add_definitions(-DQT_NO_CAST_TO_ASCII) +add_definitions(-DQT_NO_URL_CAST_FROM_STRING) + +## Handle moc, uic, and rcc files. +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) + +include_directories(libs) +add_subdirectory(libs) + +add_subdirectory(app) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt new file mode 100644 index 0000000..8a4f49e --- /dev/null +++ b/src/app/CMakeLists.txt @@ -0,0 +1,45 @@ +# TODO: Move zeal.qrc one level up to rely on CMAKE_AUTORCC. +find_package(Qt5Core REQUIRED) +qt5_add_resources(App_RESOURCES resources/zeal.qrc) + +if(APPLE) + list(APPEND App_RESOURCES resources/zeal.icns) +elseif(WIN32) + configure_file(versioninfo.rc.in ${CMAKE_CURRENT_BINARY_DIR}/versioninfo.rc) + list(APPEND App_RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/versioninfo.rc) +endif() + +add_executable(App + main.cpp + ${App_RESOURCES} +) + +target_link_libraries(App Core Util) + +find_package(Qt5 COMPONENTS Concurrent Widgets REQUIRED) +target_link_libraries(App Qt5::Concurrent Qt5::Widgets) + +set_target_properties(App PROPERTIES + OUTPUT_NAME ${PROJECT_OUTPUT_NAME} + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" +) + +if(APPLE) + set_target_properties(App PROPERTIES + MACOSX_BUNDLE TRUE + MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME} + MACOSX_BUNDLE_GUI_IDENTIFIER "org.zealdocs.zeal" + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_LONG_VERSION_STRING ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" + MACOSX_BUNDLE_ICON_FILE "zeal.icns" + MACOSX_BUNDLE_COPYRIGHT ${PROJECT_COPYRIGHT} + RESOURCE "resources/zeal.icns" + ) +elseif(UNIX) + find_package(ECM REQUIRED NO_MODULE) + set(CMAKE_MODULE_PATH ${ECM_KDE_MODULE_DIR}) + include(KDEInstallDirs) + + install(TARGETS App DESTINATION ${KDE_INSTALL_BINDIR}) +endif() diff --git a/src/app/versioninfo.rc.in b/src/app/versioninfo.rc.in new file mode 100644 index 0000000..03f89eb --- /dev/null +++ b/src/app/versioninfo.rc.in @@ -0,0 +1,56 @@ +#include + +IDI_ICON1 ICON DISCARDABLE "resources/zeal.ico" + +#define VER_COMPANYNAME_STR "${PROJECT_COMPANY_NAME}" +#define VER_FILEDESCRIPTION_STR "${PROJECT_DESCRIPTION}" +#define VER_FILEVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH} +#define VER_FILEVERSION_STR "${PROJECT_VERSION}" +#define VER_INTERNALNAME_STR "${PROJECT_NAME}" +#define VER_LEGALCOPYRIGHT_STR "${PROJECT_COPYRIGHT}" +#define VER_LEGALTRADEMARKS1_STR "" +#define VER_LEGALTRADEMARKS2_STR "" +#define VER_ORIGINALFILENAME_STR "${PROJECT_OUTPUT_NAME}.exe" +#define VER_PRODUCTNAME_STR "${PROJECT_NAME}" +#define VER_PRODUCTVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH} +#define VER_PRODUCTVERSION_STR "${PROJECT_VERSION}" + +#ifndef DEBUG +#define VER_DEBUG 0 +#else +#define VER_DEBUG VS_FF_DEBUG +#endif + +VS_VERSION_INFO VERSIONINFO +FILEVERSION VER_FILEVERSION +PRODUCTVERSION VER_PRODUCTVERSION +FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +//TODO: Set file flags. +//FILEFLAGS (VER_PRIVATEBUILD|VER_PRERELEASE|VER_DEBUG) +FILEFLAGS 0 +FILEOS VOS__WINDOWS32 +FILETYPE VFT_DLL +FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "CompanyName", VER_COMPANYNAME_STR + VALUE "FileDescription", VER_FILEDESCRIPTION_STR + VALUE "FileVersion", VER_FILEVERSION_STR + VALUE "InternalName", VER_INTERNALNAME_STR + VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR + VALUE "LegalTrademarks1", VER_LEGALTRADEMARKS1_STR + VALUE "LegalTrademarks2", VER_LEGALTRADEMARKS2_STR + VALUE "OriginalFilename", VER_ORIGINALFILENAME_STR + VALUE "ProductName", VER_PRODUCTNAME_STR + VALUE "ProductVersion", VER_PRODUCTVERSION_STR + END + END + + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END diff --git a/src/libs/CMakeLists.txt b/src/libs/CMakeLists.txt new file mode 100644 index 0000000..d0f24cc --- /dev/null +++ b/src/libs/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(core) +add_subdirectory(registry) +add_subdirectory(ui) +add_subdirectory(util) diff --git a/src/libs/core/CMakeLists.txt b/src/libs/core/CMakeLists.txt new file mode 100644 index 0000000..afe6f43 --- /dev/null +++ b/src/libs/core/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(Core + application.cpp + extractor.cpp + localserver.cpp + networkaccessmanager.cpp + settings.cpp +) + +target_link_libraries(Core Registry Ui) + +find_package(Qt5 COMPONENTS Network WebKit Widgets REQUIRED) +target_link_libraries(Core Qt5::Network Qt5::WebKit Qt5::Widgets) + +find_package(LibArchive REQUIRED) +include_directories(${LibArchive_INCLUDE_DIRS}) +target_link_libraries(Core ${LibArchive_LIBRARIES}) diff --git a/src/libs/registry/CMakeLists.txt b/src/libs/registry/CMakeLists.txt new file mode 100644 index 0000000..d04cf71 --- /dev/null +++ b/src/libs/registry/CMakeLists.txt @@ -0,0 +1,13 @@ +add_library(Registry + cancellationtoken.cpp + docset.cpp + docsetmetadata.cpp + docsetregistry.cpp + listmodel.cpp + searchmodel.cpp + searchquery.cpp + searchresult.h # Only for Qt Creator to see it. +) + +find_package(Qt5 COMPONENTS Concurrent Gui Network REQUIRED) +target_link_libraries(Registry Util Qt5::Concurrent Qt5::Gui Qt5::Network) diff --git a/src/libs/ui/CMakeLists.txt b/src/libs/ui/CMakeLists.txt new file mode 100644 index 0000000..9232d17 --- /dev/null +++ b/src/libs/ui/CMakeLists.txt @@ -0,0 +1,25 @@ +add_subdirectory(qxtglobalshortcut) + +list(APPEND Widgets_SOURCES + widgets/searchablewebview.cpp + widgets/searchedit.cpp + widgets/shortcutedit.cpp + widgets/toolbarframe.cpp + widgets/webview.cpp +) + +add_library(Ui + aboutdialog.cpp + docsetlistitemdelegate.cpp + docsetsdialog.cpp + mainwindow.cpp + progressitemdelegate.cpp + searchitemdelegate.cpp + settingsdialog.cpp + ${Widgets_SOURCES} +) + +target_link_libraries(Ui QxtGlobalShortcut Registry) + +find_package(Qt5 COMPONENTS WebKitWidgets REQUIRED) +target_link_libraries(Ui Qt5::WebKitWidgets) diff --git a/src/libs/ui/qxtglobalshortcut/CMakeLists.txt b/src/libs/ui/qxtglobalshortcut/CMakeLists.txt new file mode 100644 index 0000000..8b1b0ef --- /dev/null +++ b/src/libs/ui/qxtglobalshortcut/CMakeLists.txt @@ -0,0 +1,41 @@ +list(APPEND QxtGlobalShortcut_SOURCES + qxtglobalshortcut.cpp +) + +if(APPLE) + list(APPEND QxtGlobalShortcut_SOURCES + qxtglobalshortcut_mac.cpp + ) +elseif(UNIX) + find_package(X11) + if(X11_FOUND) + list(APPEND QxtGlobalShortcut_SOURCES + qxtglobalshortcut_x11.cpp + ) + endif() +elseif(WIN32) + list(APPEND QxtGlobalShortcut_SOURCES + qxtglobalshortcut_win.cpp + ) +endif() + +add_library(QxtGlobalShortcut ${QxtGlobalShortcut_SOURCES}) + +find_package(Qt5Gui REQUIRED) +target_link_libraries(QxtGlobalShortcut Qt5::Gui) + +if(APPLE) + find_library(CARBON_LIBRARY Carbon) + target_link_libraries(QxtGlobalShortcut ${CARBON_LIBRARY}) +elseif(UNIX AND X11_FOUND) + target_link_libraries(QxtGlobalShortcut ${X11_LIBRARIES}) + + find_package(Qt5 COMPONENTS X11Extras REQUIRED) + target_link_libraries(QxtGlobalShortcut Qt5::X11Extras) + + find_package(ECM REQUIRED NO_MODULE) + set(CMAKE_MODULE_PATH ${ECM_FIND_MODULE_DIR}) + + find_package(XCB COMPONENTS XCB KEYSYMS REQUIRED) + target_link_libraries(QxtGlobalShortcut XCB::XCB XCB::KEYSYMS) +endif() diff --git a/src/libs/util/CMakeLists.txt b/src/libs/util/CMakeLists.txt new file mode 100644 index 0000000..d4ab871 --- /dev/null +++ b/src/libs/util/CMakeLists.txt @@ -0,0 +1,18 @@ +# Nothing to moc here, so avoid empty build units. +set(CMAKE_AUTOMOC OFF) + +add_library(Util + plist.cpp + sqlitedatabase.cpp + version.cpp +) + +find_package(Qt5Core REQUIRED) +target_link_libraries(Util Qt5::Core) + +find_package(SQLite REQUIRED) +include_directories(${SQLite_INCLUDE_DIR}) +target_link_libraries(Util ${SQLite_LIBRARY}) + +# TODO: Do not export SQLite headers. +target_include_directories(Util PUBLIC ${SQLite_INCLUDE_DIR})