Results 1 to 17 of 17

Thread: QMAKE custom DEFINES & CONFIG

  1. #1
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QMAKE custom DEFINES & CONFIG

    Hi,

    I'm new to Qt and its qmake functions. I have read through the Qt Assistant but I do not comprehend everything yet.

    May I know how can we add custom DEFINES & CONFIG in the *.pro and *.pri files?

    E.g.

    Qt Code:
    1. win32 {
    2. }
    3. macx {
    4. }
    To copy to clipboard, switch view to plain text mode 

    If I need a class in Windows only, can I do a *pro file as below? However, it is not working as I expected.

    Qt Code:
    1. win32:DEFINES += WIN32_MYCLASS //(but not working also in qmake)
    2. win32:CONFIG += win32_myclass //(but not working in *.cpp during #ifdef #endif)
    To copy to clipboard, switch view to plain text mode 

    Please advice. Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    If you want different versions of a file be included use:
    Qt Code:
    1. win32 {
    2. INCLUDE += Windows/myfile.h
    3. }
    4. macx {
    5. INCLUDE += Mac/myfile.h
    6. }
    To copy to clipboard, switch view to plain text mode 

    or for different code in one file use

    Qt Code:
    1. MyClass::whatEver()
    2. {
    3. #ifdef Q_OS_UNIX
    4. // do fancy unix stuff
    5. #endif
    6. #ifdef Q_OS_WIN32
    7. // do windows stuff here
    8. #endif
    9. }
    To copy to clipboard, switch view to plain text mode 

    The right code is chosen by the compiler automatically.

  3. #3
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    Thanks, Lykurg for your fast reply! I did understand the part on macx and win32 platform specific codes.

    But, what I mean is that how can I separate the C++ classes under single win32 platform?

    e.g.
    SimpleBuild (contains ClassA only)
    AdvancedBuild (contains ClassA, ClassB, and ClassC)

    I need to do different *pro file that uses different custom configuration to add files.

    Qt Code:
    1. win32:DEFINES += WIN32_ADVANCED
    2. win32:CONFIG += win32_Advanced
    3.  
    4. SUBDIRS += simple_build.pro
    To copy to clipboard, switch view to plain text mode 

    Under SUBDIRS there are WIN32_ADVANCED flags to check whether the class is needed or not.
    Then, under a controller class, there is a #ifdef win32_Advanced flag to include its header.

    Hope this clarify my query.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    Ah, ok. Misread it the first time. Then I would suggest in your pro file:
    Qt Code:
    1. contains(DEFINES, WIN32_ADVANCED) {
    2. message(Building the advanced version...)
    3. }
    To copy to clipboard, switch view to plain text mode 

    with
    Qt Code:
    1. $qmake mypro.pro
    To copy to clipboard, switch view to plain text mode 
    build normal mode, and
    Qt Code:
    1. $qmake "DEFINES += WIN32_ADVANCED" mypro.pro
    To copy to clipboard, switch view to plain text mode 
    building the advanced.

    Hope you mean that

  5. The following user says thank you to Lykurg for this useful post:

    sheeeng (23rd April 2009)

  6. #5
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    Quote Originally Posted by Lykurg View Post
    Ah, ok. Misread it the first time. Then I would suggest in your pro file:
    Qt Code:
    1. contains(DEFINES, WIN32_ADVANCED) {
    2. message(Building the advanced version...)
    3. }
    To copy to clipboard, switch view to plain text mode 

    with
    Qt Code:
    1. $qmake mypro.pro
    To copy to clipboard, switch view to plain text mode 
    build normal mode, and
    Qt Code:
    1. $qmake "DEFINES += WIN32_ADVANCED" mypro.pro
    To copy to clipboard, switch view to plain text mode 
    building the advanced.

    Hope you mean that
    Before the contains, how do we add the WIN32_ADVANCED flag?

    How do we use that '$qmake" in *.pro file? I'm building using MSVC and opens the *.pro file using Qt-VSIntegration.

    Thanks!

  7. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    Quote Originally Posted by sheeeng View Post
    Before the contains, how do we add the WIN32_ADVANCED flag?

    How do we use that '$qmake" in *.pro file? I'm building using MSVC and opens the *.pro file using Qt-VSIntegration.

    Thanks!
    was a little typo: should be
    Qt Code:
    1. $ qmake mypro.pro
    To copy to clipboard, switch view to plain text mode 
    and should be indicate - as I don't have thought someone really is using Windows - that that is to type in the console when you building the app. How To integrate it in MSVC I don't know. To be explicate: You set the WIN32_ADVANCED flag via the console when you building.

  8. #7
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    Thanks, Lykurg. However, I did not able to add the custom DEFINES and custom CONFIG succesfully.

  9. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    Ok, here is a console output which I can't better clarify:
    Qt Code:
    1. lykurg@XXX:~/Dokumente$ cat test.pro
    2. # normal *.pro file here
    3. message(normal stuff)
    4.  
    5. contains(DEFINES, WIN32_ADVANCED) {
    6. message(WIN32_ADVANCED stuff here)
    7. }
    8.  
    9. lykurg@XXX:~/Dokumente$ qmake test.pro
    10. Project MESSAGE: normal stuff
    11.  
    12. lykurg@XXX:~/Dokumente$ qmake "DEFINES += WIN32_ADVANCED" test.pro
    13. Project MESSAGE: normal stuff
    14. Project MESSAGE: WIN32_ADVANCED stuff here
    15.  
    16. lykurg@XXX:~/Dokumente$
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    Thanks Lykurg. I guess I have to convert output to Qt-Windows and then open using Qt-VsIntegration.

  11. #10
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    I think I should rephrase my question...

    How to carry forward "DEFINES += WIN32_ADVANCED" to all *pro under SUBDIRS?

  12. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    global.pro
    Qt Code:
    1. TEMPLATE = subdirs
    2. SUBDIRS = testsub
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. qmake "DEFINES += WIN32_ADVANCED" global.pro
    To copy to clipboard, switch view to plain text mode 
    results in Makefile
    Qt Code:
    1. //..
    2. testsub/$(MAKEFILE):
    3. @$(CHK_DIR_EXISTS) testsub/ || $(MKDIR) testsub/
    4. cd testsub/ && $(QMAKE) testsub.pro -unix DEFINES\ +=\ WIN32_ADVANCED -o $(MAKEFILE)
    5. sub-testsub-qmake_all: FORCE
    6. @$(CHK_DIR_EXISTS) testsub/ || $(MKDIR) testsub/
    7. cd testsub/ && $(QMAKE) testsub.pro -unix DEFINES\ +=\ WIN32_ADVANCED -o $(MAKEFILE)
    8. //..
    To copy to clipboard, switch view to plain text mode 

    just fine

  13. #12
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    Lykurg, thanks a lot for your help on this issue. Appreciated your effort by showing me the solution the UNIX way.
    However, I'm having a hard time to make it work on Qt Visual Studio Integration tool.

    Qt Code:
    1. win32:DEFINES += WIN32_ADVANCED
    2. win32:CONFIG += win32_Advanced
    3.  
    4. SUBDIRS += simple_build.pro //WIN32_ADVANCED and win32_Advanced should be also available inside simple_build.pro
    To copy to clipboard, switch view to plain text mode 

    I do not want to open all the *.pro files and add the WIN32_ADVANCED and win32_Advanced manually.

    Hope someone know how to do it on Windows.
    Last edited by sheeeng; 23rd April 2009 at 14:13.

  14. #13
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    Qt is platform independent so all I have said is also usable under Windows, but if you can't transfer I do It for you:

    c:\global.pro
    TEMPLATE = subdirs
    SUBDIRS = testsub // and all the other subdirs you have
    c:\>qmake "DEFINES += WIN32_ADVANCED" "CONFIG += win32_Advanced" global.pro
    results in:
    ################################################## ###########################
    # Makefile for building: global
    # Generated by qmake (2.01a) (Qt 4.4.3) on: Do 23. Apr 15:45:05 2009
    # Project: ..\global.pro
    # Template: subdirs
    # Command: c:\Qt\4.4.3\bin\qmake.exe -win32 "DEFINES += WIN32_ADVANCED" "CONFIG += win32_Advanced" -o ..\Makefile ..\global.pro
    ################################################## ###########################

    first: make_default
    MAKEFILE = Makefile
    QMAKE = c:\Qt\4.4.3\bin\qmake.exe
    DEL_FILE = del
    CHK_DIR_EXISTS= if not exist
    MKDIR = mkdir
    COPY = copy /y
    COPY_FILE = $(COPY)
    COPY_DIR = xcopy /s /q /y /i
    INSTALL_FILE = $(COPY_FILE)
    INSTALL_PROGRAM = $(COPY_FILE)
    INSTALL_DIR = $(COPY_DIR)
    DEL_FILE = del
    SYMLINK =
    DEL_DIR = rmdir
    MOVE = move
    CHK_DIR_EXISTS= if not exist
    MKDIR = mkdir
    SUBTARGETS = \
    sub-testsub

    testsub\$(MAKEFILE):
    @$(CHK_DIR_EXISTS) testsub\ $(MKDIR) testsub\
    cd testsub\ && $(QMAKE) testsub.pro -win32 "DEFINES += WIN32_ADVANCED" "CONFIG += win32_Advanced" -o $(MAKEFILE)
    sub-testsub-qmake_all: FORCE
    @$(CHK_DIR_EXISTS) testsub\ $(MKDIR) testsub\
    cd testsub\ && $(QMAKE) testsub.pro -win32 "DEFINES += WIN32_ADVANCED" "CONFIG += win32_Advanced" -o $(MAKEFILE)
    sub-testsub: testsub\$(MAKEFILE) FORCE
    cd testsub\ && $(MAKE) -f $(MAKEFILE)
    sub-testsub-make_default: testsub\$(MAKEFILE) FORCE
    cd testsub\ && $(MAKE) -f $(MAKEFILE)
    sub-testsub-make_first: testsub\$(MAKEFILE) FORCE
    cd testsub\ && $(MAKE) -f $(MAKEFILE) first
    sub-testsub-all: testsub\$(MAKEFILE) FORCE
    cd testsub\ && $(MAKE) -f $(MAKEFILE) all
    sub-testsub-clean: testsub\$(MAKEFILE) FORCE
    cd testsub\ && $(MAKE) -f $(MAKEFILE) clean
    sub-testsub-distclean: testsub\$(MAKEFILE) FORCE
    cd testsub\ && $(MAKE) -f $(MAKEFILE) distclean
    sub-testsub-install_subtargets: testsub\$(MAKEFILE) FORCE
    cd testsub\ && $(MAKE) -f $(MAKEFILE) install
    sub-testsub-uninstall_subtargets: testsub\$(MAKEFILE) FORCE
    cd testsub\ && $(MAKE) -f $(MAKEFILE) uninstall

    ..\Makefile: ../global.pro ../Qt/4.4.3/mkspecs/win32-g++/qmake.conf ../Qt/4.4.3/mkspecs/qconfig.pri \
    ../Qt/4.4.3/mkspecs/features/qt_functions.prf \
    ../Qt/4.4.3/mkspecs/features/qt_config.prf \
    ../Qt/4.4.3/mkspecs/features/exclusive_builds.prf \
    ../Qt/4.4.3/mkspecs/features/default_pre.prf \
    ../Qt/4.4.3/mkspecs/features/win32/default_pre.prf \
    ../Qt/4.4.3/mkspecs/features/debug.prf \
    ../Qt/4.4.3/mkspecs/features/debug_and_release.prf \
    ../Qt/4.4.3/mkspecs/features/default_post.prf \
    ../Qt/4.4.3/mkspecs/features/win32/rtti.prf \
    ../Qt/4.4.3/mkspecs/features/win32/exceptions.prf \
    ../Qt/4.4.3/mkspecs/features/win32/stl.prf \
    ../Qt/4.4.3/mkspecs/features/shared.prf \
    ../Qt/4.4.3/mkspecs/features/warn_on.prf \
    ../Qt/4.4.3/mkspecs/features/qt.prf \
    ../Qt/4.4.3/mkspecs/features/win32/thread.prf \
    ../Qt/4.4.3/mkspecs/features/moc.prf \
    ../Qt/4.4.3/mkspecs/features/win32/windows.prf \
    ../Qt/4.4.3/mkspecs/features/resources.prf \
    ../Qt/4.4.3/mkspecs/features/uic.prf \
    ../Qt/4.4.3/mkspecs/features/yacc.prf \
    ../Qt/4.4.3/mkspecs/features/lex.prf
    $(QMAKE) -win32 "DEFINES += WIN32_ADVANCED" "CONFIG += win32_Advanced" -o ..\Makefile ..\global.pro
    ..\Qt\4.4.3\mkspecs\qconfig.pri:
    ..\Qt\4.4.3\mkspecs\features\qt_functions.prf:
    ..\Qt\4.4.3\mkspecs\features\qt_config.prf:
    ..\Qt\4.4.3\mkspecs\features\exclusive_builds.prf:
    ..\Qt\4.4.3\mkspecs\features\default_pre.prf:
    ..\Qt\4.4.3\mkspecs\features\win32\default_pre.prf :
    ..\Qt\4.4.3\mkspecs\features\debug.prf:
    ..\Qt\4.4.3\mkspecs\features\debug_and_release.prf :
    ..\Qt\4.4.3\mkspecs\features\default_post.prf:
    ..\Qt\4.4.3\mkspecs\features\win32\rtti.prf:
    ..\Qt\4.4.3\mkspecs\features\win32\exceptions.prf:
    ..\Qt\4.4.3\mkspecs\features\win32\stl.prf:
    ..\Qt\4.4.3\mkspecs\features\shared.prf:
    ..\Qt\4.4.3\mkspecs\features\warn_on.prf:
    ..\Qt\4.4.3\mkspecs\features\qt.prf:
    ..\Qt\4.4.3\mkspecs\features\win32\thread.prf:
    ..\Qt\4.4.3\mkspecs\features\moc.prf:
    ..\Qt\4.4.3\mkspecs\features\win32\windows.prf:
    ..\Qt\4.4.3\mkspecs\features\resources.prf:
    ..\Qt\4.4.3\mkspecs\features\uic.prf:
    ..\Qt\4.4.3\mkspecs\features\yacc.prf:
    ..\Qt\4.4.3\mkspecs\features\lex.prf:
    qmake: qmake_all FORCE
    @$(QMAKE) -win32 "DEFINES += WIN32_ADVANCED" "CONFIG += win32_Advanced" -o ..\Makefile ..\global.pro

    qmake_all: sub-testsub-qmake_all FORCE

    make_default: sub-testsub-make_default FORCE
    make_first: sub-testsub-make_first FORCE
    all: sub-testsub-all FORCE
    clean: sub-testsub-clean FORCE
    distclean: sub-testsub-distclean FORCE
    -$(DEL_FILE) ..\Makefile
    install_subtargets: sub-testsub-install_subtargets FORCE
    uninstall_subtargets: sub-testsub-uninstall_subtargets FORCE

    sub-testsub-sub_Debug: testsub\\$(MAKEFILE)
    cd testsub\ && $(MAKE) debug
    debug: sub-testsub-sub_Debug

    sub-testsub-sub_Release: testsub\\$(MAKEFILE)
    cd testsub\ && $(MAKE) release
    release: sub-testsub-sub_Release

    mocclean: compiler_moc_header_clean compiler_moc_source_clean

    mocables: compiler_moc_header_make_all compiler_moc_source_make_all
    install: install_subtargets FORCE

    uninstall: uninstall_subtargets FORCE

    FORCE:
    Look:
    testsub\$(MAKEFILE):
    @$(CHK_DIR_EXISTS) testsub\ $(MKDIR) testsub\
    cd testsub\ && $(QMAKE) testsub.pro -win32 "DEFINES += WIN32_ADVANCED" "CONFIG += win32_Advanced" -o $(MAKEFILE)
    c:\>make
    be happy...


    ...or I don't get your problem.

  15. The following user says thank you to Lykurg for this useful post:

    sheeeng (23rd April 2009)

  16. #14
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    Thanks, Lykurg! Felt so bad to trouble you on this simple task.
    I think the problem is not with us. It is with the Qt Visual Studio Integration. I just open *pro using Visual Studio by Qt | Open Qt *pro file and it will generate the Visual Studio *sln and *proj files for us.
    I did not use any qmake or make commands when building Qt. It was taken care of by the integration tool.
    I do feel that this should NOT be a big issue.
    Anyway, thanks a lot! Really appreciate your pointers!

  17. #15
    Join Date
    Jan 2012
    Location
    St. Petersburg, Russia
    Posts
    14
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: QMAKE custom DEFINES & CONFIG

    I faced the same problem. I would like to forward a definition into each subdir mentioned in my .pro file:

    Qt Code:
    1. DEFINES += SOME_VERY_COMMON_MACRO
    2. TEMPLATE = subdirs
    3. SUBDIRS = testsub
    To copy to clipboard, switch view to plain text mode 

    But unfortunately it doesn't work! SOME_VERY_COMMON_MACRO is not forwarded to testsub Makefile.

    Lykurg's solution is enough, but it's less convenient: it makes me write build instructions for other project developers. And it makes them read it . I think there must be simpler solution.
    Last edited by monst; 12th January 2012 at 14:08.

  18. #16
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    I haven't time to check it right now myself, but as an other possibility you can create a *.pri file and include it once in each other *.pro file. This is a one time work and then you only have to alter the *.pri file. Thus nobody has to read your build instructions.

  19. The following user says thank you to Lykurg for this useful post:

    monst (12th January 2012)

  20. #17
    Join Date
    Jan 2012
    Location
    St. Petersburg, Russia
    Posts
    14
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: QMAKE custom DEFINES & CONFIG

    Yes, that will do. But in my case one of sub directories is something like a third party project, and I don't want to modify its .pro files.
    All I want is to provide a macro definition to a compiler when I build a whole project. Maybe I want a strange thing .

Similar Threads

  1. qmake sux a lot
    By singermornings in forum Qt Programming
    Replies: 6
    Last Post: 29th January 2009, 08:33
  2. qmake and CONFIG copy_dir_files
    By Vanir in forum Qt Programming
    Replies: 0
    Last Post: 25th February 2008, 14:56
  3. Adding custom defines when on debug build
    By chus in forum Qt Programming
    Replies: 2
    Last Post: 2nd March 2007, 11:38
  4. Custom action added to make by qmake
    By NTwoO in forum Qt Programming
    Replies: 2
    Last Post: 2nd March 2007, 10:17
  5. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57

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.