summaryrefslogtreecommitdiff
path: root/share/qtcreator/templates
diff options
context:
space:
mode:
authorChristian Stenger <christian.stenger@qt.io>2019-08-21 13:54:19 +0200
committerChristian Stenger <christian.stenger@qt.io>2019-09-12 08:50:36 +0000
commit90189ec3d14e2cdb3777bb4bc09db4ee9bcaed69 (patch)
tree854feae6bcf32bf2be47457835689ec1cecbc705 /share/qtcreator/templates
parent45cd20c4a05a9b8d7e8fef021f6008730233e88a (diff)
downloadqt-creator-90189ec3d14e2cdb3777bb4bc09db4ee9bcaed69.tar.gz
AutoTest: Wizard: Soften condition for gtest repository
Make the need for the googletest repository optional. The user may have gtest installed inside the system instead. Change-Id: I4959878fa893d6b8ed53fd612934d7cd4504a6b7 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'share/qtcreator/templates')
-rw-r--r--share/qtcreator/templates/wizards/autotest/files/googlecommon.js9
-rw-r--r--share/qtcreator/templates/wizards/autotest/files/gtest_dependency.pri36
-rw-r--r--share/qtcreator/templates/wizards/autotest/files/tst.qbs8
-rw-r--r--share/qtcreator/templates/wizards/autotest/files/tst.txt21
-rw-r--r--share/qtcreator/templates/wizards/autotest/wizard.json5
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",