How to prepend all filenames on the list with common path?

后端 未结 6 1831
孤城傲影
孤城傲影 2020-12-16 09:05

How can I prepend all filenames on the list with a common path prefix automatically? For instance having a list of files in CMakeLists.txt:

SET(SRC_FILES foo         


        
6条回答
  •  孤街浪徒
    2020-12-16 09:31

    As an improvement to Ding-Yi Chen's answer, if you still need to support pre-3.12 CMake as I do, you can use following code:

    function(list_transform_prepend var prefix)
        set(temp "")
        foreach(f ${${var}})
            list(APPEND temp "${prefix}${f}")
        endforeach()
        set(${var} "${temp}" PARENT_SCOPE)
    endfunction()
    

    Advantage of this solution is, that interface is closer to one is CMake 3.12 list(TRANSFORM ...) and the change is done in-place.

    Used like this

    list_transform_prepend(FILES_TO_TRANSLATE "${CMAKE_CURRENT_SOURCE_DIR}/")
    

提交回复
热议问题