使用CMake的install命令重命名现有文件

时间:2018-09-22 16:46:55

标签: cmake

构建项目后,有一个tensorflowd.dll(由CMake安装)文件,我想在另一个CMake安装步骤中将其重命名为tensorflow.dll文件。是否可以仅重命名文件(不将其作为同一命令的一部分安装?)

还是我必须在安装tensorflowd.dll文件本身的过程中进行重命名?

评论中提到的

install_lib宏:

#general macro suitable for small libs where you don't want to pick and choose which dlls get installed
#separates all dlls into two lists and if debug versions are present it uses that or if it's not
# it uses the release ones instead
function(INSTALL_LIB libname)

    if(NOT "${${libname}_FOUND}" STREQUAL "TRUE")
        message("Library ${libname} is not present and cannot be installed.")
        return()
    endif()


    FILELIST(files "${${libname}_BINARY_DIRS}")


    #filter out non dll files
    foreach(file ${files})

        string(REGEX MATCH "^.*.dll$" result ${file})

        if(NOT result STREQUAL "")
            list(APPEND dll_files ${file})
        endif()

    endforeach()

    #message("${files}")

    #find if it has debug or is it only release dll that is present..
    foreach(file ${dll_files})

        string(REGEX MATCH "^.*d\\.dll$" result ${file})

        if(result STREQUAL "")
            list(APPEND optimized_libs ${file})
        else()          
            list(APPEND debug_libs ${file})
        endif()

        #workaround for edge case with libs ending with 'd' and debug versions with 'dd'
        #upon detecting XXXdd.lib the coresponding XXXd.lib must be already in optimized_libs
        #so take it from there and place it into correct list.
        string(REGEX REPLACE "^(.*d)d\\.lib$" "\\1" dd_result ${file})
            #message("${filename} ${dd_result}")

        if(NOT dd_result STREQUAL "" AND NOT ${dd_result} STREQUAL ${file})
            #message("${filename} ${dd_result}")
            list(REMOVE_ITEM debug_libs "${dd_result}.dll")
            list(APPEND optimized_libs "${dd_result}.dll")
        endif()

        set(dd_result "")
        set(result "")

    endforeach()

    list(LENGTH debug_libs debug_length)
    list(LENGTH optimized_libs optimized_length)

    #If there are debug version but their count is not on par with release version, raise a red flag.
    if(NOT "${debug_length}" EQUAL "${optimized_length}" AND "${debug_length}" GREATER 0)
        message(WARNING "Counts of debug and optimized dlls of library ${libname} are different from each other..")
    endif()

    if("${debug_length}" GREATER 0)   

        foreach(item ${debug_libs})
            install(FILES ${${libname}_BINARY_DIRS}/${item} DESTINATION Debug           CONFIGURATIONS Debug)
        endforeach()

        foreach(item ${optimized_libs})
            install(FILES ${${libname}_BINARY_DIRS}/${item} DESTINATION RelWithDebInfo  CONFIGURATIONS RelWithDebInfo)
            install(FILES ${${libname}_BINARY_DIRS}/${item} DESTINATION Release         CONFIGURATIONS Release) 
        endforeach()

    else()

        foreach(item ${optimized_libs})
            install(FILES ${${libname}_BINARY_DIRS}/${item} DESTINATION Debug           CONFIGURATIONS Debug)
            install(FILES ${${libname}_BINARY_DIRS}/${item} DESTINATION RelWithDebInfo  CONFIGURATIONS RelWithDebInfo)
            install(FILES ${${libname}_BINARY_DIRS}/${item} DESTINATION Release         CONFIGURATIONS Release) 
        endforeach()

    endif()
endfunction()

0 个答案:

没有答案