Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake build #406

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ indent_size = 4

[*.yml]
indent_size = 2

[CMakeLists.txt]
indent_size = 2

[*.md]
indent_size = 2

[*.cmake]
indent_size = 2
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,23 @@ c_x86_64.pch

compile_commands.json
.ccls-cache

# CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
*.ninja
.ninja*

build*/

# VSCode
.vscode/
183 changes: 183 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
cmake_minimum_required(VERSION 3.21)

project(
YACReader
VERSION 9.14.2
LANGUAGES C CXX)

# enable Objective-C for macOSX
if(APPLE)
enable_language(OBJC)
enable_language(OBJCXX)
endif()

# Extra functions
find_package(PkgConfig)
include(GNUInstallDirs)

# Set defaults TODO: Bad practice?
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(MSVC)
add_compile_options("-we4061")
else()
add_compile_options("-Werror=switch")
endif()

# Set default build type to "Release" if it is empty
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(
STATUS
"Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE
"${default_build_type}"
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()

# Require out-of-source builds
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(
FATAL_ERROR
"You cannot build in a source directory (or any \
directory with a CMakeLists.txt file). Please make a build subdirectory. \
Feel free to remove CMakeCache.txt and CMakeFiles.
")
endif()

# Common build Options
if(NOT DECOMPRESSION_BACKEND)
set(DECOMPRESSION_BACKEND
"unarr"
CACHE STRING "Decompression backend for cbx files")
endif()
set_property(CACHE DECOMPRESSION_BACKEND PROPERTY STRINGS "unarr" "7zip"
"libarchive")

if(NOT PDF_BACKEND)
set(PDF_BACKEND
"pdfium"
CACHE STRING "PDF comic rendering backend")
endif()
set_property(CACHE PDF_BACKEND PROPERTY STRINGS "pdfium" "poppler" "pdfkit")

# TODO: OpenGL
if(NOT OPENGL)
set(OPENGL
"desktop"
CACHE STRING "OpenGL backend")
endif()
set_property(CACHE OPENGL PROPERTY STRINGS "desktop" "angle" "force-angle"
"no_opengl")

# TODO: option(SERVER_STANDALONE "Server standalone build (no gui apps)" OFF)

# Handle dependencies for backends
if(DECOMPRESSION_BACKEND STREQUAL "unarr")
find_package("unarr")
# old unarr only ships PKGCONFIG
if(NOT unarr_FOUND)
pkg_check_modules(unarr IMPORTED_TARGET "libunarr" REQUIRED)
endif()
elseif(DECOMPRESSION_BACKEND STREQUAL "7zip")
find_package("7zip" REQUIRED)
elseif(DECOMPRESSION_BACKEND STREQUAL "libarchive")
find_package("LibArchive" REQUIRED)
else()
message(FATAL_ERROR "No valid decompression backend specified.")
endif()

if(PDF_BACKEND STREQUAL "pdfium")
pkg_check_modules(PDFIUM IMPORTED_TARGET "libpdfium" REQUIRED)
elseif(PDF_BACKEND STREQUAL "poppler")
pkg_check_modules(POPPLER IMPORTED_TARGET "poppler-qt6" REQUIRED)
elseif(PDF_BACKEND STREQUAL "pdfkit")
find_package("pdfkit" REQUIRED)
elseif(PDF_BACKEND STREQUAL "no_pdf")
# Do nothing
else()
message(FATAL_ERROR "No valid PDF backend specified.")
endif()

# Qt6 modules TODO: Server standalone
find_package(
Qt6 REQUIRED
COMPONENTS Core
Core5Compat
Gui
Network
LinguistTools
Multimedia
OpenGLWidgets
QuickControls2
QuickWidgets
Svg
Sql
Widgets)

# Qt project setup

# Check if qt_standard_project_setup is available
if(COMMAND qt_standard_project_setup)
qt_standard_project_setup()
else() # Old style fallback for Qt6 < 6.3
message(
WARNING
"qt_standard_project_setup is not available, falling back to old-style project setup"
)
# Auto process moc, rc and ui
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
endif()

# Modules
add_subdirectory(common)
add_subdirectory(compressed_archive)
add_subdirectory(custom_widgets)
add_subdirectory(shortcuts_management)
add_subdirectory(third_party)
add_subdirectory(YACReaderLibrary/server)

# Executables
add_subdirectory(YACReader)
add_subdirectory(YACReaderLibrary)
add_subdirectory(YACReaderLibraryServer)

# Install and Deployment
if(UNIX AND NOT APPLE)
if(SERVER_STANDALONE)
install(
TARGETS YACReaderLibraryServer
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/yacreader)
else()
install(
TARGETS YACReader YACReaderLibrary YACReaderLibraryServer
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/yacreader)
endif()
# Docs and runtime
install(DIRECTORY release DESTINATION ${CMAKE_INSTALL_DATADIR}/yacreader)
install(FILES README.md CHANGELOG.md DESTINATION ${CMAKE_INSTALL_DOCDIR})
# Manpages
install(FILES YACReader.1 YACReaderLibrary.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
# Icons, Desktop files
install(FILES YACReader.desktop YACReaderLibrary.desktop
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES YACReader.svg YACReaderLibrary.svg
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
# Translations
install(FILES ${reader_translations} ${library_translations}
DESTINATION ${CMAKE_INSTALL_DATADIR}/yacreader/release/languages)
elseif(WIN32)
# TODO
elseif(APPLE)
# TODO
endif()
77 changes: 77 additions & 0 deletions YACReader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
add_executable(YACReader main.cpp)
target_sources(
YACReader
PRIVATE bookmarks_dialog.cpp
bookmarks_dialog.h
configuration.cpp
configuration.h
goto_dialog.cpp
goto_dialog.h
goto_flow_gl.cpp
goto_flow_toolbar.cpp
goto_flow_toolbar.h
goto_flow_widget.cpp
goto_flow_widget.h
goto_flow.cpp
goto_flow.h
magnifying_glass.cpp
magnifying_glass.h
main_window_viewer.cpp
main_window_viewer.h
notifications_label_widget.cpp
notifications_label_widget.h
options_dialog.cpp
options_dialog.h
page_label_widget.cpp
page_label_widget.h
render.cpp
render.h
translator.cpp
translator.h
viewer.cpp
viewer.h
width_slider.cpp
width_slider.h
yacreader_local_client.cpp
yacreader_local_client.h)

qt_add_resources(yr_resources yacreader_images.qrc yacreader_files.qrc)
target_sources(YACReader PRIVATE ${yr_resources})

qt_add_translations(
YACReader
TS_FILES
yacreader_de.ts
yacreader_en.ts
yacreader_es.ts
yacreader_fr.ts
yacreader_it.ts
yacreader_nl.ts
yacreader_pt.ts
yacreader_ru.ts
yacreader_tr.ts
yacreader_zh_CN.ts
yacreader_zh_HK.ts
yacreader_zh_TW.ts
QM_FILES_OUTPUT_VARIABLE
reader_translations)

target_link_libraries(
YACReader
PRIVATE comic_backend
common_all
common_gui
custom_widgets_reader
naturalsort
QsLog
Qt::Gui
Qt::Multimedia
Qt::Network
Qt::OpenGLWidgets
Qt::Svg
Qt::Widgets
version_checker
yr_global
Qt::Core5Compat)
target_compile_definitions(YACReader
PRIVATE DATADIR="${CMAKE_INSTALL_FULL_DATADIR}")
Loading