From 0526d3be12d06a32761fc74a38825f9192ba49ca Mon Sep 17 00:00:00 2001
From: Don Gagne <don@thegagnes.com>
Date: Wed, 25 Dec 2013 15:16:34 -0800
Subject: [PATCH] Unit Tests are now part of main build
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- debug builds always compile unit tests in
- seperate qgcunittest.pro is no longer needed
- found out the hard way that you can’t use debug or release as a
scope. You need to use the CONFIG(debug,debug|relase) macro (in this
example to test fro debug). Reason is that debug and release show up
multiple times in CONFIG, last debug wins. This is what the CONFIG
macro does. Without it, it’s luck as to what you get. I found OSX was
getting debug, Linux was getting a debug build, build into release
directories. QT_DEBUG set randomly. Lot’s of problems.
---
 qgcunittest.pro    | 35 -----------------------------------
 qgroundcontrol.pri | 10 +++++-----
 qgroundcontrol.pro | 21 ++++++++++++++++++---
 3 files changed, 23 insertions(+), 43 deletions(-)
 delete mode 100644 qgcunittest.pro

diff --git a/qgcunittest.pro b/qgcunittest.pro
deleted file mode 100644
index f7f3ed2..0000000
--- a/qgcunittest.pro
+++ /dev/null
@@ -1,35 +0,0 @@
-# -------------------------------------------------
-# QGroundControl - Micro Air Vehicle Groundstation
-# Please see our website at <http://qgroundcontrol.org>
-# Maintainer:
-# Lorenz Meier <lm@inf.ethz.ch>
-# (c) 2009-2011 QGroundControl Developers
-# This file is part of the open groundstation project
-# QGroundControl is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-# QGroundControl is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-# You should have received a copy of the GNU General Public License
-# along with QGroundControl. If not, see <http://www.gnu.org/licenses/>.
-# -------------------------------------------------
-
-
-TARGET = qgcunittest
-QT += testlib
-
-QGCS_UNITTEST_OVERRIDE = true
-include (qgroundcontrol.pro)
-
-TESTDIR = $$BASEDIR/src/qgcunittest
-
-HEADERS += \
-    $$TESTDIR/AutoTest.h \
-    $$TESTDIR/UASUnitTest.h \
-
-SOURCES += \
-    $$TESTDIR/testSuite.cc \
-    $$TESTDIR/UASUnitTest.cc
\ No newline at end of file
diff --git a/qgroundcontrol.pri b/qgroundcontrol.pri
index 859a4ee..bdd264a 100644
--- a/qgroundcontrol.pri
+++ b/qgroundcontrol.pri
@@ -175,7 +175,7 @@ linux-g++|linux-g++-64{
 	CONFIG -= console
 	DEFINES += __STDC_LIMIT_MACROS
 
-	release {
+	CONFIG(release, debug|release) {
 		DEFINES += QT_NO_DEBUG
 	}
 
@@ -429,11 +429,11 @@ win32-g++ {
 
 
 
-	debug {
+	CONFIG(debug, debug|release) {
 		CONFIG += console
 	}
 
-	release {
+	CONFIG(release, debug|release) {
 		CONFIG -= console
 		DEFINES += QT_NO_DEBUG
 	}
@@ -445,14 +445,14 @@ win32-g++ {
 	system(cp): {
 		# CP command is available, use it instead of copy / xcopy
 		message("Using cp to copy image and audio files to executable")
-		debug {
+		CONFIG(debug, debug|release) {
 			QMAKE_POST_LINK += && cp $$BASEDIR/libs/lib/sdl/win32/SDL.dll $$TARGETDIR/debug/SDL.dll
 			QMAKE_POST_LINK += && cp -r $$BASEDIR/files $$TARGETDIR/debug/files
                         QMAKE_POST_LINK += && cp -r $$BASEDIR/libs/mavlink $$TARGETDIR/debug/mavlink
 			QMAKE_POST_LINK += && cp -r $$BASEDIR/models $$TARGETDIR/debug/models
 		}
 
-		release {
+		CONFIG(release, debug|release) {
 			QMAKE_POST_LINK += && cp $$BASEDIR/libs/lib/sdl/win32/SDL.dll $$TARGETDIR/release/SDL.dll
 			QMAKE_POST_LINK += && cp -r $$BASEDIR/files $$TARGETDIR/release/files
                         QMAKE_POST_LINK += && cp -r $$BASEDIR/libs/mavlink $$TARGETDIR/release/mavlink
diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro
index e36ae25..6da2b5d 100644
--- a/qgroundcontrol.pro
+++ b/qgroundcontrol.pro
@@ -30,7 +30,8 @@ QT += network \
     phonon \
     webkit \
     sql \
-    declarative
+    declarative \
+    testlib
 
 # Setting this variable allows you to include this .pro file in another such that
 # you can set your own TARGET and main() function. This is used by the unit test
@@ -43,11 +44,11 @@ isEmpty(QGCS_UNITTEST_OVERRIDE) {
 
 BASEDIR = $${IN_PWD}
 linux-g++|linux-g++-64{
-    debug {
+    CONFIG(debug, debug|release) {
         TARGETDIR = $${OUT_PWD}/debug
         BUILDDIR = $${OUT_PWD}/build-debug
     }
-    release {
+    CONFIG(release, debug|release) {
         TARGETDIR = $${OUT_PWD}/release
         BUILDDIR = $${OUT_PWD}/build-release
     }
@@ -736,6 +737,20 @@ SOURCES += \
     src/ui/designer/QGCXYPlot.cc \
     src/ui/menuactionhelper.cpp
 
+CONFIG(debug, debug|release) {
+    # Unit Test sources/headers go here
+    
+    INCLUDEPATH += \
+        src/qgcunittest
+
+    HEADERS += \
+        src/qgcunittest/AutoTest.h \
+        src/qgcunittest/UASUnitTest.h
+
+    SOURCES += \
+        src/qgcunittest/UASUnitTest.cc
+}
+
 # Enable Google Earth only on Mac OS and Windows with Visual Studio compiler
 macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc