Skip to content

Commit

Permalink
Let emv-viewer use relative data path for MacOS and Windows builds
Browse files Browse the repository at this point in the history
This ensures that emv-viewer can find the iso-codes and mcc-codes files
on platforms that do not install these to standardised directories.
  • Loading branch information
leonlynch committed Oct 29, 2024
1 parent e4d4206 commit fe909db
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
59 changes: 38 additions & 21 deletions viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ if(EMV_VIEWER_IS_TOP_LEVEL)
if(NOT EXISTS ${MCC_JSON_SOURCE_PATH})
message(FATAL_ERROR "mcc-codes/mcc_codes.json not found")
endif()

# Use relative data paths for MacOS bundles
set(EMV_VIEWER_USE_RELATIVE_DATA_PATH "../Resources/")
endif()
else()
# Parent project must provide the emv-utils targets
Expand All @@ -67,6 +70,14 @@ else()
if(NOT EXISTS ${MCC_JSON_SOURCE_PATH})
message(FATAL_ERROR "mcc_codes.json not found")
endif()

# All-in-builds intended for installers should use relative data paths
if(APPLE AND BUILD_MACOSX_BUNDLE)
set(EMV_VIEWER_USE_RELATIVE_DATA_PATH "../Resources/")
endif()
if(WIN32)
set(EMV_VIEWER_USE_RELATIVE_DATA_PATH "../${CMAKE_INSTALL_DATADIR}/emv-utils/")
endif()
endif()

include(FindPackageHandleStandardArgs) # Provides find_package() messages
Expand Down Expand Up @@ -184,21 +195,25 @@ if(APPLE AND BUILD_MACOSX_BUNDLE)
)

# Install iso-codes into bundle for MacOS
find_package(IsoCodes REQUIRED)
install(FILES
${IsoCodes_JSON_PATH}/iso_639-2.json
${IsoCodes_JSON_PATH}/iso_3166-1.json
${IsoCodes_JSON_PATH}/iso_4217.json
COMPONENT emv_viewer_bundle
DESTINATION $<TARGET_BUNDLE_CONTENT_DIR:emv-viewer>/Resources/
)
if(EMV_VIEWER_USE_RELATIVE_DATA_PATH)
find_package(IsoCodes REQUIRED)
install(FILES
${IsoCodes_JSON_PATH}/iso_639-2.json
${IsoCodes_JSON_PATH}/iso_3166-1.json
${IsoCodes_JSON_PATH}/iso_4217.json
COMPONENT emv_viewer_bundle
DESTINATION $<TARGET_BUNDLE_CONTENT_DIR:emv-viewer>/Resources/
)
endif()

# Install mcc-codes into bundle for MacOS
install(FILES
${MCC_JSON_SOURCE_PATH}
COMPONENT emv_viewer_bundle
DESTINATION $<TARGET_BUNDLE_CONTENT_DIR:emv-viewer>/Resources/
)
if(EMV_VIEWER_USE_RELATIVE_DATA_PATH)
install(FILES
${MCC_JSON_SOURCE_PATH}
COMPONENT emv_viewer_bundle
DESTINATION $<TARGET_BUNDLE_CONTENT_DIR:emv-viewer>/Resources/
)
endif()

# Install other tools into bundle for MacOS
if(TARGET emv-decode)
Expand Down Expand Up @@ -233,14 +248,16 @@ if(WIN32)
target_sources(emv-viewer PRIVATE icon.rc)

# Install iso-codes for Windows
find_package(IsoCodes REQUIRED)
install(FILES
${IsoCodes_JSON_PATH}/iso_639-2.json
${IsoCodes_JSON_PATH}/iso_3166-1.json
${IsoCodes_JSON_PATH}/iso_4217.json
COMPONENT emv_runtime # Same as for mcc-codes
DESTINATION ${CMAKE_INSTALL_DATADIR}/emv-utils/ # Same as for mcc-codes
)
if(EMV_VIEWER_USE_RELATIVE_DATA_PATH)
find_package(IsoCodes REQUIRED)
install(FILES
${IsoCodes_JSON_PATH}/iso_639-2.json
${IsoCodes_JSON_PATH}/iso_3166-1.json
${IsoCodes_JSON_PATH}/iso_4217.json
COMPONENT emv_runtime # Same as for mcc-codes
DESTINATION ${CMAKE_INSTALL_DATADIR}/emv-utils/ # Same as for mcc-codes
)
endif()

# Deploy Qt for Windows
include(DeployQt)
Expand Down
14 changes: 14 additions & 0 deletions viewer/emv-viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QtWidgets/QApplication>
#include <QtCore/QCommandLineParser>
#include <QtCore/QString>
#include <QtCore/QStringLiteral>

#include "emv_viewer_config.h"
#include "emv_strings.h"
Expand Down Expand Up @@ -50,6 +51,19 @@ int main(int argc, char** argv)

QString isocodes_path = parser.value("isocodes-path");
QString mcc_path = parser.value("mcc-json");
#ifdef EMV_VIEWER_USE_RELATIVE_DATA_PATH
if (isocodes_path.isEmpty()) {
isocodes_path =
app.applicationDirPath() + QStringLiteral("/") +
QStringLiteral(EMV_VIEWER_USE_RELATIVE_DATA_PATH);
}
if (mcc_path.isEmpty()) {
mcc_path =
app.applicationDirPath() + QStringLiteral("/") +
QStringLiteral(EMV_VIEWER_USE_RELATIVE_DATA_PATH) +
QStringLiteral("mcc_codes.json");
}
#endif
r = emv_strings_init(
isocodes_path.isEmpty() ? nullptr : qPrintable(isocodes_path),
mcc_path.isEmpty() ? nullptr : qPrintable(mcc_path)
Expand Down
1 change: 1 addition & 0 deletions viewer/emv_viewer_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
#define EMV_VIEWER_CONFIG_H

#define EMV_VIEWER_VERSION_STRING "@EMV_UTILS_VERSION_STRING@"
#cmakedefine EMV_VIEWER_USE_RELATIVE_DATA_PATH "@EMV_VIEWER_USE_RELATIVE_DATA_PATH@"

#endif

0 comments on commit fe909db

Please sign in to comment.