Debian Codegraph @

qmake/doc/snippets/code/doc_src_qmake-manual.pro

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4 #! [0]
5 make all
6 #! [0]
7
8
9 #! [1]
10 CONFIG += qt debug
11 #! [1]
12
13
14 #! [2]
15 QT += network xml
16 #! [2]
17
18
19 #! [3]
20 QT = network xml # This will omit the core and gui modules.
21 #! [3]
22
23
24 #! [4]
25 QT -= gui # Only the core module is used.
26 #! [4]
27
28
29 #! [5]
30 CONFIG += link_pkgconfig
31 PKGCONFIG += ogg dbus-1
32 #! [5]
33
34
35 #! [6]
36 LIBS += -L/usr/local/lib -lmath
37 #! [6]
38
39
40 #! [7]
41 INCLUDEPATH = c:/msdev/include d:/stl/include
42 #! [7]
43
44
45 #! [8]
46 qmake [mode] [options] files
47 #! [8]
48
49
50 #! [9]
51 qmake -makefile [options] files
52 #! [9]
53
54
55 #! [10]
56 qmake -makefile -o Makefile "CONFIG+=test" test.pro
57 #! [10]
58
59
60 #! [11]
61 qmake "CONFIG+=test" test.pro
62 #! [11]
63
64
65 #! [12]
66 qmake -project [options] files
67 #! [12]
68
69
70 #! [13]
71 qmake -spec macx-g++
72 #! [13]
73
74
75 #! [14]
76 LIBS += -F/path/to/framework/directory/
77 #! [14]
78
79
80 #! [15]
81 LIBS += -framework TheFramework
82 #! [15]
83
84
85 #! [16]
86 TEMPLATE = lib
87 CONFIG += lib_bundle
88 #! [16]
89
90
91 #! [17]
92 FRAMEWORK_HEADERS.version = Versions
93 FRAMEWORK_HEADERS.files = path/to/header_one.h path/to/header_two.h
94 FRAMEWORK_HEADERS.path = Headers
95 QMAKE_BUNDLE_DATA += FRAMEWORK_HEADERS
96 #! [17]
97
98
99 #! [19]
100 qmake -spec macx-xcode project.pro
101 #! [19]
102
103
104 #! [20]
105 qmake -tp vc
106 #! [20]
107
108
109 #! [21]
110 qmake -tp vc -r
111 #! [21]
112
113
114 #! [22]
115 CONFIG -= embed_manifest_exe
116 #! [22]
117
118
119 #! [23]
120 CONFIG -= embed_manifest_dll
121 #! [23]
122
123
124 #! [24]
125 make all
126 #! [24]
127
128
129 #! [25]
130 build_pass:CONFIG(debug, debug|release) {
131 unix: TARGET = $$join(TARGET,,,_debug)
132 else: TARGET = $$join(TARGET,,,d)
133 }
134 #! [25]
135
136
137 #! [26]
138 CONFIG += console newstuff
139 ...
140 newstuff {
141 SOURCES += new.cpp
142 HEADERS += new.h
143 }
144 #! [26]
145
146
147 #! [27]
148 DEFINES += USE_MY_STUFF
149 #! [27]
150
151
152 #! [30]
153 DESTDIR = ../../lib
154 #! [30]
155
156
157 #! [31]
158 DISTFILES += ../program.txt
159 #! [31]
160
161
162 #! [32]
163 FORMS = mydialog.ui \
164 mywidget.ui \
165 myconfig.ui
166 #! [32]
167
168
169 #! [34]
170 HEADERS = myclass.h \
171 login.h \
172 mainwindow.h
173 #! [34]
174
175
176 #! [35]
177 INCLUDEPATH = c:/msdev/include d:/stl/include
178 #! [35]
179
180
181 #! [36]
182 target.path += $$[QT_INSTALL_PLUGINS]/imageformats
183 INSTALLS += target
184 #! [36]
185
186
187 #! [37]
188 LEXSOURCES = lexer.l
189 #! [37]
190
191
192 #! [38]
193 unix:LIBS += -L/usr/local/lib -lmath
194 win32:LIBS += c:/mylibs/math.lib
195 #! [38]
196
197
198 #! [39]
199 CONFIG += no_lflags_merge
200 #! [39]
201
202
203 #! [40]
204 unix:MOC_DIR = ../myproject/tmp
205 win32:MOC_DIR = c:/myproject/tmp
206 #! [40]
207
208
209 #! [41]
210 unix:OBJECTS_DIR = ../myproject/tmp
211 win32:OBJECTS_DIR = c:/myproject/tmp
212 #! [41]
213
214
215 #! [43]
216 FRAMEWORK_HEADERS.version = Versions
217 FRAMEWORK_HEADERS.files = path/to/header_one.h path/to/header_two.h
218 FRAMEWORK_HEADERS.path = Headers
219 QMAKE_BUNDLE_DATA += FRAMEWORK_HEADERS
220 #! [43]
221
222
223 #! [44]
224 QMAKE_BUNDLE_EXTENSION = .myframework
225 #! [44]
226
227
228 #! [45]
229 QMAKE_RESOURCE_FLAGS += -threshold 0 -compress 9
230 #! [45]
231
232
233 #! [47]
234 QT -= gui # Only the core module is used.
235 #! [47]
236
237
238 #! [48]
239 unix:RCC_DIR = ../myproject/resources
240 win32:RCC_DIR = c:/myproject/resources
241 #! [48]
242
243
244 #! [49]
245 SOURCES = myclass.cpp \
246 login.cpp \
247 mainwindow.cpp
248 #! [49]
249
250
251 #! [50]
252 SUBDIRS = kernel \
253 tools \
254 myapp
255 #! [50]
256
257
258 #! [51]
259 SUBDIRS += my_executable my_library tests doc
260 my_executable.depends = my_library
261 tests.depends = my_executable
262 #! [51]
263
264
265 #! [52]
266 TEMPLATE = app
267 TARGET = myapp
268 SOURCES = main.cpp
269 #! [52]
270
271
272 #! [53]
273 TEMPLATE = lib
274 SOURCES = main.cpp
275 TARGET = mylib
276 #! [53]
277
278
279 #! [54]
280 unix:UI_DIR = ../myproject/ui
281 win32:UI_DIR = c:/myproject/ui
282 #! [54]
283
284
285 #! [57]
286 win32:VERSION = 1.2.3.4 # major.minor.patch.build
287 else:VERSION = 1.2.3 # major.minor.patch
288 #! [57]
289
290
291 #! [58]
292 YACCSOURCES = moc.y
293 #! [58]
294
295
296 #! [59]
297 FILE = /etc/passwd
298 FILENAME = $$basename(FILE) #passwd
299 #! [59]
300
301
302 #! [60]
303 CONFIG = debug
304 CONFIG += release
305 CONFIG(release, debug|release):message(Release build!) #will print
306 CONFIG(debug, debug|release):message(Debug build!) #no print
307 #! [60]
308
309
310 #! [61]
311 contains( drivers, network ) {
312 # drivers contains 'network'
313 message( "Configuring for network build..." )
314 HEADERS += network.h
315 SOURCES += network.cpp
316 }
317 #! [61]
318
319
320 #! [62]
321 error(An error has occurred in the configuration process.)
322 #! [62]
323
324
325 #! [63]
326 exists( $(QTDIR)/lib/libqt-mt* ) {
327 message( "Configuring for multi-threaded Qt..." )
328 CONFIG += thread
329 }
330 #! [63]
331
332
333 #! [64]
334 MY_VAR = one two three four
335 MY_VAR2 = $$join(MY_VAR, " -L", -L) -Lfive
336 MY_VAR3 = $$member(MY_VAR, 2) $$find(MY_VAR, t.*)
337 #! [64]
338
339
340 #! [65]
341 LIST = 1 2 3
342 for(a, LIST):exists(file.$${a}):message(I see a file.$${a}!)
343 #! [65]
344
345
346 #! [66]
347 include( shared.pri )
348 OPTIONS = standard custom
349 !include( options.pri ) {
350 message( "No custom build options specified" )
351 OPTIONS -= custom
352 }
353 #! [66]
354
355
356 #! [67]
357 isEmpty( CONFIG ) {
358 CONFIG += warn_on debug
359 }
360 #! [67]
361
362
363 #! [68]
364 message( "This is a message" )
365 #! [68]
366
367
368 #! [69]
369 !build_pass:message( "This is a message" )
370 #! [69]
371
372
373 #! [70]
374 This is a test.
375 #! [70]
376
377
378 #! [71]
379 system("ls /bin"): HAS_BIN = TRUE
380 #! [71]
381
382
383 #! [72]
384 UNAME = $$system(uname -s)
385 contains( UNAME, [lL]inux ):message( This looks like Linux ($$UNAME) to me )
386 #! [72]
387
388
389 #! [73]
390 ARGS = 1 2 3 2 5 1
391 ARGS = $$unique(ARGS) #1 2 3 5
392 #! [73]
393
394
395 #! [74]
396 qmake -set PROPERTY VALUE
397 #! [74]
398
399
400 #! [75]
401 qmake -query PROPERTY
402 qmake -query #queries all current PROPERTY/VALUE pairs
403 #! [75]
404
405
406 #! [77]
407 qmake -query "QT_INSTALL_PREFIX"
408 #! [77]
409
410
411 #! [78]
412 QMAKE_VERS = $$[QMAKE_VERSION]
413 #! [78]
414
415
416 #! [79]
417 documentation.path = /usr/local/program/doc
418 documentation.files = docs/*
419 #! [79]
420
421
422 #! [80]
423 INSTALLS += documentation
424 #! [80]
425
426
427 #! [81]
428 unix:documentation.extra = create_docs; mv master.doc toc.doc
429 #! [81]
430
431
432 #! [82]
433 target.path = /usr/local/myprogram
434 INSTALLS += target
435 #! [82]
436
437
438 #! [83]
439 CONFIG += create_prl
440 #! [83]
441
442
443 #! [84]
444 CONFIG += link_prl
445 #! [84]
446
447
448 #! [85]
449 QMAKE_EXT_MOC = .mymoc
450 #! [85]
451
452
453 #! [86]
454 mytarget.target = .buildfile
455 mytarget.commands = touch $$mytarget.target
456 mytarget.depends = mytarget2
457
458 mytarget2.commands = @echo Building $$mytarget.target
459 #! [86]
460
461
462 #! [87]
463 QMAKE_EXTRA_TARGETS += mytarget mytarget2
464 #! [87]
465
466
467 #! [88]
468 new_moc.output = moc_${QMAKE_FILE_BASE}.cpp
469 new_moc.commands = moc ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
470 new_moc.depend_command = g++ -E -M ${QMAKE_FILE_NAME} | sed "s,^.*: ,,"
471 new_moc.input = NEW_HEADERS
472 QMAKE_EXTRA_COMPILERS += new_moc
473 #! [88]
474
475
476 #! [89]
477 TARGET = myapp
478 #! [89]
479
480
481 #! [90]
482 DEFINES += USE_MY_STUFF
483 #! [90]
484
485
486 #! [91]
487 DEFINES -= USE_MY_STUFF
488 #! [91]
489
490
491 #! [92]
492 DEFINES *= USE_MY_STUFF
493 #! [92]
494
495
496 #! [93]
497 DEFINES ~= s/QT_[DT].+/QT
498 #! [93]
499
500
501 #! [94]
502 EVERYTHING = $$SOURCES $$HEADERS
503 message("The project contains the following files:")
504 message($$EVERYTHING)
505 #! [94]
506
507
508 #! [95]
509 win32:DEFINES += USE_MY_STUFF
510 #! [95]
511
512
513 #! [96]
514 win32:xml {
515 message(Building for Windows)
516 SOURCES += xmlhandler_win.cpp
517 } else:xml {
518 SOURCES += xmlhandler.cpp
519 } else {
520 message("Unknown configuration")
521 }
522 #! [96]
523
524
525 #! [97]
526 MY_VARIABLE = value
527 #! [97]
528
529
530 #! [98]
531 MY_DEFINES = $$DEFINES
532 #! [98]
533
534
535 #! [99]
536 MY_DEFINES = $${DEFINES}
537 #! [99]
538
539
540 #! [100]
541 TARGET = myproject_$${TEMPLATE}
542 #! [100]
543
544
545 #! [101]
546 target.path = $$[QT_INSTALL_PLUGINS]/designer
547 INSTALLS += target
548 #! [101]
549
550
551 #! [102]
552 defineReplace(functionName){
553 #function code
554 }
555 #! [102]
556
557
558 #! [103]
559 CONFIG += myfeatures
560 #! [103]
561
562
563 #! [105]
564 PRECOMPILED_HEADER = stable.h
565 #! [105]
566
567
568 #! [106]
569 precompile_header:!isEmpty(PRECOMPILED_HEADER) {
570 DEFINES += USING_PCH
571 }
572 #! [106]
573
574
575 #! [107]
576 PRECOMPILED_HEADER = window.h
577 SOURCES = window.cpp
578 #! [107]
579
580
581 #! [108]
582 SOURCES += hello.cpp
583 #! [108]
584
585
586 #! [109]
587 SOURCES += hello.cpp
588 SOURCES += main.cpp
589 #! [109]
590
591
592 #! [110]
593 SOURCES = hello.cpp \
594 main.cpp
595 #! [110]
596
597
598 #! [111]
599 HEADERS += hello.h
600 SOURCES += hello.cpp
601 SOURCES += main.cpp
602 #! [111]
603
604
605 #! [112]
606 TARGET = helloworld
607 #! [112]
608
609
610 #! [113]
611 HEADERS += hello.h
612 SOURCES += hello.cpp
613 SOURCES += main.cpp
614 #! [113]
615
616
617 #! [114]
618 qmake -o Makefile hello.pro
619 #! [114]
620
621
622 #! [115]
623 qmake -tp vc hello.pro
624 #! [115]
625
626
627 #! [116]
628 CONFIG += debug
629 HEADERS += hello.h
630 SOURCES += hello.cpp
631 SOURCES += main.cpp
632 #! [116]
633
634
635 #! [117]
636 win32 {
637 SOURCES += hellowin.cpp
638 }
639 #! [117]
640
641
642 #! [118]
643 CONFIG += debug
644 HEADERS += hello.h
645 SOURCES += hello.cpp
646 SOURCES += main.cpp
647 win32 {
648 SOURCES += hellowin.cpp
649 }
650 unix {
651 SOURCES += hellounix.cpp
652 }
653 #! [118]
654
655
656 #! [119]
657 !exists( main.cpp ) {
658 error( "No main.cpp file found" )
659 }
660 #! [119]
661
662
663 #! [120]
664 CONFIG += debug
665 HEADERS += hello.h
666 SOURCES += hello.cpp
667 SOURCES += main.cpp
668 win32 {
669 SOURCES += hellowin.cpp
670 }
671 unix {
672 SOURCES += hellounix.cpp
673 }
674 !exists( main.cpp ) {
675 error( "No main.cpp file found" )
676 }
677 #! [120]
678
679
680 #! [121]
681 win32 {
682 debug {
683 CONFIG += console
684 }
685 }
686 #! [121]
687
688
689 #! [122]
690 CONFIG += debug
691 HEADERS += hello.h
692 SOURCES += hello.cpp
693 SOURCES += main.cpp
694 win32 {
695 SOURCES += hellowin.cpp
696 }
697 unix {
698 SOURCES += hellounix.cpp
699 }
700 !exists( main.cpp ) {
701 error( "No main.cpp file found" )
702 }
703 win32:debug {
704 CONFIG += console
705 }
706 #! [122]
707
708
709 #! [123]
710 TEMPLATE = app
711 DESTDIR = c:/helloapp
712 HEADERS += hello.h
713 SOURCES += hello.cpp
714 SOURCES += main.cpp
715 DEFINES += USE_MY_STUFF
716 CONFIG += release
717 #! [123]
718
719
720 #! [124]
721 make all
722 #! [124]
723
724
725 #! [125]
726 make
727 #! [125]
728
729
730 #! [126]
731 make install
732 #! [126]
733
734
735 #! [127]
736 CONFIG(debug, debug|release) {
737 mac: TARGET = $$join(TARGET,,,_debug)
738 win32: TARGET = $$join(TARGET,,d)
739 }
740 #! [127]
741
742 #! [149]
743 SUBDIRS += my_executable my_library
744 my_executable.subdir = app
745 my_executable.depends = my_library
746 my_library.subdir = lib
747 #! [149]
748
749 #! [157]
750 packagesExist(sqlite3 QtNetwork QtDeclarative) {
751 DEFINES += USE_FANCY_UI
752 }
753 #! [157]
754
755 #! [158]
756 #ifdef USE_FANCY_UI
757 // Use the fancy UI, as we have extra packages available
758 #endif
759 #! [158]
760
761 #! [159]
762 message($$absolute_path("readme.txt", "/home/johndoe/myproject"))
763 #! [159]
764
765
766 #! [160]
767 TARGET = helloworld
768 equals(TARGET, "helloworld") {
769 message("The target assignment was successful.")
770 }
771 #! [160]
772
773
774 #! [161]
775 CONTACT = firstname middlename surname phone
776 message($$first(CONTACT))
777 #! [161]
778
779
780 #! [162]
781 CONTACT = firstname middlename surname phone
782 message($$last(CONTACT))
783 #! [162]
784
785
786 #! [163]
787 message($$format_number(BAD, ibase=16 width=6 zeropad))
788 #! [163]
789
790
791 #! [164]
792 ANSWER = 42
793 greaterThan(ANSWER, 1) {
794 message("The answer might be correct.")
795 }
796 #! [164]
797
798
799 #! [165]
800 ANSWER = 42
801 lessThan(ANSWER, 1) {
802 message("The answer might be wrong.")
803 }
804 #! [165]
805
806
807 #! [166]
808 if(linux-g++*|macx-g++*):CONFIG(debug, debug|release) {
809 message("We are on Linux or Mac OS, and we are in debug mode.")
810 }
811 #! [166]
812
813
814 #! [167]
815 CONTACT = firstname:middlename:surname:phone
816 message($$section(CONTACT, :, 2, 2))
817 #! [167]
818
819
820 #! [168]
821 CONTACT = firstname:middlename:surname:phone
822 message($$split(CONTACT, :))
823 #! [168]
824
825 #! [169]
826 NARF = zort
827 unset(NARF)
828 !defined(NARF, var) {
829 message("NARF is not defined.")
830 }
831 #! [169]
832
833
834 #! [170]
835 for(var, $$list(foo bar baz)) {
836 ...
837 }
838 #! [170]
839
840
841 #! [171]
842 values = foo bar baz
843 for(var, values) {
844 ...
845 }
846 #! [171]
847
848
849 #! [172]
850 VALUE = 123
851 TMP_VALUE = x$$VALUE
852 greaterThan(TMP_VALUE, x456): message("Condition may be true.")
853 #! [172]
854
855
856 #! [173]
857 message("First line$$escape_expand(\\n)Second line")
858 #! [173]
859
860
861 #! [174]
862 TEMPLATE = subdirs
863 SUBDIRS = one two three
864 prepareRecursiveTarget(check)
865 #! [174]
866
867
868 #! [175]
869 two.CONFIG += no_check_target
870 #! [175]
871
872
873 #! [176]
874 QMAKE_EXTRA_TARGETS += check
875 #! [176]
876
877
878 #! [177]
879 # <project root>/features/mycheck.prf
880 equals(TEMPLATE, subdirs) {
881 prepareRecursiveTarget(check)
882 } else {
883 check.commands = echo hello user
884 }
885 QMAKE_EXTRA_TARGETS += check
886 #! [177]
887
888
889 #! [178]
890 # <project root>/.qmake.conf
891 CONFIG += mycheck
892 #! [178]
893
894
895 #! [179]
896 # <project root>/project.pro
897 load(configure)
898 #! [179]
899
900
901 #! [180]
902 # <project root>/config.tests/test/test.pro
903 SOURCES = main.cpp
904 LIBS += -ltheFeature
905 # Note that the test project is built without Qt by default.
906 #! [180]
907
908
909 #! [181]
910 // <project root>/config.tests/test/main.cpp
911 #include <TheFeature/MainHeader.h>
912 int main() { return featureFunction(); }
913 #! [181]
914
915
916 #! [182]
917 # <project root>/project.pro
918 qtCompileTest(test)
919 #! [182]
920
921 #! [183]
922 # <project root>/project.pro
923 QMAKE_SONAME_PREFIX = @rpath
924 #! [183]
925
926 #! [184]
927 # <project root>/project.pro
928 QMAKE_SONAME_PREFIX = @executable_path/../Frameworks
929 QMAKE_SONAME_PREFIX = @loader_path/Frameworks
930 QMAKE_SONAME_PREFIX = /Library/Frameworks
931 #! [184]
932
933 #! [185]
934 VERSION_PE_HEADER = 1.2
935 #! [185]
936
937 #! [186]
938 RC_DEFINES += USE_MY_STUFF
939 #! [186]
940
941 #! [187]
942 win32-g++:contains(QMAKE_HOST.arch, x86_64):{
943 message("Host is 64bit")
944 ...
945 }
946 #! [187]
947
948 #! [188]
949 translations_en.files = $$PWD/en.lproj/InfoPlist.strings
950 translations_en.path = en.lproj
951 QMAKE_BUNDLE_DATA += translations_en
952 #! [188]
953
954 #! [189]
955 # Approach 1
956 translations_en.files = $$PWD/InfoPlist.strings
957 translations_en.path = en.lproj
958
959 # Approach 2
960 translations_de.files = $$PWD/de.lproj/InfoPlist.strings
961
962 QMAKE_BUNDLE_DATA += translations_en translations_de
963 #! [189]
964
965 #! [TR_EXCLUDE sources]
966 SOURCES += main.cpp \
967 excluded.cpp \
968 3rdparty/sqlite3.h \
969 3rdparty/sqlite3.c
970 TR_EXCLUDE += excluded.cpp 3rdparty/*
971 #! [TR_EXCLUDE sources]
972
973 #! [TR_EXCLUDE SUBDIRS]
974 SUBDIRS += \
975 libs \
976 apps \
977 tests
978 TR_EXCLUDE += tests
979 #! [TR_EXCLUDE SUBDIRS]
980
981 #! [TR_EXCLUDE include paths]
982 linux {
983 TR_EXCLUDE += /usr/include/boost/*
984 }
985 #! [TR_EXCLUDE include paths]