Skip to content

Commit

Permalink
Install iso-codes and mcc-codes for MacOS and Windows packages
Browse files Browse the repository at this point in the history
Both MacOS and Windows packages should contain all necessary files. In
future, emv-viewer will be improved to find and use these installed
files instead of relying on library defaults.
  • Loading branch information
leonlynch committed Oct 28, 2024
1 parent 1b89e18 commit f802bbc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ if(EXISTS ${MCC_JSON_SOURCE_PATH})
COMPONENT emv_runtime
)

# Default mcc-codes paths to be used by libraries and applications
# The build path is also set for the parent scope to facilitate testing
# Default mcc-codes paths to be used by libraries and applications.
# The source path is set for the parent scope to facilitate sub-projects.
# The build path is also set for the parent scope to facilitate testing.
set(MCC_JSON_SOURCE_PATH ${MCC_JSON_SOURCE_PATH} PARENT_SCOPE)
set(MCC_JSON_BUILD_PATH ${MCC_JSON_BINARY_DIR}/${MCC_JSON_SOURCE_FILE})
set(MCC_JSON_BUILD_PATH ${MCC_JSON_BUILD_PATH} PARENT_SCOPE)
set(MCC_JSON_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/${EMV_UTILS_INSTALL_MCC_CODES_DIR}/${MCC_JSON_SOURCE_FILE})
Expand Down
52 changes: 49 additions & 3 deletions viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,32 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
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)
# If this is the top-level project, look for the emv-utils libraries
find_package(emv-utils 0.1.0 REQUIRED)

# If this is the top-level project and being built as a MacOS bundle, the
# mcc-codes file must be available. Otherwise rely entirely on the
# installed libraries for data files such as mcc-codes and iso-codes.
if(APPLE AND BUILD_MACOSX_BUNDLE)
set(MCC_JSON_SOURCE_FILE mcc_codes.json)
set(MCC_JSON_SOURCE_PATH ${PROJECT_SOURCE_DIR}/mcc-codes/${MCC_JSON_SOURCE_FILE})
if(NOT EXISTS ${MCC_JSON_SOURCE_PATH})
message(FATAL_ERROR "mcc-codes/mcc_codes.json not found")
endif()
endif()
else()
# Otherwise the parent project must provide the emv-utils targets
# 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()

# Parent project must provide the mcc-codes file
if(NOT MCC_JSON_SOURCE_PATH)
message(FATAL_ERROR "Parent project must provide mcc-codes submodule")
endif()
if(NOT EXISTS ${MCC_JSON_SOURCE_PATH})
message(FATAL_ERROR "mcc_codes.json not found")
endif()
endif()

include(FindPackageHandleStandardArgs) # Provides find_package() messages
Expand Down Expand Up @@ -164,6 +183,23 @@ if(APPLE AND BUILD_MACOSX_BUNDLE)
DESTINATION $<TARGET_BUNDLE_CONTENT_DIR:emv-viewer>/doc/
)

# 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/
)

# 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/
)

# Install other tools into bundle for MacOS
if(TARGET emv-decode)
install(PROGRAMS
Expand Down Expand Up @@ -196,6 +232,16 @@ if(WIN32)
# Add application icon for Windows
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
)

# Deploy Qt for Windows
include(DeployQt)
windeployqt(emv-viewer emv_viewer_runtime)
Expand Down

0 comments on commit f802bbc

Please sign in to comment.