From ed07bdcb5f96d723f9c4c6b689ae95965c57c723 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 10 May 2017 18:55:06 +0200 Subject: make sql drivers independently configurable our binary packages come without many sql drivers, because they have proprietary dependencies we cannot ship. not every user wants to build all of qt from scratch, so it makes sense to make it possible to "enrich" the existing installation by compiling just the drivers. to enable this, the drivers' configuration must be independent. but note that it's still not possible to configure a single driver - the entire sqldrivers directory is configured at once. a side effect of this is that the availability of the sql plugins cannot be made known with publicFeatures any more, because there is no associated module pri file to put that information into. that should be made inconsequential by making qtHaveModule() work for plugins. Task-number: QTBUG-58372 Change-Id: Ibdebe3199688a57f93cea82dc15623081d1280f5 Reviewed-by: Joerg Bornemann --- src/plugins/sqldrivers/.qmake.conf | 19 +++ src/plugins/sqldrivers/configure.json | 201 ++++++++++++++++++++++++++++++ src/plugins/sqldrivers/configure.pri | 99 +++++++++++++++ src/plugins/sqldrivers/qsqldriverbase.pri | 3 + src/plugins/sqldrivers/sqldrivers.pro | 6 +- src/plugins/sqldrivers/sqlite/sqlite.pro | 5 +- 6 files changed, 330 insertions(+), 3 deletions(-) create mode 100644 src/plugins/sqldrivers/.qmake.conf create mode 100644 src/plugins/sqldrivers/configure.json create mode 100644 src/plugins/sqldrivers/configure.pri (limited to 'src/plugins/sqldrivers') diff --git a/src/plugins/sqldrivers/.qmake.conf b/src/plugins/sqldrivers/.qmake.conf new file mode 100644 index 0000000000..15ba71a343 --- /dev/null +++ b/src/plugins/sqldrivers/.qmake.conf @@ -0,0 +1,19 @@ +# This file detaches this sub-tree from the rest of qtbase, +# so it can be configured stand-alone. +# Of course, under normal circumstances, this _is_ part of qtbase, +# so we have to make some contortions to restore normality. + +isEmpty(_QMAKE_CONF_): return() # Pre-scan during spec loading. + +SQLDRV_SRC_TREE = $$dirname(_QMAKE_CONF_) +QTBASE_SRC_TREE = $$section(SQLDRV_SRC_TREE, /, 0, -4) + +QTBASE_BLD_TREE = $$shadowed($$QTBASE_SRC_TREE) +!isEmpty(QTBASE_BLD_TREE):exists($$QTBASE_BLD_TREE/.qmake.cache) { + # This tricks qt_build_config.prf and qt_build_paths.prf + _QMAKE_CONF_ = $$QTBASE_SRC_TREE/.qmake.conf +} else { + CONFIG += sqldrivers_standalone +} + +include($$QTBASE_SRC_TREE/.qmake.conf) diff --git a/src/plugins/sqldrivers/configure.json b/src/plugins/sqldrivers/configure.json new file mode 100644 index 0000000000..5603ceb37b --- /dev/null +++ b/src/plugins/sqldrivers/configure.json @@ -0,0 +1,201 @@ +{ + "module": "sqldrivers", + "depends": [ + "core" + ], + "testDir": "../../../config.tests", + + "commandline": { + "assignments": { + "MYSQL_PATH": "mysql.prefix", + "SYBASE": "tds.prefix", + "SYBASE_LIBS": "tds.libs" + }, + "options": { + "mysql_config": "string", + "psql_config": "string", + "sqlite": { "type": "enum", "name": "system-sqlite", "values": { "qt": "no", "system": "yes" } }, + "sql-db2": "boolean", + "sql-ibase": "boolean", + "sql-mysql": "boolean", + "sql-oci": "boolean", + "sql-odbc": "boolean", + "sql-psql": "boolean", + "sql-sqlite": "boolean", + "sql-sqlite2": "boolean", + "sql-tds": "boolean", + "plugin-sql-db2": { "type": "void", "name": "sql-db2" }, + "plugin-sql-ibase": { "type": "void", "name": "sql-ibase" }, + "plugin-sql-mysql": { "type": "void", "name": "sql-mysql" }, + "plugin-sql-oci": { "type": "void", "name": "sql-oci" }, + "plugin-sql-odbc": { "type": "void", "name": "sql-odbc" }, + "plugin-sql-psql": { "type": "void", "name": "sql-psql" }, + "plugin-sql-sqlite": { "type": "void", "name": "sql-sqlite" }, + "plugin-sql-sqlite2": { "type": "void", "name": "sql-sqlite2" }, + "plugin-sql-tds": { "type": "void", "name": "sql-tds" } + } + }, + + "libraries": { + "db2": { + "label": "DB2 (IBM)", + "test": "unix/db2", + "sources": [ + { "libs": "-ldb2cli", "condition": "config.win32" }, + { "libs": "-ldb2", "condition": "!config.win32" } + ] + }, + "ibase": { + "label": "InterBase", + "test": "unix/ibase", + "sources": [ + { "libs": "-lgds32_ms", "condition": "config.win32" }, + { "libs": "-lgds", "condition": "!config.win32" } + ] + }, + "mysql": { + "label": "MySQL", + "test": "unix/mysql", + "sources": [ + { "type": "mysqlConfig", "query": "--libs_r", "cleanlibs": true }, + { "type": "mysqlConfig", "query": "--libs", "cleanlibs": true }, + { "type": "mysqlConfig", "query": "--libs_r", "cleanlibs": false }, + { "type": "mysqlConfig", "query": "--libs", "cleanlibs": false }, + { "libs": "-lmysqlclient_r", "condition": "!config.win32" }, + { "libs": "-llibmysql", "condition": "config.win32" }, + { "libs": "-lmysqlclient", "condition": "!config.win32" } + ] + }, + "psql": { + "label": "PostgreSQL", + "test": "unix/psql", + "sources": [ + { "type": "pkgConfig", "args": "libpq" }, + { "type": "psqlConfig" }, + { "type": "psqlEnv", "libs": "-llibpq -lws2_32 -ladvapi32", "condition": "config.win32" }, + { "type": "psqlEnv", "libs": "-lpq", "condition": "!config.win32" } + ] + }, + "tds": { + "label": "TDS (Sybase)", + "test": "unix/tds", + "sources": [ + { "type": "sybaseEnv", "libs": "-lNTWDBLIB", "condition": "config.win32" }, + { "type": "sybaseEnv", "libs": "-lsybdb", "condition": "!config.win32" } + ] + }, + "oci": { + "label": "OCI (Oracle)", + "test": "unix/oci", + "sources": [ + { "libs": "-loci", "condition": "config.win32" }, + { "libs": "-lclntsh", "condition": "!config.win32" } + ] + }, + "odbc": { + "label": "ODBC", + "test": "unix/odbc", + "sources": [ + { "libs": "-lodbc32", "condition": "config.win32" }, + { "libs": "-liodbc", "condition": "config.darwin" }, + { "libs": "-lodbc", "condition": "!config.win32 && !config.darwin" } + ] + }, + "sqlite2": { + "label": "SQLite (version 2)", + "test": "unix/sqlite2", + "sources": [ + "-lsqlite" + ] + }, + "sqlite3": { + "label": "SQLite (version 3)", + "export": "sqlite", + "test": "unix/sqlite", + "sources": [ + { "type": "pkgConfig", "args": "sqlite3" }, + "-lsqlite3" + ], + "use": [ + { "lib": "zlib", "condition": "!config.win32 && features.system-zlib" } + ] + } + }, + + "tests": { + }, + + "features": { + "sql-db2": { + "label": "DB2 (IBM)", + "condition": "libs.db2", + "output": [ "privateFeature" ] + }, + "sql-ibase": { + "label": "InterBase", + "condition": "libs.ibase", + "output": [ "privateFeature" ] + }, + "sql-mysql": { + "label": "MySql", + "condition": "libs.mysql", + "output": [ "privateFeature" ] + }, + "sql-oci": { + "label": "OCI (Oracle)", + "condition": "libs.oci", + "output": [ "privateFeature" ] + }, + "sql-odbc": { + "label": "ODBC", + "condition": "features.datestring && libs.odbc", + "output": [ "privateFeature" ] + }, + "sql-psql": { + "label": "PostgreSQL", + "condition": "libs.psql", + "output": [ "privateFeature" ] + }, + "sql-sqlite2": { + "label": "SQLite2", + "condition": "libs.sqlite2", + "output": [ "privateFeature" ] + }, + "sql-sqlite": { + "label": "SQLite", + "condition": "features.datestring", + "output": [ "privateFeature" ] + }, + "system-sqlite": { + "label": " Using system provided SQLite", + "autoDetect": false, + "condition": "features.sql-sqlite && libs.sqlite3", + "output": [ "privateFeature" ] + }, + "sql-tds": { + "label": "TDS (Sybase)", + "condition": "features.datestring && libs.tds", + "output": [ "privateFeature" ] + } + }, + + "report": [ + { + "type": "warning", + "condition": "config.win32 && !config.msvc && features.sql-oci", + "message": "Qt does not support compiling the Oracle database driver with +MinGW, due to lack of such support from Oracle. Consider disabling the +Oracle driver, as the current build will most likely fail." + } + ], + + "summary": [ + { + "section": "Qt Sql", + "entries": [ + "sql-db2", "sql-ibase", "sql-mysql", "sql-oci", "sql-odbc", "sql-psql", + "sql-sqlite2", "sql-sqlite", "system-sqlite", "sql-tds" + ] + } + ] +} diff --git a/src/plugins/sqldrivers/configure.pri b/src/plugins/sqldrivers/configure.pri new file mode 100644 index 0000000000..9fb957291f --- /dev/null +++ b/src/plugins/sqldrivers/configure.pri @@ -0,0 +1,99 @@ +# custom tests + +defineReplace(filterLibraryPath) { + str = $${1} + for (l, QMAKE_DEFAULT_LIBDIRS): \ + str -= "-L$$l" + + return($$str) +} + +defineTest(qtConfLibrary_psqlConfig) { + pg_config = $$config.input.psql_config + isEmpty(pg_config): \ + pg_config = $$qtConfFindInPath("pg_config") + !win32:!isEmpty(pg_config) { + qtRunLoggedCommand("$$pg_config --libdir", libdir)|return(false) + qtRunLoggedCommand("$$pg_config --includedir", includedir)|return(false) + libdir -= $$QMAKE_DEFAULT_LIBDIRS + libs = + !isEmpty(libdir): libs += "-L$$libdir" + libs += "-lpq" + $${1}.libs = "$$val_escape(libs)" + includedir -= $$QMAKE_DEFAULT_INCDIRS + $${1}.includedir = "$$val_escape(includedir)" + export($${1}.libs) + export($${1}.includedir) + return(true) + } + qtLog("pg_config not found.") + return(false) +} + +defineTest(qtConfLibrary_psqlEnv) { + # Respect PSQL_LIBS if set + PSQL_LIBS = $$getenv(PSQL_LIBS) + !isEmpty(PSQL_LIBS) { + $${1}.libs = $$PSQL_LIBS + export($${1}.libs) + } else { + !qtConfLibrary_inline($$1): \ + return(false) + } + return(true) +} + +defineTest(qtConfLibrary_mysqlConfig) { + mysql_config = $$config.input.mysql_config + isEmpty(mysql_config): \ + mysql_config = $$qtConfFindInPath("mysql_config") + !isEmpty(mysql_config) { + qtRunLoggedCommand("$$mysql_config --version", version)|return(false) + version = $$split(version, '.') + version = $$first(version) + isEmpty(version)|lessThan(version, 4): return(false)] + + # query is either --libs or --libs_r + query = $$eval($${1}.query) + qtRunLoggedCommand("$$mysql_config $$query", libs)|return(false) + qtRunLoggedCommand("$$mysql_config --include", includedir)|return(false) + eval(libs = $$libs) + libs = $$filterLibraryPath($$libs) + # -rdynamic should not be returned by mysql_config, but is on RHEL 6.6 + libs -= -rdynamic + equals($${1}.cleanlibs, true) { + for(l, libs) { + # Drop all options besides the -L one and the -lmysqlclient one + # so we don't unnecessarily link to libs like OpenSSL + contains(l, "^(-L|-lmysqlclient).*"): cleanlibs += $$l + } + libs = $$cleanlibs + } + $${1}.libs = "$$val_escape(libs)" + eval(rawincludedir = $$includedir) + rawincludedir ~= s/^-I//g + includedir = + for (id, rawincludedir): \ + includedir += $$clean_path($$id) + includedir -= $$QMAKE_DEFAULT_INCDIRS + $${1}.includedir = "$$val_escape(includedir)" + export($${1}.libs) + export($${1}.includedir) + return(true) + } + qtLog("mysql_config not found.") + return(false) +} + +defineTest(qtConfLibrary_sybaseEnv) { + libs = + sybase = $$getenv(SYBASE) + !isEmpty(sybase): \ + libs += "-L$${sybase}/lib" + libs += $$getenv(SYBASE_LIBS) + !isEmpty(libs) { + $${1}.libs = "$$val_escape(libs)" + export($${1}.libs) + } + return(true) +} diff --git a/src/plugins/sqldrivers/qsqldriverbase.pri b/src/plugins/sqldrivers/qsqldriverbase.pri index 512c046ec1..4b78fa9454 100644 --- a/src/plugins/sqldrivers/qsqldriverbase.pri +++ b/src/plugins/sqldrivers/qsqldriverbase.pri @@ -1,5 +1,8 @@ QT = core core-private sql-private +# For QMAKE_USE in the parent projects. +include($$shadowed($$PWD)/qtsqldrivers-config.pri) + PLUGIN_TYPE = sqldrivers load(qt_plugin) diff --git a/src/plugins/sqldrivers/sqldrivers.pro b/src/plugins/sqldrivers/sqldrivers.pro index 30fb6019ce..8a9ae46f82 100644 --- a/src/plugins/sqldrivers/sqldrivers.pro +++ b/src/plugins/sqldrivers/sqldrivers.pro @@ -1,5 +1,9 @@ TEMPLATE = subdirs -QT_FOR_CONFIG += sql + +sqldrivers_standalone { + _QMAKE_CACHE_ = $$shadowed($$SQLDRV_SRC_TREE)/.qmake.conf + load(qt_configure) +} qtConfig(sql-psql) : SUBDIRS += psql qtConfig(sql-mysql) : SUBDIRS += mysql diff --git a/src/plugins/sqldrivers/sqlite/sqlite.pro b/src/plugins/sqldrivers/sqlite/sqlite.pro index 1066bf7f51..d7e19f97b1 100644 --- a/src/plugins/sqldrivers/sqlite/sqlite.pro +++ b/src/plugins/sqldrivers/sqlite/sqlite.pro @@ -1,10 +1,11 @@ TARGET = qsqlite -QT_FOR_CONFIG += sql-private - HEADERS += $$PWD/qsql_sqlite_p.h SOURCES += $$PWD/qsql_sqlite.cpp $$PWD/smain.cpp +include($$OUT_PWD/../qtsqldrivers-config.pri) +QT_FOR_CONFIG += sqldrivers-private + qtConfig(system-sqlite) { QMAKE_USE += sqlite } else { -- cgit v1.2.3