Skip to content

Commit

Permalink
Install library dependencies for Windows builds
Browse files Browse the repository at this point in the history
Use CMake's RUNTIME_DEPENDENCY_SET feature to generate and install
library dependencies like json-c and boost for iso8859 and emv_strings.
This approach was more robust than CMake's IMPORTED_RUNTIME_ARTIFACTS
because the latter only installs the imported artifact and not the
artifact's dependencies, which is especially problematic for boost.

It is unknown whether any of this would work for non-MSYS2 builds
because the search paths may differ for other environments.
  • Loading branch information
leonlynch committed Nov 15, 2024
1 parent c4f7fed commit 3eec2b2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ install(
TARGETS
iso8859
EXPORT emvUtilsTargets # For use by install(EXPORT) command
RUNTIME_DEPENDENCY_SET iso8859_deps
PUBLIC_HEADER
DESTINATION "include/iso8859"
COMPONENT emv_development
Expand All @@ -242,6 +243,22 @@ install(
ARCHIVE
COMPONENT emv_development
)
if(WIN32 AND ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21")
# Assume that MSYS2/MinGW environments have all DLLs in the same path
# as the compiler
get_filename_component(COMPILER_PATH ${CMAKE_CXX_COMPILER} PATH)
install(
RUNTIME_DEPENDENCY_SET iso8859_deps
PRE_EXCLUDE_REGEXES
"api-ms-"
POST_EXCLUDE_REGEXES
"system32"
DIRECTORIES
${COMPILER_PATH}
RUNTIME
COMPONENT emv_runtime
)
endif()

# EMV library
add_library(emv
Expand Down Expand Up @@ -349,6 +366,7 @@ install(
TARGETS
emv_strings
EXPORT emvUtilsTargets # For use by install(EXPORT) command
RUNTIME_DEPENDENCY_SET emv_strings_deps
PUBLIC_HEADER
DESTINATION "include/emv"
COMPONENT emv_development
Expand All @@ -360,3 +378,19 @@ install(
ARCHIVE
COMPONENT emv_development
)
if(WIN32 AND ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21")
# Assume that MSYS2/MinGW environments have all DLLs in the same path
# as the compiler
get_filename_component(COMPILER_PATH ${CMAKE_CXX_COMPILER} PATH)
install(
RUNTIME_DEPENDENCY_SET emv_strings_deps
PRE_EXCLUDE_REGEXES
"api-ms-"
POST_EXCLUDE_REGEXES
"system32"
DIRECTORIES
${COMPILER_PATH}
RUNTIME
COMPONENT emv_runtime
)
endif()

0 comments on commit 3eec2b2

Please sign in to comment.