mirror of
https://github.com/YACReader/yacreader
synced 2026-03-01 10:22:58 -05:00
Migrate the build system to cmake
This commit is contained in:
197
common/CMakeLists.txt
Normal file
197
common/CMakeLists.txt
Normal file
@ -0,0 +1,197 @@
|
||||
# Common libraries for YACReader
|
||||
# Fine-grained STATIC targets per concern
|
||||
|
||||
# --- yr_global (no GUI, used by all 3 apps) ---
|
||||
add_library(yr_global STATIC
|
||||
yacreader_global.h
|
||||
yacreader_global.cpp
|
||||
)
|
||||
target_include_directories(yr_global PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(yr_global PUBLIC Qt::Core)
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_compile_definitions(yr_global PRIVATE
|
||||
"LIBDIR=\"${CMAKE_INSTALL_FULL_LIBDIR}\"")
|
||||
endif()
|
||||
|
||||
# --- naturalsort ---
|
||||
add_library(naturalsort STATIC
|
||||
qnaturalsorting.h
|
||||
qnaturalsorting.cpp
|
||||
)
|
||||
target_include_directories(naturalsort PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(naturalsort PUBLIC Qt::Core)
|
||||
|
||||
# --- concurrent_queue ---
|
||||
add_library(concurrent_queue STATIC
|
||||
concurrent_queue.h
|
||||
concurrent_queue.cpp
|
||||
)
|
||||
target_include_directories(concurrent_queue PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(concurrent_queue PUBLIC Qt::Core)
|
||||
|
||||
# --- worker (header-only thread helpers) ---
|
||||
add_library(worker INTERFACE)
|
||||
target_include_directories(worker INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_sources(worker INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/worker_thread.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/release_acquire_atomic.h
|
||||
)
|
||||
|
||||
# --- common_all (shared non-GUI code used by all 3 apps) ---
|
||||
add_library(common_all STATIC
|
||||
comic_db.h
|
||||
comic_db.cpp
|
||||
folder.h
|
||||
folder.cpp
|
||||
library_item.h
|
||||
library_item.cpp
|
||||
bookmarks.h
|
||||
bookmarks.cpp
|
||||
http_worker.h
|
||||
http_worker.cpp
|
||||
cover_utils.h
|
||||
cover_utils.cpp
|
||||
global_info_provider.h
|
||||
global_info_provider.cpp
|
||||
)
|
||||
target_include_directories(common_all PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(common_all PUBLIC
|
||||
Qt::Core
|
||||
Qt::Gui
|
||||
Qt::Sql
|
||||
Qt::Network
|
||||
yr_global
|
||||
naturalsort
|
||||
pdf_backend_iface
|
||||
)
|
||||
|
||||
# --- comic_backend (comic file handling + PDF) ---
|
||||
add_library(comic_backend STATIC
|
||||
comic.h
|
||||
comic.cpp
|
||||
pdf_comic.h
|
||||
)
|
||||
|
||||
# PDF source depends on backend
|
||||
if(PDF_BACKEND STREQUAL "pdfkit")
|
||||
target_sources(comic_backend PRIVATE pdf_comic.mm)
|
||||
elseif(NOT PDF_BACKEND STREQUAL "no_pdf")
|
||||
target_sources(comic_backend PRIVATE pdf_comic.cpp)
|
||||
endif()
|
||||
|
||||
target_include_directories(comic_backend PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(comic_backend PUBLIC
|
||||
Qt::Core
|
||||
Qt::Gui
|
||||
common_all
|
||||
pdf_backend_iface
|
||||
cbx_backend
|
||||
QsLog
|
||||
)
|
||||
|
||||
# GUI-only targets: not needed for server-standalone builds (Qt 6.4+) which
|
||||
# lack Qt::Widgets, Qt::ShaderTools, Qt::GuiPrivate, etc.
|
||||
if(NOT BUILD_SERVER_STANDALONE)
|
||||
|
||||
# --- common_gui (GUI-only code: widgets, version check, themes infrastructure) ---
|
||||
# NOTE: theme_manager.h/cpp is NOT included here because it depends on app-specific
|
||||
# theme.h (YACReader vs YACReaderLibrary have different Theme structs).
|
||||
# Each app includes theme_manager directly alongside its own theme.h/theme_factory.
|
||||
add_library(common_gui STATIC
|
||||
custom_widgets.h
|
||||
custom_widgets.cpp
|
||||
check_new_version.h
|
||||
check_new_version.cpp
|
||||
yacreader_global_gui.h
|
||||
yacreader_global_gui.cpp
|
||||
exit_check.h
|
||||
exit_check.cpp
|
||||
scroll_management.h
|
||||
scroll_management.cpp
|
||||
# themes infrastructure (does NOT depend on app-specific theme.h)
|
||||
themes/icon_utils.h
|
||||
themes/icon_utils.cpp
|
||||
themes/theme_id.h
|
||||
themes/themable.h
|
||||
themes/yacreader_icon.h
|
||||
themes/shared/help_about_dialog_theme.h
|
||||
themes/shared/whats_new_dialog_theme.h
|
||||
)
|
||||
target_include_directories(common_gui PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/themes
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/themes/shared
|
||||
)
|
||||
target_link_libraries(common_gui PUBLIC
|
||||
Qt::Core
|
||||
Qt::Core5Compat
|
||||
Qt::Widgets
|
||||
Qt::Network
|
||||
Qt::Svg
|
||||
common_all
|
||||
yr_global
|
||||
QsLog
|
||||
)
|
||||
|
||||
# --- RHI flow (3D coverflow) ---
|
||||
# Compiled twice with different defines, like the old GL flow pattern.
|
||||
# Shaders are compiled from GLSL 450 source at build time via qt_add_shaders().
|
||||
|
||||
set(RHI_FLOW_SOURCES
|
||||
rhi/flow_types.h
|
||||
rhi/flow_types.cpp
|
||||
rhi/yacreader_flow_rhi.h
|
||||
rhi/yacreader_flow_rhi.cpp
|
||||
rhi/yacreader_comic_flow_rhi.h
|
||||
rhi/yacreader_comic_flow_rhi.cpp
|
||||
rhi/yacreader_page_flow_rhi.h
|
||||
rhi/yacreader_page_flow_rhi.cpp
|
||||
)
|
||||
|
||||
add_library(rhi_flow_reader STATIC ${RHI_FLOW_SOURCES})
|
||||
target_include_directories(rhi_flow_reader PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rhi
|
||||
)
|
||||
target_compile_definitions(rhi_flow_reader PRIVATE YACREADER)
|
||||
target_link_libraries(rhi_flow_reader PUBLIC
|
||||
Qt::Core
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
Qt::Widgets
|
||||
)
|
||||
qt_add_shaders(rhi_flow_reader "flow_shaders_reader"
|
||||
BASE rhi/shaders
|
||||
PREFIX "/shaders"
|
||||
GLSL "100es,120,150"
|
||||
HLSL 50
|
||||
MSL 12
|
||||
FILES
|
||||
rhi/shaders/flow.vert
|
||||
rhi/shaders/flow.frag
|
||||
)
|
||||
|
||||
add_library(rhi_flow_library STATIC ${RHI_FLOW_SOURCES})
|
||||
target_include_directories(rhi_flow_library PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rhi
|
||||
)
|
||||
target_compile_definitions(rhi_flow_library PRIVATE YACREADER_LIBRARY)
|
||||
target_link_libraries(rhi_flow_library PUBLIC
|
||||
Qt::Core
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
Qt::Widgets
|
||||
)
|
||||
qt_add_shaders(rhi_flow_library "flow_shaders_library"
|
||||
BASE rhi/shaders
|
||||
PREFIX "/shaders"
|
||||
GLSL "100es,120,150"
|
||||
HLSL 50
|
||||
MSL 12
|
||||
FILES
|
||||
rhi/shaders/flow.vert
|
||||
rhi/shaders/flow.frag
|
||||
)
|
||||
|
||||
endif() # NOT BUILD_SERVER_STANDALONE
|
||||
@ -27,7 +27,7 @@ QRhiWidget (Qt base class)
|
||||
|
||||
- **yacreader_flow_rhi.h** - Header with class definitions
|
||||
- **yacreader_flow_rhi.cpp** - Implementation
|
||||
- **shaders/** - GLSL 450 shaders and compiled .qsb files
|
||||
- **shaders/** - GLSL 450 shader source files (compiled to .qsb at build time by `qt_add_shaders`)
|
||||
- **README.md** - This file
|
||||
|
||||
## Key Features
|
||||
@ -52,7 +52,8 @@ QRhi resources managed:
|
||||
|
||||
### Shader System
|
||||
|
||||
Shaders are written in **GLSL 4.50** and compiled to `.qsb` format supporting:
|
||||
Shaders are written in **GLSL 4.50** and compiled to `.qsb` format at build time
|
||||
via `qt_add_shaders()` in CMake, supporting:
|
||||
- OpenGL ES 2.0, 3.0
|
||||
- OpenGL 2.1, 3.0+
|
||||
- HLSL (Direct3D 11/12)
|
||||
@ -134,36 +135,20 @@ All public methods from `YACReaderFlowGL` are preserved:
|
||||
|
||||
### Prerequisites
|
||||
|
||||
1. **Qt 6.7 or later**
|
||||
2. **qsb tool** (Qt Shader Baker) in PATH
|
||||
3. **C++17 compiler**
|
||||
|
||||
### Compile Shaders
|
||||
|
||||
Before building YACReader, compile the shaders:
|
||||
|
||||
```bash
|
||||
cd common/rhi/shaders
|
||||
# Windows
|
||||
compile_shaders.bat
|
||||
|
||||
# Unix/macOS
|
||||
chmod +x compile_shaders.sh
|
||||
./compile_shaders.sh
|
||||
```
|
||||
|
||||
This generates `flow.vert.qsb` and `flow.frag.qsb` which are embedded via `shaders.qrc`.
|
||||
1. **Qt 6.7 or later** (with ShaderTools module)
|
||||
2. **CMake 3.25+**
|
||||
3. **C++20 compiler**
|
||||
|
||||
### Build YACReader
|
||||
|
||||
The `.pro` files automatically include RHI sources for Qt 6.7+:
|
||||
Shaders are compiled automatically at build time via `qt_add_shaders()`:
|
||||
|
||||
```bash
|
||||
qmake YACReader.pro
|
||||
make
|
||||
cmake -B build -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build --parallel
|
||||
```
|
||||
|
||||
For Qt 5 builds, the OpenGL version is used automatically.
|
||||
No manual shader compilation step is needed.
|
||||
|
||||
## Graphics API Selection
|
||||
|
||||
@ -224,7 +209,7 @@ qDebug() << "Driver:" << rhi->driverInfo();
|
||||
### Common Issues
|
||||
|
||||
**Problem**: Shaders fail to load
|
||||
**Solution**: Ensure `.qsb` files are compiled and included in resources
|
||||
**Solution**: Ensure Qt ShaderTools module is installed and `qt_add_shaders()` ran during build
|
||||
|
||||
**Problem**: Black screen on Qt 6.7
|
||||
**Solution**: Check if `YACREADER_USE_RHI` is defined in build
|
||||
@ -260,7 +245,7 @@ The RHI version is a **drop-in replacement** requiring no application code chang
|
||||
1. **Qt Version**: Requires Qt 6.7+ (released April 2024)
|
||||
2. **QRhi Stability**: QRhi APIs may change in minor Qt releases
|
||||
3. **Mixed Renderers**: Only one graphics API per window
|
||||
4. **Shader Compilation**: Must recompile shaders when modifying source
|
||||
4. **Shader Compilation**: Shaders are recompiled automatically when source files change
|
||||
|
||||
## Future Improvements
|
||||
|
||||
|
||||
@ -1,49 +0,0 @@
|
||||
# YACReader Flow RHI Shaders
|
||||
|
||||
This directory contains the GLSL 4.50 shaders for the QRhiWidget-based flow implementation.
|
||||
|
||||
## Files
|
||||
|
||||
- `flow.vert` - Vertex shader (GLSL 450)
|
||||
- `flow.frag` - Fragment shader (GLSL 450)
|
||||
- `flow.vert.qsb` - Compiled vertex shader (multi-platform)
|
||||
- `flow.frag.qsb` - Compiled fragment shader (multi-platform)
|
||||
- `compile_shaders.bat` - Windows compilation script
|
||||
- `compile_shaders.sh` - Unix/macOS compilation script
|
||||
- `shaders.qrc` - Qt resource file
|
||||
|
||||
## Compiling Shaders
|
||||
|
||||
The shaders must be compiled to `.qsb` format using Qt's `qsb` tool before building YACReader.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
Ensure `qsb` is in your PATH. It's typically located in:
|
||||
- Windows: `C:\Qt\6.x.x\msvc2019_64\bin\qsb.exe`
|
||||
- macOS: `/opt/Qt/6.x.x/macos/bin/qsb`
|
||||
- Linux: `/opt/Qt/6.x.x/gcc_64/bin/qsb`
|
||||
|
||||
### Compilation
|
||||
|
||||
**Windows:**
|
||||
```cmd
|
||||
cd common/rhi/shaders
|
||||
compile_shaders.bat
|
||||
```
|
||||
|
||||
**Unix/macOS:**
|
||||
```bash
|
||||
cd common/rhi/shaders
|
||||
chmod +x compile_shaders.sh
|
||||
./compile_shaders.sh
|
||||
```
|
||||
|
||||
The compiled `.qsb` files contain shader variants for:
|
||||
- OpenGL ES 2.0, 3.0
|
||||
- OpenGL 2.1, 3.0+
|
||||
- HLSL (Direct3D 11/12)
|
||||
- Metal Shading Language (macOS/iOS)
|
||||
|
||||
## Note
|
||||
|
||||
The `.qsb` files are included in the repository for convenience. Recompile only if you modify the shader source.
|
||||
@ -1,19 +0,0 @@
|
||||
@echo off
|
||||
REM Compile shaders to .qsb format for Qt RHI
|
||||
REM Requires qsb tool from Qt installation
|
||||
|
||||
echo Compiling flow vertex shader...
|
||||
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o flow.vert.qsb flow.vert
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo Error compiling vertex shader
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Compiling flow fragment shader...
|
||||
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o flow.frag.qsb flow.frag
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo Error compiling fragment shader
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo Shader compilation complete!
|
||||
@ -1,19 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Compile shaders to .qsb format for Qt RHI
|
||||
# Requires qsb tool from Qt installation
|
||||
|
||||
echo "Compiling flow vertex shader..."
|
||||
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o flow.vert.qsb flow.vert
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error compiling vertex shader"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Compiling flow fragment shader..."
|
||||
qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -o flow.frag.qsb flow.frag
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error compiling fragment shader"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Shader compilation complete!"
|
||||
Binary file not shown.
Binary file not shown.
@ -1,6 +0,0 @@
|
||||
<RCC>
|
||||
<qresource prefix="/shaders">
|
||||
<file>flow.vert.qsb</file>
|
||||
<file>flow.frag.qsb</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@ -1,16 +0,0 @@
|
||||
INCLUDEPATH += $$PWD \
|
||||
$$PWD/shared
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/icon_utils.h \
|
||||
$$PWD/theme_id.h \
|
||||
$$PWD/theme_manager.h \
|
||||
$$PWD/themable.h \
|
||||
$$PWD/yacreader_icon.h \
|
||||
$$PWD/shared/help_about_dialog_theme.h \
|
||||
$$PWD/shared/whats_new_dialog_theme.h \
|
||||
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/icon_utils.cpp \
|
||||
$$PWD/theme_manager.cpp
|
||||
Reference in New Issue
Block a user