add pkgconfig, improve Qt example

This commit is contained in:
Syping 2021-08-27 21:48:33 +02:00
parent 33c3dcb512
commit dd47087afd
5 changed files with 43 additions and 23 deletions

View file

@ -8,8 +8,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)
project(ragephoto-gtkviewer LANGUAGES CXX)
set(GTKVIEWER_HEADERS
src/PhotoViewer.h
)
@ -19,13 +17,18 @@ set(GTKVIEWER_SOURCES
src/PhotoViewer.cpp
)
if(TARGET ragephoto)
if (TARGET ragephoto)
set(RAGEPHOTO_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src)
add_executable(ragephoto-gtkviewer ${GTKVIEWER_HEADERS} ${GTKVIEWER_SOURCES})
target_link_libraries(ragephoto-gtkviewer ${GTKMM_LIBRARIES} ragephoto)
target_link_directories(ragephoto-gtkviewer PRIVATE ${GTKMM_LIBRARY_DIRS})
target_include_directories(ragephoto-gtkviewer PRIVATE ${GTKMM_INCLUDE_DIRS} ${RAGEPHOTO_INCLUDE_DIRS})
install(TARGETS ragephoto-gtkviewer DESTINATION bin)
set(RAGEPHOTO_LIBRARIES ragephoto)
else()
message("ragephoto-gtkviewer need to be build with libragephoto together")
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
endif()
add_executable(ragephoto-gtkviewer ${GTKVIEWER_HEADERS} ${GTKVIEWER_SOURCES})
target_compile_options(ragephoto-gtkviewer PRIVATE ${GTKMM_CFLAGS} ${RAGEPHOTO_CFLAGS})
target_link_libraries(ragephoto-gtkviewer PRIVATE ${GTKMM_LIBRARIES} ${RAGEPHOTO_LIBRARIES})
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
target_link_directories(ragephoto-gtkviewer PRIVATE ${GTKMM_LIBRARY_DIRS} ${RAGEPHOTO_LIBRARY_DIRS})
endif()
target_include_directories(ragephoto-gtkviewer PRIVATE ${GTKMM_INCLUDE_DIRS} ${RAGEPHOTO_INCLUDE_DIRS})
install(TARGETS ragephoto-gtkviewer DESTINATION bin)

View file

@ -17,10 +17,18 @@ set(QTVIEWER_SOURCES
src/main.cpp
)
if(TARGET ragephoto)
add_executable(ragephoto-qtviewer ${QTVIEWER_SOURCES})
target_link_libraries(ragephoto-qtviewer Qt${QT_VERSION_MAJOR}::Widgets ragephoto)
target_include_directories(ragephoto-qtviewer PRIVATE ${RAGEPHOTO_INCLUDE_DIRS})
if (TARGET ragephoto)
set(RAGEPHOTO_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src)
set(RAGEPHOTO_LIBRARIES ragephoto)
else()
message("ragephoto-qtviewer need to be build with libragephoto together")
find_package(PkgConfig REQUIRED)
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
endif()
add_executable(ragephoto-qtviewer ${QTVIEWER_SOURCES})
target_compile_options(ragephoto-qtviewer PRIVATE ${RAGEPHOTO_CFLAGS})
target_link_libraries(ragephoto-qtviewer PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${RAGEPHOTO_LIBRARIES})
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
target_link_directories(ragephoto-qtviewer PRIVATE ${RAGEPHOTO_LIBRARY_DIRS})
endif()
target_include_directories(ragephoto-qtviewer PRIVATE ${RAGEPHOTO_INCLUDE_DIRS})

View file

@ -89,6 +89,8 @@ int main(int argc, char *argv[])
QPushButton openButton("Open", &mainWindow);
QObject::connect(&openButton, &QPushButton::clicked, &mainWindow, [&](){
const QString filename = QFileDialog::getOpenFileName(&mainWindow, "Open Photo...", QString(), "GTA V Photo (PGTA5*)");
if (filename.isEmpty())
return;
if (readPhotoFile(filename, &mainWindow, &photoLabel)) {
QTimer::singleShot(0, &mainWindow, [&](){
mainWindow.setFixedSize(mainWindow.sizeHint());