[CMake] the list parameter passed to function
Petr Kmoch
petr.kmoch at gmail.com
Mon May 28 03:45:49 EDT 2012
On Sun, May 27, 2012 at 3:23 PM, Marmot Ken <realwangbo at gmail.com> wrote:
> Sorry. Copy-paste error kicks my ass.
>
>
> Output expected :
>
> SRC_LIST : ./a.cpp;./c.cpp;./main.cpp
> src_list_in : ./a.cpp;./c.cpp;./main.cpp
>
> Now i got the solution.
>
> invoke the function like this :
>
> AUX_SOURCE_DIRECTORY( . SRC_LIST )
> MESSAGE( SRC_LIST " : ${SRC_LIST} " )
>
> Append_headers_to_src_list( SRC_LIST "${SRC_LIST}"
> ${CMAKE_SOURCE_DIR}/include/test )
>
> Question is :
> Why?
Because cmake is a text-based scripting language and for backward
compatibility reasons, list elements (including in argument lists) can
be separated either by space or semi-colon. Therefore, the call
Append_headers_to_src_list(SRC_LIST ${SRC_LIST}
${CMAKE_SOURCE_DIR}/include/test)
expands to:
Append_headers_to_src_list(SRC_LIST ./a.cpp;./c.cpp;./main.cpp
the_source_dir/include/test)
(where the_source_dir is your value of CMAKE_SOURCE_DIR), which is
equivalent to:
Append_headers_to_src_list(SRC_LIST ./a.cpp ./c.cpp ./main.cpp
the_source_dir/include/test)
So the function paramteres are assigned as follows:
src_list_out: SRC_LIST
src_list_in: ./a.cpp
header_file_path_in: ./c.cpp
ARGN: ./main.cpp;the_source_dir/include/test
(ARGN is the list of "arguments past last named parameter").
You have two solutions: one is the one you already use (pass the
in-list quoted), the other would be to require the in-list to always
be stored in a variable and pass only the name of the variable.
Hope this helps,
Petr
>
>
> 2012/5/22 Petr Kmoch <petr.kmoch at gmail.com>
>>
>> Hi,
>>
>> try as I might, I can't see a difference between the output and
>> expected output. Perhaps a copy-paste error?
>>
>> Petr
>>
>> On Tue, May 22, 2012 at 3:07 AM, Marmot Ken <realwangbo at gmail.com> wrote:
>> > here is the function :
>> >
>> > FUNCTION( Append_headers_to_src_list src_list_out src_list_in
>> > header_file_path_in )
>> > MESSAGE( src_list_in " : ${src_list_in}" )
>> > FILE( GLOB_RECURSE TEMP_LIST ${header_file_path_in}/*.h )
>> > SET( ${src_list_out} ${src_list_in} ${TEMP_LIST} PARENT_SCOPE )
>> > ENDFUNCTION( Append_headers_to_src_list
>> >
>> >
>> > here is the place where the function is invoked:
>> >
>> > AUX_SOURCE_DIRECTORY( . SRC_LIST )
>> > MESSAGE( SRC_LIST " : ${SRC_LIST} " )
>> >
>> > Append_headers_to_src_list( SRC_LIST ${SRC_LIST}
>> > ${CMAKE_SOURCE_DIR}/include/test )
>> >
>> > here is output :
>> >
>> > SRC_LIST : ./a.cpp;./c.cpp;./main.cpp
>> > src_list_in : ./a.cpp
>> >
>> > Output expected :
>> >
>> > SRC_LIST : ./a.cpp;./c.cpp;./main.cpp
>> > src_list_in : ./a.cpp
>> >
>> > Question:
>> > <1> how to get expected Output ?
>> > <2> why ?
>> >
>> > Thanks.
>> >
>> > --
>> >
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Please keep messages on-topic and check the CMake FAQ at:
>> > http://www.cmake.org/Wiki/CMake_FAQ
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://www.cmake.org/mailman/listinfo/cmake
>
>
More information about the CMake
mailing list