diff --git a/viewer/CMakeLists.txt b/viewer/CMakeLists.txt index 3d3d07d..99e4186 100644 --- a/viewer/CMakeLists.txt +++ b/viewer/CMakeLists.txt @@ -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 @@ -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 @@ -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 $/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 $/Resources/ + ) + endif() # Install mcc-codes into bundle for MacOS - install(FILES - ${MCC_JSON_SOURCE_PATH} - COMPONENT emv_viewer_bundle - DESTINATION $/Resources/ - ) + if(EMV_VIEWER_USE_RELATIVE_DATA_PATH) + install(FILES + ${MCC_JSON_SOURCE_PATH} + COMPONENT emv_viewer_bundle + DESTINATION $/Resources/ + ) + endif() # Install other tools into bundle for MacOS if(TARGET emv-decode) @@ -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) diff --git a/viewer/emv-viewer.cpp b/viewer/emv-viewer.cpp index 8ed4385..9cc5f94 100644 --- a/viewer/emv-viewer.cpp +++ b/viewer/emv-viewer.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "emv_viewer_config.h" #include "emv_strings.h" @@ -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) diff --git a/viewer/emv_viewer_config.h.in b/viewer/emv_viewer_config.h.in index 951afb6..b6716e7 100644 --- a/viewer/emv_viewer_config.h.in +++ b/viewer/emv_viewer_config.h.in @@ -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