Skip to content

Commit

Permalink
configure: verify header presence against sources
Browse files Browse the repository at this point in the history
in addition to the actual library resolution, also resolve the headers
belonging to the library, to validate the include path, and possibly
ensure that the right version of the library is present.

the "include" entries were moved out of the "test" objects, and renamed
to "headers". this cleanly permits libraries without compile tests.

the headers were not put into the sources, because the variance among
the includes is generally orthogonal to the variance among the
libraries.

note that this - like the library resolution - provides no support for
darwin frameworks. consequently, the opengl libraries are excluded from
the conversion on darwin.

similarly, wasm is excluded (centrally), because emcc is magic and would
need advanced wizardry to be dealt with.

Change-Id: Ib390c75371efa2badcfec9b74274047ce67c3e5a
Reviewed-by: Joerg Bornemann <[email protected]>
Reviewed-by: Paul Wicking <[email protected]>
  • Loading branch information
ossilator committed Dec 14, 2018
1 parent a227ea5 commit e80bf65
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 82 deletions.
6 changes: 3 additions & 3 deletions configure.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@
"zlib": {
"label": "zlib",
"test": {
"include": "zlib.h",
"main": [
"z_streamp stream = 0;",
"(void) zlibVersion();",
"(void) compress2(0, 0, 0, 0, 1); // compress2 was added in zlib version 1.0.8"
]
},
"headers": "zlib.h",
"sources": [
{ "libs": "-lzdll", "condition": "config.msvc" },
{ "libs": "-lzlib", "condition": "config.msvc" },
Expand All @@ -169,9 +169,9 @@
"dbus": {
"label": "D-Bus >= 1.2",
"test": {
"include": "dbus/dbus.h",
"main": "(void) dbus_bus_get_private(DBUS_BUS_SYSTEM, (DBusError *)NULL);"
},
"headers": "dbus/dbus.h",
"sources": [
{ "type": "pkgConfig", "args": "dbus-1 >= 1.2" },
{
Expand All @@ -196,9 +196,9 @@
"libudev": {
"label": "udev",
"test": {
"include": "libudev.h",
"main": "udev_unref(udev_new());"
},
"headers": "libudev.h",
"sources": [
{ "type": "pkgConfig", "args": "libudev" },
"-ludev"
Expand Down
58 changes: 51 additions & 7 deletions mkspecs/features/qt_configure.prf
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,33 @@ defineTest(qtConfResolvePathLibs) {
return($$ret)
}

# includes-var, includes
defineReplace(qtConfGetTestIncludes) {
defined($${1}._KEYS_, var) {
1st = $$first($${1}._KEYS_)
equals(1st, 0) {
# array; recurse for every element
ret =
for (k, $${1}._KEYS_): \
ret += $$qtConfGetTestIncludes($${1}.$$k)
return($$ret)
}
# object; try condition and recurse
!defined($${1}.headers, var):!defined($${1}.headers._KEYS_, var): \ # just plain broken without it
error("headers object '$$1' has no nested headers entry")
cond = $$eval($${1}.condition)
isEmpty(cond): \ # would be pointless otherwise
error("headers object '$$1' has no condition")
!$$qtConfEvaluate($$cond) {
qtLog("header entry '$$1' failed condition '$$cond'.")
return()
}
qtLog("header entry '$$1' passed condition.")
return($$qtConfGetTestIncludes($${1}.headers))
}
return($$eval($$1)) # plain string - or nothing (can happen for top-level call only)
}

# includes-var, in-paths, test-object-var
defineTest(qtConfResolvePathIncs) {
ret = true
for (incdir, 2) {
Expand All @@ -594,6 +620,21 @@ defineTest(qtConfResolvePathIncs) {
2 -= $$QMAKE_DEFAULT_INCDIRS
$$1 = $$2
export($$1)
wasm {
# FIXME: emcc downloads pre-built libraries and adds their include
# path to the clang call dynamically. it would be possible to parse
# the emcc -s USE_xyz=1 --cflags output to populate xzy_INCDIR and
# thus make the code below work.
return($$ret)
}
hdrs = $$qtConfGetTestIncludes($${3}.headers)
for (hdr, hdrs) {
h = $$qtConfFindInPathList($$hdr, $$2 $$EXTRA_INCLUDEPATH $$QMAKE_DEFAULT_INCDIRS)
isEmpty(h) {
qtLog("$$hdr not found in [$$val_escape(2)] and global paths.")
ret = false
}
}
return($$ret)
}

Expand Down Expand Up @@ -662,7 +703,7 @@ defineTest(qtConfLibrary_inline) {
!qtConfResolveAllLibs($$1): \
return(false)

!qtConfResolvePathIncs($${1}.includedir, $$includes): \
!qtConfResolvePathIncs($${1}.includedir, $$includes, $$2): \
return(false)

return(true)
Expand All @@ -678,7 +719,7 @@ defineTest(qtConfLibrary_makeSpec) {
!qtConfResolvePathLibs($${1}.libs, $$eval(QMAKE_LIBDIR_$$spec), $$eval(QMAKE_LIBS_$$spec)): \
return(false)

!qtConfResolvePathIncs($${1}.includedir, $$eval(QMAKE_INCDIR_$$spec)): \
!qtConfResolvePathIncs($${1}.includedir, $$eval(QMAKE_INCDIR_$$spec), $$2): \
return(false)

# note that the object is re-exported, because we resolve the libraries.
Expand Down Expand Up @@ -741,7 +782,7 @@ defineTest(qtConfLibrary_pkgConfig) {
}
!isEmpty(ignored): \
qtLog("Note: Dropped compiler flags '$$ignored'.")
!qtConfResolvePathIncs($${1}.includedir, $$includes): \
!qtConfResolvePathIncs($${1}.includedir, $$includes, $$2): \
return(false)
$${1}.defines = $$defines

Expand Down Expand Up @@ -1054,7 +1095,7 @@ defineTest(qtConfTestPrepare_compile) {
}

defineTest(qtConfPrepareCompileTestSource) {
test_dir = $$2
test_dir = $$3

test_lang = $$eval($${1}.lang)
isEmpty(test_lang): test_lang = "c++"
Expand All @@ -1071,7 +1112,10 @@ defineTest(qtConfPrepareCompileTestSource) {
for (ent, $$qtConfScalarOrList($${1}.head)): \
contents += $$ent
# Includes
for (ent, $$qtConfScalarOrList($${1}.include)): \
hdrs = $$qtConfGetTestIncludes($${1}.include)
isEmpty(hdrs): \
hdrs = $$qtConfGetTestIncludes($$2)
for (ent, hdrs): \
contents += "$${LITERAL_HASH}include <$$ent>"
# Custom code after includes
for (ent, $$qtConfScalarOrList($${1}.tail)): \
Expand Down Expand Up @@ -1107,7 +1151,7 @@ defineTest(qtConfTest_compile) {
isEmpty(test) {
test_dir = $$test_base_out_dir/$$section(1, ".", -1)
test_out_dir = $$test_dir
qtConfPrepareCompileTestSource($${1}.test, $$test_dir)
qtConfPrepareCompileTestSource($${1}.test, $${1}.headers, $$test_dir)
} else {
test_dir = $$QMAKE_CONFIG_TESTS_DIR/$$test
test_out_dir = $$test_base_out_dir/$$test
Expand Down
22 changes: 11 additions & 11 deletions src/corelib/configure.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"doubleconversion": {
"label": "DoubleConversion",
"test": {
"include": "double-conversion/double-conversion.h",
"main": "(void) double_conversion::StringToDoubleConverter::NO_FLAGS;"
},
"headers": "double-conversion/double-conversion.h",
"sources": [
"-ldouble-conversion"
]
Expand All @@ -35,14 +35,14 @@
"label": "GLib",
"test": {
"head": "typedef struct _GMainContext GMainContext;",
"include": "glib.h",
"main": [
"g_thread_init(NULL);",
"(void) g_main_context_default();",
"(void) g_source_new(0, 0);",
"g_source_add_poll(NULL, NULL);"
]
},
"headers": "glib.h",
"sources": [
{ "type": "pkgConfig", "args": "glib-2.0 gthread-2.0" }
]
Expand All @@ -58,14 +58,14 @@
"icu": {
"label": "ICU",
"test": {
"include": [ "unicode/utypes.h", "unicode/ucol.h", "unicode/ustring.h" ],
"main": [
"UErrorCode status = U_ZERO_ERROR;",
"UCollator *collator = ucol_open(\"ru_RU\", &status);",
"if (!U_FAILURE(status))",
" ucol_close(collator);"
]
},
"headers": [ "unicode/utypes.h", "unicode/ucol.h", "unicode/ustring.h" ],
"sources": [
{
"builds": {
Expand All @@ -84,9 +84,9 @@
"journald": {
"label": "journald",
"test": {
"include": [ "systemd/sd-journal.h", "syslog.h" ],
"main": "sd_journal_send(\"PRIORITY=%i\", LOG_INFO, NULL);"
},
"headers": [ "systemd/sd-journal.h", "syslog.h" ],
"sources": [
{ "type": "pkgConfig", "args": "libsystemd" },
{ "type": "pkgConfig", "args": "libsystemd-journal" }
Expand All @@ -95,7 +95,6 @@
"libatomic": {
"label": "64 bit atomics",
"test": {
"include": [ "atomic", "cstdint" ],
"tail": [
"void test(volatile std::atomic<std::int64_t> &a)",
"{",
Expand All @@ -114,6 +113,7 @@
],
"qmake": "CONFIG += c++11"
},
"headers": [ "atomic", "cstdint" ],
"sources": [
"",
"-latomic"
Expand All @@ -122,13 +122,13 @@
"libdl": {
"label": "dlopen()",
"test": {
"include": "dlfcn.h",
"main": [
"dlclose(dlopen(0, 0));",
"dlsym(RTLD_DEFAULT, 0);",
"dlerror();"
]
},
"headers": "dlfcn.h",
"sources": [
"",
"-ldl"
Expand All @@ -137,9 +137,9 @@
"librt": {
"label": "clock_gettime()",
"test": {
"include": [ "unistd.h", "time.h" ],
"main": "timespec ts; clock_gettime(CLOCK_REALTIME, &ts);"
},
"headers": [ "unistd.h", "time.h" ],
"sources": [
"",
"-lrt"
Expand All @@ -148,9 +148,9 @@
"lttng-ust": {
"label": "lttng-ust",
"test": {
"include": "lttng/ust-events.h",
"main": "lttng_session_destroy(nullptr);"
},
"headers": "lttng/ust-events.h",
"sources": [
{ "type": "pkgConfig", "args": "lttng-ust" },
"-llttng-ust"
Expand All @@ -161,13 +161,13 @@
"label": "PCRE2",
"test": {
"head": "#define PCRE2_CODE_UNIT_WIDTH 16",
"include": "pcre2.h",
"tail": [
"#if (PCRE2_MAJOR < 10) || ((PCRE2_MAJOR == 10) && (PCRE2_MINOR < 20))",
"# error This PCRE version is not supported",
"#endif"
]
},
"headers": "pcre2.h",
"sources": [
{ "type": "pkgConfig", "args": "libpcre2-16" },
"-lpcre2-16"
Expand All @@ -176,23 +176,23 @@
"pps": {
"label": "PPS",
"test": {
"include": "sys/pps.h",
"main": [
"pps_decoder_t decoder;",
"pps_decoder_initialize(&decoder, NULL);"
]
},
"headers": "sys/pps.h",
"sources": [
"-lpps"
]
},
"slog2": {
"label": "slog2",
"test": {
"include": "sys/slog2.h",
"main": "slog2_set_default_buffer((slog2_buffer_t)-1);"
},
"export": "",
"headers": "sys/slog2.h",
"sources": [
"-lslog2"
]
Expand Down
Loading

0 comments on commit e80bf65

Please sign in to comment.