[CMake] Location of ui and moc generated files (qt)

Maik Keller atracks at gmx.de
Tue Aug 14 10:37:52 EDT 2007


Thank you Torsten!
If I would exchange CMAKE_CURRENT_BINARY_DIR for CMAKE_CURRENT_SOURCE_DIR in your macro and if I would also add CMAKE_CURRENT_SOURCE_DIR to my include directories, then it should work the way as I need the generated files in my source-directory. Or do I miss something?

Best,
Mick


-------- Original-Nachricht --------
Datum: Tue, 14 Aug 2007 16:01:27 +0200
Von: Torsten Martinsen <tma at gatehouse.dk>
An: "Maik Keller" <atracks at gmx.de>
CC: cmake at cmake.org
Betreff: RE: [CMake] Location of ui and moc generated files (qt)

> Maik Keller <> wrote:
> 
> > Hi Alex,
> > 
> > I prefer to use the class, which is contained in the automatically
> > generated ui-header file, as a base class for an extended
> > implementation of the widget. Therefore I have to include the header
> > of that class. So it would be nice to locate the base class in the
> > same directory like the derived class (somewhere in my sources - and
> > not in the build-directory).     
> > 
> > In case of the moc-file it is not that important. But it would be
> > also nice to have the location under the control of the user. 
> > 
> > Would there be a possibility to use cmake's "ADD_CUSTOM_COMMAND"? I
> > appreciate any help of defining such custom commands for ui and moc
> > files. I tried it on my own, but I failed...  
> 
> As a reference point, here is the macro I use:
> 
> # Run Qt UIC on a UI file.
> # Arguments:
> #    1-N   Names of .ui files
> MACRO(AIS_UI)
>    FOREACH (it ${ARGN})
>       GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
>       SET(outhfile ${CMAKE_CURRENT_BINARY_DIR}/${outfile}.h)
>       SET(outcppfile ${CMAKE_CURRENT_BINARY_DIR}/${outfile}_uic.cpp)
>       ADD_CUSTOM_COMMAND(OUTPUT ${outhfile}
>          COMMAND ${QT_UIC_EXECUTABLE} ARGS -o ${outhfile}
> ${CMAKE_CURRENT_SOURCE_DIR}/${it}
>          WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
>          MAIN_DEPENDENCY ${it}
>          DEPENDS ${it}
>       )
>       ADD_CUSTOM_COMMAND(OUTPUT ${outcppfile}
>          COMMAND ${QT_UIC_EXECUTABLE} ARGS
> ${CMAKE_CURRENT_SOURCE_DIR}/${it} -impl ${outhfile} -o ${outcppfile}
> 	 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
>          MAIN_DEPENDENCY ${it}
> 	 DEPENDS ${it} ${outhfile})
> 	SET(CPP_SOURCE ${CPP_SOURCE} ${outcppfile})
>       AIS_MOC(${outhfile})
> 
>       SET(AIS_UIC_SOURCES ${AIS_UIC_SOURCES} ${outcppfile})
>       LIST(APPEND AIS_UIC_HEADERS ${outhfile})
>    ENDFOREACH (it)
> ENDMACRO(AIS_UI)
> 
> Note that this also generates the header file out-of-source - therefore
> I have this line in another macro:
> 
>    INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
> 
> (This macro is used in all my projects).
> 
> -Torsten
> 

-- 
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail


More information about the CMake mailing list