diff options
Diffstat (limited to 'share/qtcreator')
5 files changed, 55 insertions, 24 deletions
diff --git a/share/qtcreator/templates/wizards/autotest/files/googlecommon.js b/share/qtcreator/templates/wizards/autotest/files/googlecommon.js index 1079ed5fdf..7f754cc9e8 100644 --- a/share/qtcreator/templates/wizards/autotest/files/googlecommon.js +++ b/share/qtcreator/templates/wizards/autotest/files/googlecommon.js @@ -13,12 +13,13 @@ ** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** **/ +var File = require("qbs.File") var FileInfo = require("qbs.FileInfo") function getGTestDir(qbs, str) { if (!str) { - if (qbs.hostOS.contains("linux")) - return "/usr/include/gtest"; + if (qbs.hostOS.contains("linux") && File.exists("/usr/src/gtest")) + return "/usr/src/gtest"; } else { return FileInfo.joinPaths(str, "googletest"); } @@ -27,8 +28,8 @@ function getGTestDir(qbs, str) { function getGMockDir(qbs, str) { if (!str) { - if (qbs.hostOS.contains("linux")) - return "/usr/include/gmock"; + if (qbs.hostOS.contains("linux") && File.exists("/usr/src/gmock")) + return "/usr/src/gmock"; } else { return FileInfo.joinPaths(str, "googlemock"); } diff --git a/share/qtcreator/templates/wizards/autotest/files/gtest_dependency.pri b/share/qtcreator/templates/wizards/autotest/files/gtest_dependency.pri index c01bab677c..c064ef6242 100644 --- a/share/qtcreator/templates/wizards/autotest/files/gtest_dependency.pri +++ b/share/qtcreator/templates/wizards/autotest/files/gtest_dependency.pri @@ -1,31 +1,43 @@ isEmpty(GOOGLETEST_DIR):GOOGLETEST_DIR=$$(GOOGLETEST_DIR) isEmpty(GOOGLETEST_DIR) { - warning("Using googletest src dir specified at Qt Creator wizard") - message("set GOOGLETEST_DIR as environment variable or qmake variable to get rid of this message") GOOGLETEST_DIR = %{GTestRepository} + !isEmpty(GOOGLETEST_DIR) { + warning("Using googletest src dir specified at Qt Creator wizard") + message("set GOOGLETEST_DIR as environment variable or qmake variable to get rid of this message") + } } !isEmpty(GOOGLETEST_DIR): { GTEST_SRCDIR = $$GOOGLETEST_DIR/googletest GMOCK_SRCDIR = $$GOOGLETEST_DIR/googlemock +} else: unix { + exists(/usr/src/gtest):GTEST_SRCDIR=/usr/src/gtest + exists(/usr/src/gmock):GMOCK_SRCDIR=/usr/src/gmock + !isEmpty(GTEST_SRCDIR): message("Using gtest from system") } requires(exists($$GTEST_SRCDIR):exists($$GMOCK_SRCDIR)) -!exists($$GOOGLETEST_DIR):message("No googletest src dir found - set GOOGLETEST_DIR to enable.") - @if "%{GTestCXX11}" == "true" DEFINES += \\ GTEST_LANG_CXX11 @endif -INCLUDEPATH *= \\ - $$GTEST_SRCDIR \\ - $$GTEST_SRCDIR/include \\ - $$GMOCK_SRCDIR \\ - $$GMOCK_SRCDIR/include +!isEmpty(GTEST_SRCDIR) { + INCLUDEPATH *= \\ + $$GTEST_SRCDIR \\ + $$GTEST_SRCDIR/include + + SOURCES += \\ + $$GTEST_SRCDIR/src/gtest-all.cc +} -SOURCES += \\ - $$GTEST_SRCDIR/src/gtest-all.cc \\ - $$GMOCK_SRCDIR/src/gmock-all.cc +!isEmpty(GMOCK_SRCDIR) { + INCLUDEPATH *= \\ + $$GMOCK_SRCDIR \\ + $$GMOCK_SRCDIR/include + + SOURCES += \\ + $$GMOCK_SRCDIR/src/gmock-all.cc +} diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.qbs b/share/qtcreator/templates/wizards/autotest/files/tst.qbs index 92a0656d65..e66605f0a5 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst.qbs +++ b/share/qtcreator/templates/wizards/autotest/files/tst.qbs @@ -26,8 +26,12 @@ CppApplication { @if "%{TestFrameWork}" == "GTest" property string googletestDir: { if (typeof Environment.getEnv("GOOGLETEST_DIR") === 'undefined') { - console.warn("Using googletest src dir specified at Qt Creator wizard") - console.log("set GOOGLETEST_DIR as environment variable or Qbs property to get rid of this message") + if ("%{GTestRepository}" === "" && googleCommon.getGTestDir(qbs, undefined) !== "") { + console.warn("Using googletest from system") + } else { + console.warn("Using googletest src dir specified at Qt Creator wizard") + console.log("set GOOGLETEST_DIR as environment variable or Qbs property to get rid of this message") + } return "%{GTestRepository}" } else { return Environment.getEnv("GOOGLETEST_DIR") diff --git a/share/qtcreator/templates/wizards/autotest/files/tst.txt b/share/qtcreator/templates/wizards/autotest/files/tst.txt index bf5e75ff16..f1d57e97ab 100644 --- a/share/qtcreator/templates/wizards/autotest/files/tst.txt +++ b/share/qtcreator/templates/wizards/autotest/files/tst.txt @@ -62,22 +62,35 @@ find_package(Threads REQUIRED) if ($ENV{GOOGLETEST_DIR}) set(GOOGLETEST_DIR $ENV{GOOGLETEST_DIR}) else () - message(WARNING "Using googletest src dir specified at Qt Creator wizard") + if (NOT "%{GTestRepository}" STREQUAL "") + message(WARNING "Using googletest src dir specified at Qt Creator wizard") + endif () set(GOOGLETEST_DIR "%{GTestRepository}") endif () if (EXISTS ${GOOGLETEST_DIR}) set(GTestSrc ${GOOGLETEST_DIR}/googletest) set(GMockSrc ${GOOGLETEST_DIR}/googlemock) +elseif (UNIX AND EXISTS /usr/src/gtest) + set(GTestSrc /usr/src/gtest) + message(WARNING "Using gtest from system") + if (EXISTS /usr/src/gmock) + set(GMockSrc /usr/src/gmock) + endif () else () message( FATAL_ERROR "No googletest src dir found - set GOOGLETEST_DIR to enable!") endif () +set(GTestFiles ${GTestSrc}/src/gtest-all.cc) +set(GTestIncludes ${GTestSrc} ${GTestSrc}/include) +if (NOT ${GMockSrc} STREQUAL "") + list(APPEND GTestFiles ${GMockSrc}/src/gmock-all.cc) + list(APPEND GTestIncludes ${GMockSrc} ${GMockSrc}/include) +endif () -include_directories(${GTestSrc} ${GTestSrc}/include ${GMockSrc} ${GMockSrc}/include) +include_directories(${GTestIncludes}) add_executable(%{TestCaseName} %{MainCppName} %{TestCaseFileWithHeaderSuffix} - ${GTestSrc}/src/gtest-all.cc - ${GMockSrc}/src/gmock-all.cc) + ${GTestFiles}) add_test(%{TestCaseName} COMMAND %{TestCaseName}) target_link_libraries(%{TestCaseName} PRIVATE Threads::Threads) diff --git a/share/qtcreator/templates/wizards/autotest/wizard.json b/share/qtcreator/templates/wizards/autotest/wizard.json index 83a4be09a4..6744a14a8c 100644 --- a/share/qtcreator/templates/wizards/autotest/wizard.json +++ b/share/qtcreator/templates/wizards/autotest/wizard.json @@ -149,8 +149,9 @@ }, { "name": "GTestRepository", - "trDisplayName": "Googletest repository:", + "trDisplayName": "Googletest source directory (optional):", "visible": "%{JS: value('TestFrameWork') === 'GTest'}", + "mandatory": false, "type": "PathChooser", "data": { "kind": "existingDirectory" @@ -158,7 +159,7 @@ }, { "name": "BoostIncDir", - "trDisplayName": "Boost include dir (optional):", + "trDisplayName": "Boost include directory (optional):", "visible": "%{JS: value('TestFrameWork') == 'BoostTest'}", "mandatory": false, "type": "PathChooser", |