Hi,

 

I wrote this macro to generate my ui.[ch] and moc files in my source
directory. Use it as a QT4_WRAP_UI replacement.

The macro also creates a "ui" target which generates all these files.

(Note: I use it with Qt 3, and did not check if uic is used the same way
on Qt 4.

 

 

#-----------------------------------------------------------------------
----

# ui (in)         : name of the list containing ui files

# headers (in+out): name of the list containing

#     - in : user headers containing Q_OBJECT macro

#     - out: in value + headers generated from ui files

# sources (out)   : name of the list containing generated c++ files

#-----------------------------------------------------------------------
----

macro(k_gen_qt_code ui headers sources)

    set_directory_properties(PROPERTIES CLEAN_NO_CUSTOM true) # don't
remove installed includes on make clean

      set(dest ${CMAKE_CURRENT_SOURCE_DIR})

    foreach(ui_name ${${ui}})

        string(REGEX REPLACE "ui$" "h" header ${ui_name})

        string(REGEX REPLACE "ui$" "cxx" source ${ui_name})

 

            add_custom_command(

                  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${header}

            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}

                  COMMAND ${QT_UIC} ${ui_name} -o ${header}

                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${ui_name}

                  COMMENT "Generating
${CMAKE_CURRENT_SOURCE_DIR}/${header}"

             )

            set (${headers} ${${headers}} ${header})

 

            add_custom_command(

                  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${source}

            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}

                  COMMAND ${QT_UIC} ${ui_name} -impl ${header} -o
${source}

                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${ui_name}

                  COMMENT "Generating
${CMAKE_CURRENT_SOURCE_DIR}/${source}"

             )

            set (${sources} ${${sources}} ${source})

 

    endforeach(ui_name)

 

    # headers contains

    #   - headers generated from ui files

    #   - headers initially given by the user because they contain
Q_OBJECT macro

    foreach(header ${${headers}})

        string(REGEX REPLACE "h$" "cxx" moc ${header})

        set(moc "moc_${moc}")

            add_custom_command(

                  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${moc}

            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}

                  COMMAND ${QT_MOC} ${header} -o ${moc}

                  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${header}

                  COMMENT "Generating
${CMAKE_CURRENT_SOURCE_DIR}/${moc}"

             )

            set (${sources} ${${sources}} ${moc})

 

    endforeach(header)

 

      add_custom_target(ui

            DEPENDS ${${sources}} ${${headers}}

      )

endmacro()

 

 

Cordialement / Regards,

Alexandre 



________________________________

From: [email protected] [mailto:[email protected]] On Behalf
Of Ivan Chupahin
Sent: Thursday, 02 April 2009 11:47
To: [email protected]
Subject: [CMake] Output directory for genereated ui_Header.h files

 

Hi,folks!

My project uses Qt4 and i need to generate *.h files from *.ui files.
For that i use QT4_WRAP_UI macro. But it generete *.h files in a
derectory where CMake is running. Maybe exist some CMake variable for
point an output directory for that generated files or some other tools? 



This email was sent to you by Thomson Reuters, the global news and information 
company.
Any views expressed in this message are those of the individual sender, except 
where the sender specifically states them to be the views of Thomson Reuters.

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to