Control what is installed / packaged

Yes, that’s a good call and matches blocking system32 on Windows obviously.

This is my general purpose process that I’ve thrown together and use by default:

if(WIN32)
     set(_path_runtime "${CMAKE_INSTALL_BINDIR}")
else()
     set(_path_runtime "${CMAKE_INSTALL_LIBDIR}")
endif()

install(CODE "set(_EXECUTABLE \"$<TARGET_FILE:${_TARGET_NAME}>\")"
    COMPONENT ${_TARGET_NAME}
)
install(CODE "set(_RUNTIME_PATH \"${_path_runtime }\")"
    COMPONENT ${_TARGET_NAME}
)
install(CODE [==[
    file(GET_RUNTIME_DEPENDENCIES
        EXECUTABLES "${_EXECUTABLE}"
        RESOLVED_DEPENDENCIES_VAR _runtime_deps_resolved
        UNRESOLVED_DEPENDENCIES_VAR _runtime_deps_unresolved
        PRE_EXCLUDE_REGEXES
            [=[api-ms-]=] # VC Redistibutable DLLs
            [=[ext-ms-]=] # Windows extension DLLs
            [=[[Qq]t[0-9]+[^\\/]*\.dll]=] # Qt Libs, don't block on Linux since users likely only have older Qt available
        POST_EXCLUDE_REGEXES
            [=[.*system32\/.*\.dll]=] # Windows system DLLs
            [=[^\/(lib|usr\/lib|usr\/local\/lib)]=] # Unix system libraries
    )
    if(_runtime_deps_unresolved)
        foreach(_udep ${_runtime_deps_unresolved})
            message(SEND_ERROR "Failed to resolve dependency: ${_udep}")
        endforeach()
        message(FATAL_ERROR "Unable to resolve all dependencies for executable ${_EXECUTABLE }")
    endif()

    foreach(_rdep ${_runtime_deps_resolved})
        file(INSTALL
          DESTINATION "${CMAKE_INSTALL_PREFIX}/${_RUNTIME_PATH}"
          TYPE SHARED_LIBRARY
          FILES "${_rdep}"
          FOLLOW_SYMLINK_CHAIN
    )
    endforeach()
    ]==]
    COMPONENT ${_TARGET_NAME}
)

I handle Qt DLLs using its macros in a subsequent step and as the comment above suggests I tend to use a lot of custom builds of Qt with newer versions that aren’t available on some distros, so I let the shared libraries for those go through on non-Windows platforms.