Discussion:
[CMake] Location of ui and moc generated files (qt)
Maik Keller
2007-08-14 08:57:20 UTC
Permalink
Hello,

I'd like to use cmake for my upcoming project. I am going to use qt also.
At the moment I use the QT4_WRAP_UI macro in CMake.

I am wondering about the name and the location of the generated moc and ui files. Is it possible to rename these files (by default ui_...) and to determine another location (by default the build-directory)?

Thanks a lot!

Best,
Mick
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
Alexander Neundorf
2007-08-14 12:24:56 UTC
Permalink
Post by Maik Keller
Hello,
I'd like to use cmake for my upcoming project. I am going to use qt also.
At the moment I use the QT4_WRAP_UI macro in CMake.
I am wondering about the name and the location of the generated moc and ui
files. Is it possible to rename these files (by default ui_...) and to
determine another location (by default the build-directory)?
Currently that's not possible.
Why do you need this ?

Bye
Alex
Maik Keller
2007-08-14 13:53:26 UTC
Permalink
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...

Thanks,
Mick




-------- Original-Nachricht --------
Datum: Tue, 14 Aug 2007 08:24:56 -0400
Von: Alexander Neundorf <a.neundorf-***@gmx.net>
An: ***@cmake.org
Betreff: Re: [CMake] Location of ui and moc generated files (qt)
Post by Alexander Neundorf
Post by Maik Keller
Hello,
I'd like to use cmake for my upcoming project. I am going to use qt
also.
Post by Maik Keller
At the moment I use the QT4_WRAP_UI macro in CMake.
I am wondering about the name and the location of the generated moc and
ui
Post by Maik Keller
files. Is it possible to rename these files (by default ui_...) and to
determine another location (by default the build-directory)?
Currently that's not possible.
Why do you need this ?
Bye
Alex
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
Torsten Martinsen
2007-08-14 14:01:27 UTC
Permalink
Post by Maik Keller
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

This e-mail and any files sent with it contain information that may be privileged or confidential and is the property of the GateHouse Group. This information is intended solely for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use the message or any part thereof. If you have received this e-mail in error, please notify the sender immediately, and delete all copies of this message. In accordance with GateHouse Security Policy, e-mails sent or received may be monitored.
Maik Keller
2007-08-14 14:37:52 UTC
Permalink
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 <***@gatehouse.dk>
An: "Maik Keller" <***@gmx.de>
CC: ***@cmake.org
Betreff: RE: [CMake] Location of ui and moc generated files (qt)
Post by Torsten Martinsen
Post by Maik Keller
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...
# Run Qt UIC on a UI file.
# 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
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
Torsten Martinsen
2007-08-14 14:47:14 UTC
Permalink
Post by Maik Keller
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.
Yes.

-Torsten

This e-mail and any files sent with it contain information that may be privileged or confidential and is the property of the GateHouse Group. This information is intended solely for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use the message or any part thereof. If you have received this e-mail in error, please notify the sender immediately, and delete all copies of this message. In accordance with GateHouse Security Policy, e-mails sent or received may be monitored.
Maik Keller
2007-08-14 15:31:28 UTC
Permalink
Thanks Torsten. I just tested it, and it seems to work with CMAKE_CURRENT_SOURCE_DIR. Would it be possible to provide me with your implementation of the AIS_MOC macro as well?

Thanks again!

Best,
Mick


-------- Original-Nachricht --------
Datum: Tue, 14 Aug 2007 16:47:14 +0200
Von: Torsten Martinsen <***@gatehouse.dk>
An: "Maik Keller" <***@gmx.de>
CC: ***@cmake.org
Betreff: RE: [CMake] Location of ui and moc generated files (qt)
Post by Torsten Martinsen
Post by Maik Keller
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.
Yes.
-Torsten
This e-mail and any files sent with it contain information that may be
privileged or confidential and is the property of the GateHouse Group. This
information is intended solely for the person to whom it is addressed. If you
are not the intended recipient, you are not authorized to read, print,
retain, copy, disseminate, distribute, or use the message or any part thereof.
If you have received this e-mail in error, please notify the sender
immediately, and delete all copies of this message. In accordance with GateHouse
Security Policy, e-mails sent or received may be monitored.
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
Alexander Neundorf
2007-08-14 15:49:10 UTC
Permalink
Post by Maik Keller
Thanks Torsten. I just tested it, and it seems to work with
CMAKE_CURRENT_SOURCE_DIR. Would it be possible to provide me with your
implementation of the AIS_MOC macro as well?
If you are working on a bigger project with more developers, you shouldn't
generate the files in the source directory. You or other developers will
sooner or later use out-of-source builds, which will break due to the
generated files in the source tree.

There is no real need to have the generated headers in the same dir as the
other source files.

Bye
Alex
Maik Keller
2007-08-14 15:52:55 UTC
Permalink
Hi,

but I need to include the generated header file in my derived class file. How do I do this if the generated file is not in one of my source directories?

Thanks,
Maik



-------- Original-Nachricht --------
Datum: Tue, 14 Aug 2007 11:49:10 -0400
Von: Alexander Neundorf <a.neundorf-***@gmx.net>
An: ***@cmake.org
Betreff: Re: [CMake] Location of ui and moc generated files (qt)
Post by Alexander Neundorf
If you are working on a bigger project with more developers, you shouldn't
generate the files in the source directory. You or other developers will
sooner or later use out-of-source builds, which will break due to the
generated files in the source tree.
There is no real need to have the generated headers in the same dir as the
other source files.
Bye
Alex
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
Alexander Neundorf
2007-08-14 16:11:34 UTC
Permalink
Post by Maik Keller
Hi,
but I need to include the generated header file in my derived class file.
How do I do this if the generated file is not in one of my source
directories?
You can add CMAKE_CURRENT_BINARY_DIRECTORY as include directory or set the
cmake variable CMAKE_INCLUDE_CURRENT_DIR to true so cmake does that
automatically.

Alex
Maik Keller
2007-08-14 16:32:34 UTC
Permalink
Ok - I thought about the solution which is already provided by cmake. Probably it is a good moment to change the organization of my own files and directories. I give it a try :-)

Now there is only one thing left I worry about: because of all the generated files the build-directory seems to look like a mess. I mean e.g. using Visual Studio the solution file (.sln) is also in the same directory with the automatically generated files. So the build directory is a bit chaotic. And in large projects this directory can contain an enormous number of (generated) files...

Or is there any other possibility to avoid this? Maybe by defining a variable/directory for all the generated files in general?

Thank you guys for the quick and competent help!

-Mick



-------- Original-Nachricht --------
Datum: Tue, 14 Aug 2007 12:11:34 -0400
Von: Alexander Neundorf <a.neundorf-***@gmx.net>
An: "Maik Keller" <***@gmx.de>
CC: ***@cmake.org
Betreff: Re: [CMake] Location of ui and moc generated files (qt)
Post by Alexander Neundorf
Post by Maik Keller
Hi,
but I need to include the generated header file in my derived class
file.
Post by Maik Keller
How do I do this if the generated file is not in one of my source
directories?
You can add CMAKE_CURRENT_BINARY_DIRECTORY as include directory or set the
cmake variable CMAKE_INCLUDE_CURRENT_DIR to true so cmake does that
automatically.
Alex
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger
Marie-Christine Vallet
2007-08-14 16:23:15 UTC
Permalink
Post by Maik Keller
Hi,
but I need to include the generated header file in my derived class file. How do I do this if the generated file is not in one of my source directories?
Thanks,
Maik
Yes, but you don't need to change the location with cmake. I am also
working with a qt project and my ui_files are generated in my bin
directory, and they are refered to in the inherited class and it works
just fine.
Marie
Marie-Christine Vallet
2007-08-14 16:25:48 UTC
Permalink
Post by Marie-Christine Vallet
Post by Maik Keller
Hi,
but I need to include the generated header file in my derived class
file. How do I do this if the generated file is not in one of my
source directories?
Thanks,
Maik
Yes, but you don't need to change the location with cmake. I am also
working with a qt project and my ui_files are generated in my bin
directory, and they are refered to in the inherited class and it works
just fine.
Marie
_______________________________________________
CMake mailing list
http://www.cmake.org/mailman/listinfo/cmake
This is an example of my cmakelistfile in src

SET ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake"
) #required to find my custom features

#include my custom cmake features
INCLUDE ( MacroLogFeature )
# INCLUDE ( FindQGLViewer )

#include required packages
FIND_PACKAGE ( Qt4 REQUIRED ) # find and setup Qt4 for this project)
FIND_PACKAGE ( QGLViewer REQUIRED )
FIND_PACKAGE ( GMP REQUIRED )
FIND_PACKAGE(M REQUIRED)
FIND_PACKAGE(GL REQUIRED)
FIND_PACKAGE(GLU REQUIRED)



# the next line sets up include and link directories and defines some
variables that we will use.
# you can modify the behavior by setting some variables, ee.g.
SET ( QT_USE_OPENGL TRUE )
SET ( QT_USE_QTXML TRUE )
# -> this will cause cmake to include and link against the OpenGL module
INCLUDE (
${QT_USE_FILE}
)

SET(LIBRARIES
${QT_LIBRARIES}
${QT_QTOPENGL_LIBRARIES}
${QGLVIEWER_LIBRARY}
${PROJECT_LIBRARIES}
${GMP_LIBRARIES}
${M_LIBRARIES}
${GL_LIBRARIES}
${GLU_LIBRARIES}
)
SET(INCLUDE_DIR
${CMAKE_CURRENT_BINARY_DIR}
${QT_INCLUDE_DIR}
${QT_QTOPENGL_INCLUDE_DIR}
${QT_INCLUDE_DIR}
${GMP_INCLUDE_DIR}
${M_INCLUDE_DIR}
${GL_INCLUDE_DIR}
${GLU_INCLUDE_DIR}

)# Make sure the compiler can find include files from our Hello library.
SET(SKINMESH_LIBRARIES
${LIBRARY_OUTPUT_PATH}/libskinmesh.a
)
SET(SKINMESH_INCLUDE_DIR
${CMAKE_SOURCE_DIR}/skinmesh
)
SET (INCLUDE_DIR
${INCLUDE_DIR}
${SKINMESH_INCLUDE_DIR}
)
SET(LIBRARIES
${LIBRARIES}
${SKINMESH_LIBRARIES}
)
#@TODO do this another way
FIND_LIBRARY(C_LIBRARIES NAMES g2c
PATHS
/usr/lib/*
/usr/lib/*/*/*
/usr/local/lib/*
)
#add a library to the existing list
SET(LIBRARIES ${LIBRARIES}
${C_LIBRARIES})



#VARIABLE INITIALISATION

# the variable "mdi_SRCS" contains all .cpp files of this project
SET ( mdi_SRCS
main.cpp
mainwindow.cpp
csbdmainwindow.cpp
mdichild.cpp
csbdmdichild.cpp
csbdqglviewer.cpp
)

#header files
SET ( mdi_MOC_HDRS
mainwindow.h
csbdmainwindow.h
mdichild.h
csbdmdichild.h
csbdqglviewer.h


)
#resource files
SET ( mdi_RCCS
mdi.qrc
qt4skinmesh.qrc
)

#.ui files
SET ( mdi_UIS
mainwindow.ui
mdichild.ui
)




#If you need cmake to generate ui*.h files from .ui files then you need
to use QT4_WRAP_UI

QT4_WRAP_UI ( mdi_UIS_H ${mdi_UIS} )

# generate rules for building source files from the resources
QT4_ADD_RESOURCES ( mdi_RCC_SRCS ${mdi_RCCS} )


# After this call, foo_MOC_SRCS = moc_Class1.cxx moc_Class2.cxx
moc_Class3.cxx.
QT4_WRAP_CPP ( mdi_MOC_SRCS ${mdi_MOC_HDRS} )


# tell cmake to create .moc files for all files in the variable mdi_SRCS
that require such a file.
# note: this assumes that you use #include "header.moc" in your files
QT4_AUTOMOC ( ${mdi_SRCS} )

SET(mdi_EXECUTABLE
${mdi_SRCS}
${mdi_UIS_H}
${mdi_MOC_SRCS}
${mdi_RCC_SRCS}
)

# Don't forget to include output directory, otherwise
# the UI file won't be wrapped!
# include_directories ( )

# create an executable file named "mdi" from the source files in the
variable "mdi_SRCS".
ADD_EXECUTABLE ( mdi
${mdi_EXECUTABLE}
)


INCLUDE_DIRECTORIES(${INCLUDE_DIR})
# link the "mdi" target against the Qt libraries. which libraries
exactly, is defined by the "include(${QT_USE_FILE})" line above, which
sets up this variable.INCLUDE_DIRECTORIES(
TARGET_LINK_LIBRARIES ( mdi
${LIBRARIES}
)
Torsten Martinsen
2007-08-15 06:35:35 UTC
Permalink
Post by Maik Keller
Thanks Torsten. I just tested it, and it seems to work with
CMAKE_CURRENT_SOURCE_DIR. Would it be possible to provide me with
your implementation of the AIS_MOC macro as well?
Here it is:

# Run Qt MOC on a C++ header file.
# Arguments:
# 1-N Names of headerfiles
MACRO(AIS_MOC)
FOREACH (it ${ARGN})
# Make .h filename absolute
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)

# Build x_moc.cpp filename
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/${outfile}_moc.cpp)

# Run MOC
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND ${QT_MOC_EXECUTABLE}
ARGS ${infile} -o ${outfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${infile}
COMMENT MOCing ${it})
LIST(APPEND CPP_SOURCE ${outfile})
LIST(APPEND AIS_MOC_SOURCES ${outfile})
ENDFOREACH(it)
ENDMACRO(AIS_MOC)

This e-mail and any files sent with it contain information that may be privileged or confidential and is the property of the GateHouse Group. This information is intended solely for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use the message or any part thereof. If you have received this e-mail in error, please notify the sender immediately, and delete all copies of this message. In accordance with GateHouse Security Policy, e-mails sent or received may be monitored.
Loading...