File: qt.m4

package info (click to toggle)
unixodbc 2.2.14p2-5
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 14,620 kB
  • sloc: ansic: 104,255; cpp: 38,573; sh: 15,958; makefile: 2,728; sql: 1
file content (441 lines) | stat: -rw-r--r-- 12,709 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# Copyright (C) 2001 David Johnson
# This file is free software; the author gives unlimited permission to  copy
# and/or distribute it, with or without modifications, as long as this notice
# is preserved.

#
# This was pulled from a gettext example on a SuSE 9.1 distro and has since been 
# enhanced to serve the purposes of unixODBC.
#
# Peter Harvey <pharvey@codebydesign.com> 30.AUG.05
#

# FUN_CHECK_QT([qt_min_version],[qt_max_version])
# check for qt headers, libs, progs and compilation
# substs QT_CXXFLAGS, QT_LDFLAGS, and QT_LIBS
# substs QTVERSION, MOC and UIC
# MOC and UIC 'precious' variables

AC_DEFUN([FUN_CHECK_QT],
[
  AC_REQUIRE([AC_PROG_CXX])
  AC_REQUIRE([AC_PATH_X])
  AC_REQUIRE([AC_PATH_XTRA])

  # some 'precious' variables for configure --help
  AC_ARG_VAR(QTMIN, minimum version of Qt to search for  e.g. export QTMIN=020400)
  AC_ARG_VAR(QTMAX, maximum version of Qt to search for  e.g. export QTMAX=030305)
  AC_ARG_VAR(MOC, QT meta object compiler command)
  AC_ARG_VAR(UIC, Qt UI compiler command)

  AC_CACHE_SAVE

  AC_MSG_NOTICE([checking for Qt])

  # process our args
  if test -z "$1" ; then
    qt_min_version=0
  else
    qt_min_version=$1
  fi
  if test -z "$2" ; then
    qt_max_version=99999
  else
    qt_max_version=$2
  fi
  # adjust for user preferences
  if test "x$QTMIN" != "x" ; then
      qt_min_version=$QTMIN;
  fi
  if test "x$QTMAX" != "x" ; then
    if expr $QTMAX '<' $qt_max_version > /dev/null ; then
      qt_max_version=$QTMAX;
    fi
  fi

  # set up our configuration options
  qt_dir=""
  qt_includes=""
  qt_libraries=""
  qt_programs=""
  AC_ARG_WITH([qt_dir], AC_HELP_STRING([--with-qt-dir=DIR],
                        [where the Qt package is installed]),
    [ qt_dir="$withval"
      qt_includes="$withval"/include
      qt_libraries="$withval"/lib
      qt_programs="$withval"/bin
    ])
  AC_ARG_WITH([qt_includes], AC_HELP_STRING([--with-qt-includes=DIR],
                             [where the Qt includes are installed]),
    [qt_includes="$withval"])
  AC_ARG_WITH([qt_libraries], AC_HELP_STRING([--with-qt-libraries=DIR],
                              [where the Qt libraries are installed]),
    [qt_libraries="$withval"])
  AC_ARG_WITH([qt_programs], AC_HELP_STRING([--with-qt-programs=DIR],
                             [where the Qt programs are installed]),
    [qt_programs="$withval"])

  QTVERSION="00000"

  FUN_QT_HEADERS

  AC_MSG_NOTICE([Found Qt version $QTVERSION])

  FUN_QT_LIBRARIES
  FUN_QT_PROGRAMS
  FUN_QT_COMPILE

  AC_SUBST(QTVERSION)
  AC_SUBST(MOC)
  AC_SUBST(UIC)
  QT_CXXFLAGS="-I$qt_includes -I$qt_includes/QtCore -I$qt_includes/QtGui -I$qt_includes/QtAssistant -I$qt_includes/QtNetwork"
  AC_SUBST(QT_CXXFLAGS)
  QT_LDFLAGS="-L$qt_libraries"
  AC_SUBST(QT_LDFLAGS)
  QT_LIBS="$qt_libs"
  AC_SUBST(QT_LIBS)

  have_qt="yes"

])#FUN_CHECK_QT

# FUN_QT_HEADERS
# helper function for FUN_CHECK_QT
# check for qt headers in standard locations

AC_DEFUN([FUN_QT_HEADERS],
[

  qt_found_version=""
  qt_v4_include=""

  # Have not been told where Qt is so search for it...
  if test "x$qt_includes" = "x" ; then
    # look in standard locations
    qt_found_dirs=""
    qt_include_dirs="
      $QTDIR/include
      /usr/include
      /usr/local/include
      /usr/X11R6/include
      `ls -dr /usr/include/qt* 2>/dev/null`
      `ls -dr /usr/local/include/qt* 2>/dev/null`
      `ls -dr /usr/X11R6/include/qt* 2>/dev/null`
      `ls -dr /usr/lib/qt*/include 2>/dev/null`
      `ls -dr /usr/local/lib/qt*/include 2>/dev/null`
      `ls -dr /usr/X11R6/lib/qt*/include 2>/dev/null`
      `ls -dr /usr/local/qt*/include 2>/dev/null`
      `ls -dr /usr/local/Trolltech/Qt*/include 2>/dev/null`
      `ls -dr /opt/qt*/include 2>/dev/null` "
    for n in $qt_include_dirs ; do
      if test -r "$n/qglobal.h"; then
        qt_found_dirs="$qt_found_dirs $n"
      else
        if test -r "$n/Qt/qglobal.h"; then
          qt_found_dirs="$qt_found_dirs $n"
	fi
      fi
    done

    # find the latest version between min_version and max_version
    qt_prev_version=$qt_min_version
    for n in $qt_found_dirs ; do

AC_MSG_NOTICE([Checking dir $n])
      FUN_QT_VERSION($n)	

      if expr $qt_current_version '>=' $qt_prev_version > /dev/null ; then
        if expr $qt_current_version '<=' $qt_max_version > /dev/null ; then
          qt_includes=$n
          qt_prev_version=$qt_current_version
          qt_found_version=$qt_current_version
        fi
      fi
    done
  fi

  AC_MSG_CHECKING([for Qt headers])

  if test "x$qt_includes" = "x" ; then
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([cannot find correct Qt headers!, consider adding --enable-gui=no to configure arguments])
  else
    # Ensure we have a version...
    if test "x$qt_found_version" = "x" ; then
      FUN_QT_VERSION($qt_includes)
      qt_found_version=$qt_current_version
    fi
    if test "x$qt_found_version" = "x" ; then
      AC_MSG_RESULT([no])
      AC_MSG_ERROR([cannot find version of Qt!, consider adding --enable-gui=no to configure arguments])
    fi

    AC_MSG_RESULT([$qt_includes])

    AC_MSG_CHECKING([for Qt4 headers])
    if test -r "$qt_includes/Qt/qglobal.h"; then
	  qt_v4_include="y"
      AC_MSG_RESULT([yes])
	else
      AC_MSG_RESULT([no])
	fi

    dnl TODO need to strip out white space
    QTVERSION=$qt_found_version;
	AC_MSG_CHECKING([include layout])
  	if test "x$qt_v4_include" = "xy" ; then
    	AC_MSG_RESULT([v4 layout])
    	AC_DEFINE(QT_V4LAYOUT)
# Lets get rid of qt3support in favour of pure qt4 - PAH
#    	AC_DEFINE(QT3_SUPPORT)
#		MOCDEFS="-DQT3_SUPPORT"
#		AC_SUBST(MOCDEFS)
		have_qt4="yes"
	else
		MOCDEFS=""
		AC_SUBST(MOCDEFS)
    	AC_MSG_RESULT([standard layout])
	fi
  fi
])#FUN_QT_HEADERS

# FUN_QT_VERSION(qt_include_dir)
# helper function for FUN_QT_HEADERS
# get version from qglobal.h

AC_DEFUN([FUN_QT_VERSION],
[
  dnl the 2x versions need the extra sed 
  if test -r "$1/qglobal.h"; then
    qt_current_version=`grep -w '#define QT_VERSION' "$1"/qglobal.h | grep -v '#define QT_VERSION_STR' |
      sed s/'#define QT_VERSION 0x'// | sed s/'#define QT_VERSION'//`
  else
    if test -r "$1/Qt/qglobal.h"; then
# if test "x$qt_current_version" = "x" ; then
      qt_current_version=`grep -w '#define QT_VERSION' "$1"/Qt/qglobal.h | grep -v '#define QT_VERSION_STR' |
        sed s/'#define QT_VERSION 0x'// | sed s/'#define QT_VERSION'//`
    fi
  fi
])#FUN_QT_VERSION

# FUN_QT_LIBRARIES
# helper function for FUN_CHECK_QT
# check for qt libs in standard locations

AC_DEFUN([FUN_QT_LIBRARIES],
[
  AC_REQUIRE([FUN_QT_HEADERS])

  AC_MSG_CHECKING([for Qt libraries])

  # Ensure we have the lib dir...
  if test "x$qt_libraries" = "x" ; then
    # see if it is relative to the includes
    qt_tree="$qt_includes"

	#
	# the cygwin dirhame only strips up to the first /
	#

	case $host_os in
	  cygwin*) empty_dir="x/" ;;
	  *) empty_dir="x" ;;
	esac

    while test "x$qt_tree" != $empty_dir ; do
      # first go around will fail...
      if expr "$QTVERSION" '>=' "040000" > /dev/null ; then
        if ls $qt_tree/lib/libQt* > /dev/null 2> /dev/null ; then
          qt_libraries=$qt_tree/lib
          break
        else
          # lop off tail of path
          dnl not as portable as it should be...
          qt_tree="`dirname $qt_tree`"
	fi
      else
        if ls $qt_tree/lib/libqt* > /dev/null 2> /dev/null ; then
          qt_libraries=$qt_tree/lib
          break
        else
          # lop off tail of path
          dnl not as portable as it should be...
          qt_tree="`dirname $qt_tree`"
	fi
      fi
    done
  fi  

  # Use QTVERSION and gotthread to set libs we need...
  if expr "$QTVERSION" '>=' "040000" > /dev/null ; then
    qt_libs="-lQtGui -lQtCore -lQtAssistantClient -lQtNetwork"
  else
    if test "x$gotthread" = "xyes" ; then
      try="ls -1 $qt_libraries/libqt-mt*"
      if test=`eval $try 2> /dev/null`; then
        qt_libs="-lqt-mt"
      else
        qt_libs="-lqt"
      fi
    else
      qt_libs="-lqt"
    fi
  fi

  # Return...
  if test "x$qt_libraries" = "x" ; then
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([cannot find Qt libraries!, consider adding --enable-gui=no to configure arguments])
  else
    AC_MSG_RESULT([$qt_libraries])
	AC_CHECK_FILE([$qt_includes/QtGui/QWizard], [have_qtwizard=yes], [have_qtwizard=no])
	AC_CHECK_FILE([$qt_includes/QtGui/QMdiArea], [have_qtmdiarea=yes], [have_qtmdiarea=no])
  fi
])#FUN_QT_LIBRARIES

# FUN_QT_PROGRAMS
# helper function for FUN_CHECK_QT
# searches for moc and uic

AC_DEFUN([FUN_QT_PROGRAMS],
[
  AC_REQUIRE([FUN_QT_LIBRARIES])

  AC_MSG_CHECKING([for Qt utilities])

  if test "x$q_programs" = "x" ; then
    # see if it is relative to the libraries
    qt_tree="$qt_libraries"
    while test "x$qt_tree" != "x" ; do
      # first go around will fail
      if ls $qt_tree/bin/moc* > /dev/null 2> /dev/null ; then
        qt_programs=$qt_tree/bin
        break
      else
        # lop off tail of path
        dnl not as portable as it should be...
        qt_tree="`dirname $qt_tree`"
      fi
    done
    # if we haven't found the progs, there's not much more we can do
  fi  

  if test "x$qt_programs" = "x" ; then
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([cannot find Qt utilities!, consider adding --enable-gui=no to configure arguments])
  else
    AC_MSG_RESULT([$qt_programs])
    # find the right moc
    if test -z "$MOC" ; then
      AC_CHECK_PROG(MOC, moc, moc )
      if test "x$MOC" = "x" ; then
        # could be renamed to avoid clashes
        if ls $qt_programs/moc > /dev/null 2> /dev/null ; then
          MOC="$qt_programs/moc"
        else
          if expr "$QTVERSION" '>=' "200" > /dev/null ; then
            if ls $qt_programs/moc2 > /dev/null 2> /dev/null ; then
              MOC="$qt_programs/moc2"
            fi
          else
            if expr "$QTVERSION" '>=' "300" > /dev/null ; then
              if $qt_programs/moc3 > /dev/null 2> /dev/null ; then
                MOC="$qt_programs/moc3"
              fi
            fi
          fi
        fi
      fi
      if test "x$MOC" = "x" ; then
        AC_MSG_RESULT([no])
        AC_MSG_ERROR([cannot find Qt meta object compiler!, consider adding --enable-gui=no to configure arguments])
      fi
    fi

    # find the right uic
    if expr "$QTVERSION" '>=' "220" > /dev/null ; then
      if test -z "$UIC" ; then
        AC_CHECK_PROG(UIC, uic, uic )
        if test "x$UIC" = "x" ; then
          # could be renamed to avoid clashes
          if ls $qt_programs/uic > /dev/null 2> /dev/null ; then
            UIC="$qt_programs/uic"
          else
            if expr "$QTVERSION" '>=' "300" > /dev/null ; then
              if ls $qt_programs/uic3 > /dev/null 2> /dev/null ; then
                UIC="$qt_programs/uic3"
              fi
            fi
          fi
        fi
      fi
    else
      # if uic is important to the build, change this
      UIC=""
    fi
  fi
])#FUN_QT_PROGRAMS

# FUN_QT_COMPILE
# helper function for FUN_CHECK_QT
# compile a simple qt program

AC_DEFUN([FUN_QT_COMPILE],
[
  AC_REQUIRE([FUN_QT_HEADERS])
  AC_REQUIRE([FUN_QT_LIBRARIES])
  AC_REQUIRE([FUN_QT_PROGRAMS])


  AC_LANG_PUSH(C++)

AC_MSG_NOTICE([qt_libraries=$qt_libraries])
AC_MSG_NOTICE([LDFLAGS=$LDFLAGS])
AC_MSG_NOTICE([X_LIBS=$X_LIBS])

  AC_MSG_CHECKING([whether a simple Qt program compiles])

  ac_cxxflags_save="$CXXFLAGS"
  ac_ldflags_save="$LDFLAGS"
  ac_libs_save="$LIBS"
  if expr "$QTVERSION" '>=' "040000" > /dev/null ; then
    CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS -I$qt_includes -I$qt_includes/QtCore -I$qt_includes/QtGui $X_CFLAGS $all_includes"
  else
    CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS -I$qt_includes $X_CFLAGS $all_includes"
  fi
  LDFLAGS="$LDFLAGS -L$qt_libraries $X_LIBS $X_LDFLAGS"
  LIBS="$LIBS $PTHREAD_LIBS $qt_libs $X_EXTRA_LIBS -lXext -lX11 $X_PRE_LIBS $EXTRA_XLIBS"

  if expr "$QTVERSION" '>=' "040000" > /dev/null ; then
    AC_TRY_LINK([
      #include <QMessageBox>
      #include <QString>],
      [QString s = "hello world";
      QMessageBox::information(0, s, "no he is not");
      return 0;],
    qt_compile=yes, qt_compile=no)
  else
    AC_TRY_LINK([
      #include <qmessagebox.h>
      #include <qstring.h>],
      [QString s = "hello world";
      QMessageBox::information(0, s, "no he is not");
      return 0;],
    qt_compile=yes, qt_compile=no)
  fi

  CXXFLAGS="$ac_cxxflags_save"
  LDFLAGS="$ac_ldflags_save"
  LIBS="$ac_libs_save"

  AC_LANG_POP(C++)

  if test "x$qt_compile" = "xyes" ; then
    AC_MSG_RESULT([yes])
  else
    AC_MSG_RESULT([no])
# We do not want to force everything to stop because we do not have 
# qt - let caller decide what to do.
#    AC_MSG_ERROR([cannot compile a Qt program!])
  fi
])#FUN_QT_COMPILE