[CMake] Trouble using QT_WRAP_* in out-of-source builds

Sören Freudiger muffmolch at gmx.de
Fri Sep 2 12:01:45 EDT 2005


Hi Dave
we had have a similar problem.
because of this I first made a core solution to this and after that I
defined two macros

this will create the header, cpp and moc file whereever you want. don't
forget to put these files to the ADDITIONAL_CLEAN_FILES, then they will be
deleted at clean.

usage:
QT_WRAP_CPP3(/home/source/folder/MOC GENERATED_MOC_FILES
/home/source/folder/neddToBeMoced.h)

QT_WRAP_UI3(/home/source/folder/header 
            /home/source/folder/CPP 
		/home/source/folder/MOC
            GENERATED_HEADER_FILES
            GENERATED_CPP_FILES
            GENERATED_MOC_FILES       
            /home/source/folder/test1.ui /home/source/folder/test2.ui)

I think it's easy to understand hoe the macros are working.
You can fit them to your problem!

SirAnn

CMakeQtMacros.txt:
---------------------------------------
IF(NOT QT_FOUND)
  INCLUDE(${CMAKE_ROOT}/Modules/FindQt.cmake)
ENDIF(NOT QT_FOUND)


################################################################
###                     QT_WRAP_CPP3                         ###
### QT_WRAP_CPP3 outdirectory outfiles infileList)           ###
################################################################
MACRO(QT_WRAP_CPP3 outdirectory outfiles)
  MAKE_DIRECTORY(outdirectory)
  FOREACH(infile ${ARGN}) #ARGN is infiles-list!!!
    GET_FILENAME_COMPONENT(outname ${infile} NAME_WE)
    SET(outfile ${outdirectory}/${outname}MOC.cpp)
    ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
		       PRE_BUILD
                       COMMAND ${QT_MOC_EXECUTABLE}
                       ARGS -o ${outfile} ${infile}
                       MAIN_DEPENDENCY ${infile})
    SET(${outfiles} ${${outfiles}} ${outfile})
  ENDFOREACH(infile ${infiles})
  SET(GENERATED_FILES ${GENERATED_FILES} ${${outfiles}})
ENDMACRO(QT_WRAP_CPP3)

################################################################
###                     QT_WRAP_UI3                          ###
### QT_WRAP_UI3(houtdir   cppoutdir   mocoutdir              ###
###             houtfiles cppoutfiles mocoutfiles)           ###
###             infileList(=.ui files)             )         ###
################################################################
MACRO(QT_WRAP_UI3 houtdir cppoutdir mocoutdir houtfiles cppoutfiles
mocoutfiles)
  FOREACH(infile ${ARGN}) #ARGN is infiles-list!!!
    GET_FILENAME_COMPONENT(filename_we ${infile} NAME_WE)
    ########## HEADER ######################################
    SET(houtfile ${houtdir}/${filename_we}.h)
    ADD_CUSTOM_COMMAND(OUTPUT  ${houtfile}
                       PRE_BUILD
                       COMMAND ${QT_UIC_EXECUTABLE}
                       ARGS -o ${houtfile} ${infile}
                       DEPENDS ${infile}
    )
    SET(${houtfiles} ${${houtfiles}} ${houtfile})
    ########## CPP #########################################
    SET(cppoutfile ${cppoutdir}/${filename_we}.cpp)
    ADD_CUSTOM_COMMAND(OUTPUT  ${cppoutfile}
                       PRE_BUILD
                       COMMAND ${QT_UIC_EXECUTABLE}
                       ARGS ${infile} -i ${houtfile} -o ${cppoutfile}
                       DEPENDS ${infile}
    )
    SET(${cppoutfiles} ${${cppoutfiles}} ${cppoutfile})
    ########## MOC #########################################
    SET(mocoutfile ${mocoutdir}/${filename_we}MOC.cpp)
    ADD_CUSTOM_COMMAND(OUTPUT ${mocoutfile}
		       PRE_BUILD
                       COMMAND ${QT_MOC_EXECUTABLE}
                       ARGS -o ${mocoutfile} ${houtfile}
                       MAIN_DEPENDENCY ${houtfile})
    SET(${mocoutfiles} ${${mocoutfiles}} ${mocoutfile})
  ENDFOREACH(infile ${infiles})
  SET(GENERATED_FILES ${GENERATED_FILES} ${${houtfiles}} ${${cppoutfiles}}
${${mocoutfiles}})
ENDMACRO(QT_WRAP_UI3)


-----Ursprüngliche Nachricht-----
Von: cmake-bounces+muffmolch=gmx.de at cmake.org
[mailto:cmake-bounces+muffmolch=gmx.de at cmake.org] Im Auftrag von David
Flitney
Gesendet: Freitag, 2. September 2005 17:16
An: cmake at cmake.org
Betreff: [CMake] Trouble using QT_WRAP_* in out-of-source builds

My project uses Qt and I'm getting a problem with compilation of the uic
generated .h sources. These are created in the build tree but the include
paths aren't being set to reflect this so when, later in the build, the
header gets included in a source file it doesn't get found.

An in-source build works fine.

OS: MacOSX Tiger
CMake: version 2.3-20050831

--
Cheers, Dave

Dave Flitney, IT Manager
Oxford Centre for Functional MRI of the Brain E:flitney at fmrib.ox.ac.uk
W:+44-1865-222713 F:+44-1865-222717
URL: http://www.fmrib.ox.ac.uk/~flitney

_______________________________________________
CMake mailing list
CMake at cmake.org
http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list