Patch to add two more automoc4 convenience macros
Matthias Kretz
kretz at kde.org
Wed Jul 30 08:15:44 CEST 2008
On Tuesday 29 July 2008 23:01:47 Alexander Neundorf wrote:
> On Tuesday 29 July 2008, Matthias Kretz wrote:
> > Hi,
> >
> > for all the automoc4 users that cannot use KDE4Macros.cmake I'd like to
> > add the following two macros:
>
> The names should be AUTOMOC4_ADD_EXECUTABLE() and AUTOMOC4_ADD_LIBRARY(),
> so they conform to the cmake modules style guide.
Right, I thought about it after sending the mail.
> > macro(ADD_AUTOMOC4_EXECUTABLE _target_NAME)
> > set(_SRCS ${ARGN})
> >
> > set(_add_executable_param)
> > foreach(_argName "WIN32" "MACOSX_BUNDLE" "EXCLUDE_FROM_ALL")
> > list(GET _SRCS 0 _arg)
> > if(_arg STREQUAL _argName)
> > list(APPEND _add_executable_param ${_argName})
> > list(REMOVE_AT _SRCS 0)
> > endif(_arg STREQUAL _argName)
> > endforeach(_argName)
>
> I think that loop isn't perfect.
> automoc4_add_executable(foo EXCLUDE_FROM_ALL WIN32 ${sources})
> Here WIN32 will be ignored, right ?
> It may make sense to add a special function for that to the cmake LIST()
> command.
cmake --help-command add_executable
[...]
add_executable(<name> [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL]
source1 source2 ... sourceN)
This is why I replaced "LIST(FIND _SRCS ${_argName}" with "LIST(GET _SRCS 0",
but I guess my interpretation that the order has to be followed was stupid. I
was just afraid that a list(FIND would be slower than necessary.
New version:
macro(AUTOMOC4_ADD_EXECUTABLE _target_NAME)
set(_SRCS ${ARGN})
set(_add_executable_param)
foreach(_argName "WIN32" "MACOSX_BUNDLE" "EXCLUDE_FROM_ALL")
list(FIND _SRCS ${_argName} _index)
if(_index GREATER -1)
list(APPEND _add_executable_param ${_argName})
list(REMOVE_AT _SRCS ${_index})
endif(_index GREATER -1)
endforeach(_argName)
if(MSVC)
add_automoc4_target("${_target_NAME}_automoc" _SRCS)
else(MSVC)
automoc4(${_target_NAME} _SRCS)
endif(MSVC)
add_executable(${_target_NAME} ${_add_executable_param} ${_SRCS})
if(MSVC)
add_dependencies(${_target_NAME} "${_target_NAME}_automoc")
endif(MSVC)
endmacro(AUTOMOC4_ADD_EXECUTABLE)
macro(AUTOMOC4_ADD_LIBRARY _target_NAME)
set(_SRCS ${ARGN})
set(_add_executable_param)
foreach(_argName "STATIC" "SHARED" "MODULE" "EXCLUDE_FROM_ALL")
list(FIND _SRCS ${_argName} _index)
if(_index GREATER -1)
list(APPEND _add_executable_param ${_argName})
list(REMOVE_AT _SRCS ${_index})
endif(_index GREATER -1)
endforeach(_argName)
if(MSVC)
add_automoc4_target("${_target_NAME}_automoc" _SRCS)
else(MSVC)
automoc4(${_target_NAME} _SRCS)
endif(MSVC)
add_library(${_target_NAME} ${_add_executable_param} ${_SRCS})
if(MSVC)
add_dependencies(${_target_NAME} "${_target_NAME}_automoc")
endif(MSVC)
endmacro(AUTOMOC4_ADD_LIBRARY)
--
________________________________________________________
Matthias Kretz (Germany) <><
http://Vir.homelinux.org/
MatthiasKretz at gmx.net, kretz at kde.org,
Matthias.Kretz at urz.uni-heidelberg.de
More information about the Kde-buildsystem
mailing list