Skip to content

Commit

Permalink
Initial layout for emv-viewer sub-project
Browse files Browse the repository at this point in the history
* CMake sub-project for the emv-viewer application will be in the
  `viewer` directory.
* It should be possible to build emv-viewer using libraries provided by
  the parent project, or as a standalone project using installed
  libraries provided by the platform.
* Qt is optional. If it cannot be found, emv-viewer build will be
  skipped. Use the BUILD_EMV_VIEWER option to ensure that emv-viewer
  will be built.
  • Loading branch information
leonlynch committed Jun 9, 2024
1 parent 1d2b40c commit dfbabf6
Show file tree
Hide file tree
Showing 9 changed files with 1,187 additions and 0 deletions.
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,43 @@ add_subdirectory(src)
add_subdirectory(tools)
add_subdirectory(tests)

# If Qt::Widgets is available, build emv-viewer
option(BUILD_EMV_VIEWER "Build emv-viewer")
# See https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html#supporting-older-qt-5-versions
# Note that CMAKE_DISABLE_FIND_PACKAGE_<PackageName> only applies to the
# primary package name and not the alternative names and therefore it is
# necessary to build the list of alternative names to ensure that either Qt5 or
# Qt6 can be disabled, otherwise CMAKE_DISABLE_FIND_PACKAGE_<PackageName> will
# be ignored.
if(NOT CMAKE_DISABLE_FIND_PACKAGE_Qt5)
list(APPEND Qt_NAMES Qt5)
endif()
if(NOT CMAKE_DISABLE_FIND_PACKAGE_Qt6)
list(APPEND Qt_NAMES Qt6)
endif()
if(Qt_NAMES)
find_package(QT 5.12 NAMES ${Qt_NAMES} COMPONENTS Widgets)
if(QT_FOUND)
message(STATUS "Found Qt${QT_VERSION_MAJOR} Widgets: ${QT_CONFIG} (found suitable version \"${QT_VERSION}\")")
else()
if(BUILD_EMV_VIEWER)
message(FATAL_ERROR "Could NOT find Qt Widgets; required to build emv-viewer")
else()
message(STATUS "Could NOT find Qt Widgets: skipping emv-viewer build")
endif()
endif()
else()
if(BUILD_EMV_VIEWER)
message(FATAL_ERROR "Both Qt5 and Qt6 are disabled: required to build emv-viewer")
else()
message(STATUS "Both Qt5 and Qt6 are disabled: skipping emv-viewer build")
endif()
endif()
if(QT_FOUND)
message(STATUS "Adding emv-viewer to build")
add_subdirectory(viewer)
endif()

include(GNUInstallDirs) # Provides CMAKE_INSTALL_* variables and good defaults for install()

# Install README and LICENSE files to runtime component
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Dependencies
[PCSCLite](https://pcsclite.apdu.fr/) on Linux/MacOS. Use the
`BUILD_EMV_TOOL` option to prevent `emv-tool` from being built and avoid the
dependency on PC/SC.
* `emv-viewer` can _optionally_ be built if [Qt](https://www.qt.io/) (see
[Qt](#qt) for details) is available at build-time. If it is not available,
`emv-viewer` will not be built. Use the `BUILD_EMV_VIEWER` option to ensure
that `emv-viewer` will be built.
* [Doxygen](https://github.com/doxygen/doxygen) can _optionally_ be used to
generate API documentation if it is available; see
[Documentation](#documentation)
Expand Down Expand Up @@ -162,6 +166,20 @@ at build time using the CMake `ISO8859_IMPL` option. It allows these values:
* `simple`: Only supports ISO 8859-1, has no dependencies and doesn't require
C++.

Qt
--

This project supports Qt 5.12.x, Qt 5.15.x, Qt 6.5.x and Qt 6.6.x (although it
may be possible to use other versions of Qt) when building the `emv-viewer`
application. However, on some platforms it may be necessary to use the `QT_DIR`
option (and not the `Qt5_DIR` nor `Qt6_DIR` options) or `CMAKE_PREFIX_PATH`
option to specify the exact Qt installation to be used. For Qt6 it may also be
necessary for the Qt tools to be available in the executable PATH regardless of
the `QT_DIR` option.

If the Qt installation does not provide universal binaries for MacOS, it will
not be possible to build `emv-viewer` as a universal binary for MacOS.

MacOS / Windows
---------------

Expand Down
123 changes: 123 additions & 0 deletions viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
##############################################################################
# Copyright 2024 Leon Lynch
#
# This file is licensed under the terms of the GPL v3 license.
# See LICENSE.gpl file.
##############################################################################

cmake_minimum_required(VERSION 3.16)

project(emv-viewer
VERSION 0.1.0
DESCRIPTION "EMV Viewer using Qt"
HOMEPAGE_URL "https://github.com/openemv/emv-utils"
LANGUAGES CXX
)

# Determine whether this project is the top-level project
if(${CMAKE_VERSION} VERSION_LESS "3.21")
get_directory_property(EMV_VIEWER_HAS_PARENT PARENT_DIRECTORY)
if(NOT EMV_VIEWER_HAS_PARENT)
set(EMV_VIEWER_IS_TOP_LEVEL True)
endif()
else()
# CMake >=3.21 provides <PROJECT-NAME>_IS_TOP_LEVEL
set(EMV_VIEWER_IS_TOP_LEVEL ${emv-viewer_IS_TOP_LEVEL})
endif()

# Configure compiler
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wall)
add_compile_options($<$<CONFIG:Debug>:-ggdb>)
add_compile_options($<$<CONFIG:RelWithDebInfo>:-ggdb>)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wall)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
add_compile_options(-Wall)
endif()

if(EMV_VIEWER_IS_TOP_LEVEL)
# If this is the top-level project, look for the platform emv-utils libraries
find_package(emv-viewer 0.1.0 REQUIRED)
else()
# Otherwise the parent project must provide the emv-utils targets
if(NOT TARGET emv::emv_strings)
message(FATAL_ERROR "Parent project must provide emv-utils libraries")
endif()
endif()

include(GNUInstallDirs) # Provides CMAKE_INSTALL_* variables and good defaults for install()

# Generate config file for internal use only
# This file should NOT be installed or used by an installed header
if(NOT EMV_UTILS_VERSION_STRING)
set(EMV_UTILS_VERSION_STRING ${emv-viewer_VERSION})
endif()
configure_file(
emv_viewer_config.h.in
emv_viewer_config.h
)

# See https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html#supporting-older-qt-5-versions
# Note that CMAKE_DISABLE_FIND_PACKAGE_<PackageName> only applies to the
# primary package name and not the alternative names and therefore it is
# necessary to build the list of alternative names to ensure that either Qt5 or
# Qt6 can be disabled, otherwise CMAKE_DISABLE_FIND_PACKAGE_<PackageName> will
# be ignored.
if(NOT CMAKE_DISABLE_FIND_PACKAGE_Qt5)
list(APPEND Qt_NAMES Qt5)
endif()
if(NOT CMAKE_DISABLE_FIND_PACKAGE_Qt6)
list(APPEND Qt_NAMES Qt6)
endif()
if(NOT Qt_NAMES)
message(FATAL_ERROR "Either Qt5 or Qt6 are required to build emv-viewer")
endif()

find_package(QT 5.12 NAMES ${Qt_NAMES} REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets PATHS ${QT_DIR})
message(STATUS "Found Qt${QT_VERSION_MAJOR} Widgets: ${QT_CONFIG} (found suitable version \"${QT_VERSION}\")")
if(QT_VERSION VERSION_LESS 5.15)
# Qt-5.12 provides these versioned commands
qt5_wrap_ui(UI_SRCS emv-viewer-mainwindow.ui)
qt5_wrap_cpp(MOC_SRCS emv-viewer-mainwindow.h)
add_library(Qt::Widgets ALIAS Qt5::Widgets)
else()
# Qt-5.15 and Qt-6 provide these version-less commands
qt_wrap_ui(UI_SRCS emv-viewer-mainwindow.ui)
qt_wrap_cpp(MOC_SRCS emv-viewer-mainwindow.h)
endif()

add_executable(emv-viewer emv-viewer.cpp emv-viewer-mainwindow.cpp ${UI_SRCS} ${MOC_SRCS} ${QRC_SRCS})
target_include_directories(emv-viewer PRIVATE
${CMAKE_CURRENT_BINARY_DIR} # For generated files
)
target_link_libraries(emv-viewer Qt::Widgets)

if(WIN32)
# Set properties needed for GUI applications on Windows
set_target_properties(
emv-viewer
PROPERTIES
WIN32_EXECUTABLE TRUE
)
endif()

# Install LICENSE.gpl file to UI runtime component
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.gpl
TYPE DOC
COMPONENT emv_viewer_runtime
)

install(
TARGETS
emv-viewer
EXPORT emvUtilsTargets # For use by install(EXPORT) command
RUNTIME
COMPONENT emv_viewer_runtime
)
Loading

0 comments on commit dfbabf6

Please sign in to comment.