Results 1 to 8 of 8

Thread: Preventing UI_HEADERS_DIR from being added to include path

  1. #1
    Join Date
    Aug 2010
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Question Preventing UI_HEADERS_DIR from being added to include path

    Hi,

    I have a mid scale project which i recently decided to move from lumbering netbeans to qtcreator and change the build system to qmake. It consists of a core library, a gui library, various tests and executables.

    Directory structure goes like this

    Qt Code:
    1. libcore
    2. string.h
    3. signal.h
    4. a.h
    5. b.h
    6. a.cpp
    7. b.cpp
    8. libgui
    9. widget_a.h
    10. widget_a.cpp
    11. form_a.ui
    12. form_a.h
    13. form_a.cpp
    14. form_b.ui
    15. form_b.h
    16. form_b.cpp
    17. tests and executables
    18. test directory
    19. test_a.h
    20. test_a.cpp
    21. executable directory
    22. exe_a.h
    23. exe_a.cpp
    To copy to clipboard, switch view to plain text mode 

    As you can see, i have some header names like "string.h" and "signal.h" and because of that, when a library is built, it is supposed to go into build directory like this.

    Qt Code:
    1. build_direcotory
    2. include
    3. tbs
    4. string.h
    5. signal.h
    6. widget_a.h
    7. ui_widget_a.h // Generated as result of uic causes directory
    8. // to be added to include path
    9. etc...
    10. lib
    11. libcore.a
    To copy to clipboard, switch view to plain text mode 

    To achieve this, i have an pri file and a function in it. (macro / test ?)
    which does configuration _almost_ correctly

    Qt Code:
    1. # ----------------------------------------------------------------------------
    2. header_copy.input = HEADERS
    3. header_copy.commands = @$$QMAKE_COPY ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
    4. header_copy.output = ../include/tbs/${QMAKE_FILE_BASE}.h
    5.  
    6. # ----------------------------------------------------------------------------
    7. defineTest(configuration) {
    8. target_name = $$1
    9. target_type = $$2
    10. output_directory = $$3
    11.  
    12. TARGET = $$target_name
    13. INCLUDEPATH = $$output_directory/include
    14. LIBS += -L$$output_directory/lib
    15.  
    16. contains(target_type, lib) {
    17. TEMPLATE = lib
    18. CONFIG += staticlib
    19. DESTDIR = $$output_directory/lib
    20. UI_DIR = $$output_directory/obj/ui
    21. #UI_HEADERS_DIR = $$output_directory/include/tbs
    22. QMAKE_EXTRA_COMPILERS += header_copy
    23. }
    24. else:contains(target_type, exe) {
    25. DESTDIR = $$output_directory/bin
    26. TEMPLATE = app
    27. debug {
    28. CONFIG += console
    29. }
    30. }
    31.  
    32. export(TARGET)
    33. export(TEMPLATE)
    34. export(CONFIG)
    35. export(DESTDIR)
    36. export(UI_DIR)
    37. export(UI_HEADERS_DIR)
    38. export(INCLUDEPATH)
    39. export(LIBS)
    40. export(HEADERS)
    41. export(QMAKE_EXTRA_COMPILERS)
    42. }
    To copy to clipboard, switch view to plain text mode 

    Which is called from each "pro" file like this
    Qt Code:
    1. include (../tbs_desktop.pri)
    2. configuration(tbs, lib, ..)
    To copy to clipboard, switch view to plain text mode 

    This does most of the job as intended. However the commented out line which places generated headers to their correct place, also adds that directory to include path. Resulting headers like "string.h" and "signal.h" to be included from standart library and Qt in place of intended headers. Creating a thousand lines long compile time mess.

    I've tried :

    Qt Code:
    1. INCLUDEPATH -= $$UI_HEADERS_DIR
    To copy to clipboard, switch view to plain text mode 
    which had no effect, and attempted to replace command that executes uic with

    Qt Code:
    1. # ----------------------------------------------------------------------------
    2. UIC.input = FORMS
    3. UIC.commands = @$$QMAKE_UIC ${QMAKE_FILE_NAME} -o ../include/tbs/${QMAKE_FILE_BASE}.h && echo ehore
    4. UIC.output = ../include/tbs/${QMAKE_FILE_BASE}.h
    5. QMAKE_EXTRA_COMPILERS += UIC
    To copy to clipboard, switch view to plain text mode 
    but this created another mess.

    Is there a way to prevent UI_HEADERS_DIR from being added to include path or any other way to work around this issue?

    * autotools is not an option as it is not really cross platform. (it requires a full blown unix environment to work)
    * CMake is an option but it requires re-write of build system and i'm a total newbie to it.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Preventing UI_HEADERS_DIR from being added to include path

    Do I understand you right that you want to have a separate build dir?
    If so, use OBJECTS_DIR = ... in your .pro file.

  3. #3
    Join Date
    Aug 2010
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Preventing UI_HEADERS_DIR from being added to include path

    Do I understand you right that you want to have a separate build dir?
    Uh.. no. I'm already building in to a seperate dir. I just want to prevent the direcotry pointed by UI_HEADERS_DIR to being added to INCLUDEPATH.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Preventing UI_HEADERS_DIR from being added to include path

    Sorry for asking stupid questions, but I don't understand your problem.
    Are you trying to build separate targets? Why do you want to copy headers?

    Edit: well, I do understand what your problem is, but not why.

  5. #5
    Join Date
    Aug 2010
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Preventing UI_HEADERS_DIR from being added to include path

    As i said, i have two types of libraries, core and gui. Let's say core library (libtbs) has a signal class resides in "signal.h" and "signal.cpp" both are in "source/libtbs" directory. To use signal class from within signal.cpp or any other file within core library i'm including it like #include "signal.h"

    That's ok. But when i need to use signal class from one of the unit tests or from a gui library, #include "signal.h" will not work. Since they are not in the same directory. Adding "source/libtbs" to include path (-I../libtbs) will not work either as "signal.h" from libtbs and "signal.h" of POSIX will be included in place of each other... So, the headers of libtbs must be copied to "builddir/include/tbs" and "builddir/include" must be added to include path then users of core library can include and use "signal.h" as #include <tbs/signal.h>

    Setting UI_HEADERS_DIR to builddir/include/tbs also enables -I builddir/include/tbs causing "signal.h" of core library to be included in place of POSIX one.

  6. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Preventing UI_HEADERS_DIR from being added to include path

    Wouldn't it be easier to just rename your signal.h to tbs_signal.h ? Then you have no collisions to worry about and can just use the paths as normal without copying header files around.

  7. #7
    Join Date
    Aug 2010
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Preventing UI_HEADERS_DIR from being added to include path

    It is. However this will move signal.h from it's own _namespace_ to global one. ( #include <tbs/signal.h> | #include <tbs_signal.h> ) breaking source consistency with previous versions etc... Isn't it correct way to shape the build system for project instead of shaping the project for build system?

  8. #8
    Join Date
    Aug 2010
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Preventing UI_HEADERS_DIR from being added to include path

    I've managed to solve the problem by overriding uic.

    The key point is disabling the uic by adding "CONFIG -= uic" then using a custom compiler. I'm posting both full configuration file and another that uses it.

    pri file.

    Qt Code:
    1. # Public domain.
    2. # Turns off warnings about strict aliasing
    3. QMAKE_CXXFLAGS += -Wstrict-aliasing=0 -Wno-unused-parameter
    4. CONFIG += no_include_pwd silent
    5. CONFIG -= uic
    6.  
    7. # ----------------------------------------------------------------------------
    8. # Header copier
    9. header_copy.input = HEADERS
    10. header_copy.CONFIG += no_link target_predeps
    11. header_copy.variable_out = GENERATED_FILES
    12.  
    13. # ----------------------------------------------------------------------------
    14. # UI compiler
    15. tbsuic.input = FORMS
    16. tbsuic.variable_out = GENERATED_FILES
    17. tbsuic.CONFIG += no_link target_predeps
    18.  
    19. # ----------------------------------------------------------------------------
    20. defineTest(configuration) {
    21. target_name = $$1
    22. target_type = $$2
    23. output_directory = $$3
    24.  
    25. TARGET = $$target_name
    26. INCLUDEPATH = $$output_directory/include
    27. LIBS += -L$$output_directory/lib
    28. UI_DIR = $$output_directory/obj/ui
    29. UI_HEADERS_DIR = $$output_directory/include/tbs
    30. QMAKE_EXTRA_COMPILERS += tbsuic header_copy
    31.  
    32. # Relative part of header _compiler_
    33. header_copy.output = $$output_directory/include/tbs/${QMAKE_FILE_BASE}.h
    34. header_copy.commands = @$$QMAKE_COPY ${QMAKE_FILE_NAME} ${QMAKE_FILE_OUT}
    35.  
    36. # Relative part of ui compiler
    37. tbsuic.output = $$output_directory/include/tbs/ui_${QMAKE_FILE_BASE}.h
    38. tbsuic.commands = @$$QMAKE_UIC ${QMAKE_FILE_NAME} -o $$output_directory/include/tbs/ui_${QMAKE_FILE_BASE}.h
    39.  
    40. contains(target_type, lib) {
    41. TEMPLATE = lib
    42. CONFIG += staticlib
    43. DESTDIR = $$output_directory/lib
    44. }
    45. else:contains(target_type, exe) {
    46. DESTDIR = $$output_directory/bin
    47. TEMPLATE = app
    48. debug {
    49. CONFIG += console
    50. }
    51. }
    52.  
    53. export(TARGET)
    54. export(TEMPLATE)
    55. export(CONFIG)
    56. export(DESTDIR)
    57. export(UI_DIR)
    58. export(UI_HEADERS_DIR)
    59. export(INCLUDEPATH)
    60. export(LIBS)
    61. export(HEADERS)
    62. export(header_copy.output)
    63. export(header_copy.commands)
    64. export(tbsuic.output)
    65. export(tbsuic.commands)
    66. export(QMAKE_EXTRA_COMPILERS)
    67. }
    To copy to clipboard, switch view to plain text mode 


    Pro file that uses configuration file
    Qt Code:
    1. include (../tbs_desktop.pri) #Inclusion
    2.  
    3. #First parameter is target's name, second is it's type, and third is source root relative
    4. #to project
    5. configuration(tbs_forms, lib, ..)
    6.  
    7. SOURCES += \
    8. point_list_model.cpp \
    9. tabular_data_editor.cpp \
    10. route_editor.cpp \
    11. .....
    12.  
    13. HEADERS += \
    14. vertex.h \
    15. tabular_data_editor.h \
    16. route_editor.h \
    17. point_list_model.h \
    18. ...
    19.  
    20. FORMS += \
    21. route_editor.ui \
    22. line_property_editor.ui \
    23. .....
    To copy to clipboard, switch view to plain text mode 


    "CONFIG -= uic" is suggested at irc.freenode.net#qt by someone which his/her nick name is
    eluding my memory at the moment.

Similar Threads

  1. Replies: 8
    Last Post: 17th October 2009, 08:10
  2. Include path question
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 28th September 2009, 13:21
  3. Include path confusion in Qt with Eclipse
    By PUK_999 in forum Installation and Deployment
    Replies: 0
    Last Post: 20th August 2009, 20:56
  4. g++ include path
    By LMZ in forum Newbie
    Replies: 2
    Last Post: 8th May 2007, 13:45
  5. Set include file path in KDevelop
    By zlatko in forum KDE Forum
    Replies: 2
    Last Post: 16th January 2006, 11:12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.