aboutsummaryrefslogtreecommitdiff
path: root/cmake/AddDllCopyCommands.cmake
blob: b32215adc8f3e3348d350255ee049e47618e5e5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
macro (addDllCopyCommand target sourceDebug sourceRelease)
    add_custom_command(TARGET ${target} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "$<$<CONFIG:Debug>:${sourceDebug}>$<$<CONFIG:Release>:${sourceRelease}>$<$<CONFIG:RelWithDebInfo>:${sourceRelease}>$<$<CONFIG:MinSizeRel>:${sourceRelease}>"
        $<TARGET_FILE_DIR:${target}>)
endmacro()

macro (addBoostDllCopyCommand target ignored sourceReleaseLib ignored sourceDebugLib)
    string(REGEX REPLACE ".lib$" ".dll" sourceReleaseDll ${sourceReleaseLib})
    string(REGEX REPLACE "/libboost" "/boost" sourceReleaseDll2 ${sourceReleaseDll})

    string(REGEX REPLACE ".lib$" ".dll" sourceDebugDll ${sourceDebugLib})
    string(REGEX REPLACE "/libboost" "/boost" sourceDebugDll2 ${sourceDebugDll})
    addDllCopyCommand(${target} ${sourceDebugDll2} ${sourceReleaseDll2})
endmacro()

# Checks if the given list contains an entry which matches the given regex.
function(listContainsRegex result list regex)
    set(${result} 0 PARENT_SCOPE)
    foreach(element ${list})
        if(${element} MATCHES ${regex})
            set(${result} 1 PARENT_SCOPE)
            return()
        endif()
    endforeach()
endfunction()

macro(addDllCopyCommands target)
    if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
        # Get the list of dependencies for the given target, so we can copy just the DLLs we need.
        get_target_property(target_deps_str ${target} LINK_LIBRARIES)
        set(target_deps)
        list(APPEND target_deps ${target_deps_str})

        cmake_policy(SET CMP0057 NEW) # Enable the "IN_LIST" operator

        # armnn.dll
        if ("armnn" IN_LIST target_deps)
            addDllCopyCommand(${target} "$<TARGET_FILE_DIR:armnn>/armnn.dll" "$<TARGET_FILE_DIR:armnn>/armnn.dll")
        endif()

        # armnnTfLiteParser.dll
        if ("armnnTfLiteParser" IN_LIST target_deps)
            addDllCopyCommand(${target} "$<TARGET_FILE_DIR:armnnTfLiteParser>/armnnTfLiteParser.dll"
                                        "$<TARGET_FILE_DIR:armnnTfLiteParser>/armnnTfLiteParser.dll")
        endif()
    endif()
endmacro()