[CMake] Question regarding list arguments in macros
James Bigler
jamesbigler at gmail.com
Tue Mar 31 17:57:14 EDT 2009
On Tue, Mar 31, 2009 at 2:06 PM, Allen Gooch <allen.gooch at gmail.com> wrote:
> I have the following macro for generation of c++ source from a proprietary
> IDL language:
>
> macro (oidl_generate IDL_SOURCES IDL_INCLUDE_DIRS)
> message (STATUS "IDL Sources: ${IDL_SOURCES}")
> foreach (idlsrc ${IDL_SOURCES})
> get_filename_component (idlsrc_file ${idlsrc} NAME_WE)
> get_filename_component (idlsrc_path ${idlsrc} PATH)
> set (outsrc_file
> ${CMAKE_CURRENT_BINARY_DIR}/${idlsrc_path}/${idlsrc_file}.cpp)
> set (outsrc_path ${CMAKE_CURRENT_BINARY_DIR}/${idlsrc_path})
> set (omegaprotocols_SOURCES ${omegaprotocols_SOURCES} ${outsrc_file})
> set_source_files_properties ($outsrc_file PROPERTIES OBJECT_DEPENDS
> ${idlsrc})
> set (insrc_file ${CMAKE_CURRENT_SOURCE_DIR}/${idlsrc})
> make_directory (${outsrc_path})
> add_custom_command (
> OUTPUT ${outsrc_file}
> DEPENDS oidl
> COMMAND oidl ${insrc_file} -m -dynamic -O ${outsrc_path}
> ${IDL_INCLUDE_DIRS}
> )
> endforeach ()
> endmacro ()
>
> I call the macro from another CMakeLists.txt file:
>
> include (OidlRules)
> message (STATUS "IDL Sources from protocols:
> ${omegaprotocols_IDL_SOURCES}")
> oidl_generate (${omegaprotocols_IDL_SOURCES}
> ${omegaprotocols_IDL_INCLUDES})
>
> Inside of my macro, the status message indicates that ${IDL_SOURCES} is not
> getting expanded to the full list, but is instead giving me the first
> element of the list I passed in. In my CMakeLists.txt file, before I call
> the macro, status message indicates that the ${omegaprotocols_IDL_SOURCES}
> value is the expected full list. Is anything special required when passing
> lists as arguments to macros?
>
> Many thanks,
> -allen
>
If you want the list to be passed in as a single argument you need to put
quotes around it.
macro(print_args)
message("${ARGC} passed in")
message("ARGV0 = ${ARGV0}")
message("ARGV1 = ${ARGV1}")
message("ARGV2 = ${ARGV2}")
endmacro()
print_args(a b c)
print_args(a "b;c")
set(mylist b c)
print_args(a ${mylist})
print_args(a "${mylist}")
=====================
output:
3 passed in
ARGV0 = a
ARGV1 = b
ARGV2 = c
2 passed in
ARGV0 = a
ARGV1 = b;c
ARGV2 =
3 passed in
ARGV0 = a
ARGV1 = b
ARGV2 = c
2 passed in
ARGV0 = a
ARGV1 = b;c
ARGV2 =
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090331/3030fa8f/attachment.htm>
More information about the CMake
mailing list