Results 1 to 7 of 7

Thread: Passing global defines to moc

  1. #1
    Join Date
    Feb 2006
    Posts
    8
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Passing global defines to moc

    Hi all. We are building an embedded application. On the target a QT application runs. There is however also other processes running that are written in C. We have customer specific requirements that we differentiate via defines. To avoid editing the defines in each subsection, I have environment variables that I set. According to these environment variables, the code is built.

    If the defines are added to QMAKE_CXX_RELEASE, then they are automatically added to the CFLAGS in the generated Makefile. This is then handled at compiletime and all is fine.

    Unfortunately the moc compiler only looks at $(DEFINES) and at $(INCLUDE). How can I add my list (-DBLA -DBLAH) to the DEFINES without prepending another -D? Alternatively, how can I pass the defines directly to the moc compiler?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing global defines to moc

    Maybe move the defines from QMAKE_CXX_RELEASE to the proper place?
    For example create a separate variable that will hold all these defines and tell QMake to add the contents of this variable to DEFINES.

  3. #3
    Join Date
    Feb 2006
    Posts
    8
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Passing global defines to moc

    I would love to do that, but that would mean one of the following:
    1: use a scripting language to edit my .pro file before compilation.
    2: pass empty/ undefined variables to DEFINES (that provides problems with redefined variables, but that can be solved with undefine)
    3: get some information from you how I should get the DEFINES to pack out my list literally without prepending a -D
    Hope you can help.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing global defines to moc

    Quote Originally Posted by NTwoO View Post
    1: use a scripting language to edit my .pro file before compilation.
    What for?
    2: pass empty/ undefined variables to DEFINES (that provides problems with redefined variables, but that can be solved with undefine)
    Again, why?

    3: get some information from you how I should get the DEFINES to pack out my list literally without prepending a -D
    You would have to explain exactly what you want, because from my point of view the thing I think you want is easy to do and from your point of view it sounds complicated, so we might be speaking about completely different two things

    Could you please explain what effect you want to achieve? Then we can talk about solutions...

  5. #5
    Join Date
    Feb 2006
    Posts
    8
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Passing global defines to moc

    Let the code do the talking...

    Qt Code:
    1. PRO_VER=1
    2. UI_COMPILE_DEFINES="set"
    3. CRIPTLIB="n"
    4. QVFB="n"
    5. LOCALE="US"
    6.  
    7. export UI_COMPILE_DEFINES
    8. export CRIPTLIB
    9. export QVFB
    10. export LOCALE
    11. export PRO_VER
    To copy to clipboard, switch view to plain text mode 

    this is sourced to set the environment variables.

    next up, I have makefile in my project to preprocess some steps. This consequently calls Makefile, the file generated by qmake. This is to automate my versioning and environment variables.

    Qt Code:
    1. ifneq ($(UI_COMPILE_DEFINES),set)
    2. all:
    3. @echo "*** The User interface environment variables aren't correctly set ***"; \
    4. echo " try sourcing UIDEFS.sh"
    5. exit 1
    6. boot: all
    7. else #ifneq ($(UI_COMPILE....
    8. ifeq ($(PRO_VER),1)
    9. UIFCFLAGS += -DPRO_VER1
    10. endif
    11. ifeq ($(PRO_VER),2)
    12. UIFCFLAGS += -DPRO_VER2
    13. endif
    14. ifeq ($(PRO_VER),3)
    15. UIFCFLAGS += -DPRO_VER3
    16. endif
    17. ifeq ($(ALPR),y)
    18. UIFCFLAGS += -DALPR
    19. endif
    20. ifeq ($(QVFB),y)
    21. UIFCFLAGS += -DQVFB
    22. endif
    23. ifeq ($(LOCALE),US)
    24. UIFCFLAGS += -DVER_US
    25. endif
    26. ifeq ($(LOCALE),UK)
    27. UIFCFLAGS += -DVER_UK
    28. endif
    29. ifeq ($(LOCALE),NL)
    30. UIFCFLAGS += -DVER_NL
    31. endif
    32. ifeq ($(LOCALE),BE)
    33. UIFCFLAGS += -DVER_BE
    34. endif
    35. ifeq ($(DRAFTLABLE),y)
    36. UIFCFLAGS += -DDODRAFT
    37. endif
    38. export UIFCFLAGS
    39. all: version
    40. make -f Makefile $@
    41. install: first
    42. #rm ./install/usr/bin/*
    43. make -f Makefile $@
    44. clean:
    45. make -f Makefile $@
    46. distclean:
    47. make -f Makefile $@
    48.  
    49. first: all
    50. boot: all
    51. version:
    52. ifeq ($(PRO_VER),1)
    53. make -e -C VersionPRO1
    54. endif
    55. ifeq ($(PRO_VER),2)
    56. make -e -C VersionPRO2
    57. endif
    58. ifeq ($(PRO_VER),3)
    59. make -e -C VersionPRO3
    60. endif
    61.  
    62. endif
    63. ~
    64. ~
    65. "makefile" [converted] 67L, 1181C 61,2-9 All
    To copy to clipboard, switch view to plain text mode 

    The exported UIFCFLAGS should then be added to the $DEFINES in the generated Makefile.

    I tried to add them by using DEFINES += $(UIFCFLAGS), but this only generates the the following in the generated Makefile.

    Qt Code:
    1. DEFINES = -D$(UIFCFLAGS)
    To copy to clipboard, switch view to plain text mode 

    which does not work.

    Adding them to the QMAKE_CFLAGS means the moc misses them.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing global defines to moc

    The way I see it you'd have to regenerate the Makefile, for example like this:

    qmake UICFLAGS=....
    make -f Makefile

    and in the project file add:

    DEFINES += $UICFLAGS

    Of course get rid of the -D prefix when filling the UIFCFLAGS variable.

    An alternative way is to alter the way moc works:

    new_moc.output = moc_${QMAKE_FILE_BASE}.cpp
    new_moc.commands = moc ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} ${QMAKE_CXX_RELEASE}
    new_moc.depends = g++ -E -M ${QMAKE_FILE_NAME} | sed "s,^.*: ,,"
    new_moc.input = HEADERS
    QMAKE_EXTRA_UNIX_COMPILERS += new_moc

  7. #7
    Join Date
    Feb 2006
    Posts
    8
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Passing global defines to moc

    Quote Originally Posted by wysota View Post
    The way I see it you'd have to regenerate the Makefile, for example like this:

    qmake UICFLAGS=....
    make -f Makefile
    I'll check out what the options are when passing the variables to qmake.

    Quote Originally Posted by wysota View Post
    and in the project file add:

    DEFINES += $UICFLAGS

    Of course get rid of the -D prefix when filling the UIFCFLAGS variable.
    Shabby of me to write the project example with a -D

    The problem is if my $UIFCFLAGS is set to "-DPRO_VER1 -DQVFB -DVER_US"
    and added to the defines using
    DEFINES += $(UIFCFLAGS)
    it is expanded to "-D-DPRO_VER1 -DQVFB -DVER_US"
    if however it is defined as "PRO_VER1 QVFB VER_US"
    it is expanded to
    "-DPRO_VER1 QVFB VER_US"

    Quote Originally Posted by wysota View Post
    An alternative way is to alter the way moc works:

    new_moc.output = moc_${QMAKE_FILE_BASE}.cpp
    new_moc.commands = moc ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} ${QMAKE_CXX_RELEASE}
    new_moc.depends = g++ -E -M ${QMAKE_FILE_NAME} | sed "s,^.*: ,,"
    new_moc.input = HEADERS
    QMAKE_EXTRA_UNIX_COMPILERS += new_moc
    This might just be the option I would end with. I'll check this out. Hopefully I can get this running:w

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.