[CMake] CMake is Converting lists to strings

J Decker d3ck0r at gmail.com
Wed Jun 12 06:22:30 EDT 2019


I know... just need to rebuild a new list... something like....

 set( _ALL_INCLUDES )
foreach( INC ${ALL_INCLUDES})
    string(REPLACE "../" "" INC ${INC})
    LIST( APPEND _ALL_INCLUDES ${INC} )
endforeach( INC )
set( ALL_INCLUDES ${_ALL_INCLUDES})

On Wed, Jun 12, 2019 at 3:10 AM J Decker <d3ck0r at gmail.com> wrote:

> I'm collecting sources and includes into a parent scope variable, and then
> attempting to use that variable to reference the right sources.
> Sources get added to the list as ../(theirpath)/(source) so in the parent
> level I can simply replace "../" with "" and then they are relative in the
> right place.
> This works; as far as, the includes, sources and defines get all collected
> into the top level, but when i try to remove the ../ the list gets
> converted into a string.
>
> # Create a list of things
> set( SIMPLE_LIST -I../lib1/include -I../lib2/include -I../lib3/include )
> # set a variable using that list...
>   set( AMALG_COMMAND echo ${SIMPLE_LIST}  )
> # this outputs
> COMMAND:echo;-I../lib1/include;-I../lib2/include;-I../lib3/include
>   message( "COMMAND:${AMALG_COMMAND}")
>
> # replace ../ with nothing
> STRING( REPLACE "../" "" SIMPLE_LIST ${SIMPLE_LIST} )
> # re-set a variable with the eventual command to run
>   set( AMALG_COMMAND echo ${SIMPLE_LIST}  )
> # this outputs COMMAND:echo;-Ilib1/include -Ilib2/include -Ilib3/include
>   message( "COMMAND:${AMALG_COMMAND}")
>
> When that final command actually gets run in a
>   add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/out.c   COMMAND
> ${AMALG_COMMAND}  )
>
> Then the command is 'echo "-Ilib1/include -Ilib2/include -Ilib3/include"'
> which is incorrect.
>
>
> I tried first LIST(JOIN) but that defiantly makes a string and doesn't
> help.
> string(REPLACE " " ";" SIMPLE_LIST ${SIMPLE_LIST})  to try and reverse it
> back to a list doesn't seem to help...
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190612/df8d605d/attachment.html>


More information about the CMake mailing list