From 9233e70977767bdc354cb81f105721ab41940a35 Mon Sep 17 00:00:00 2001 From: iakov Date: Wed, 21 Dec 2016 23:11:28 +0300 Subject: [PATCH] Fix OS X build. Need to check Win32, Linux & TRIK OS builds --- .gitignore | 2 + global.pri | 116 ++++++++++++++---- tests/common.pri | 5 +- .../trikScriptRunnerTest.cpp | 1 + trikControl/src/analogSensor.h | 2 +- trikControl/src/eventDevice.h | 1 + trikControl/src/gyroSensor.cpp | 2 +- trikControl/src/vectorSensorWorker.h | 1 + trikGui/mac/powerLevel.cpp | 22 ++++ trikGui/motorsWidget.cpp | 2 + trikGui/scriptHolder.h | 2 +- trikHal/trikHal.pro | 4 +- trikKernel/include/trikKernel/timeVal.h | 2 +- trikKernel/src/mac/coreDumping.cpp | 19 +++ .../src/mac/wpaSupplicantCommunicator.cpp | 74 +++++++++++ 15 files changed, 225 insertions(+), 30 deletions(-) create mode 100644 trikGui/mac/powerLevel.cpp create mode 100644 trikKernel/src/mac/coreDumping.cpp create mode 100644 trikWiFi/src/mac/wpaSupplicantCommunicator.cpp diff --git a/.gitignore b/.gitignore index d8a73bf2c..8c5b78910 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ moc_*.cpp ui_*.h qrc_*.cpp +Thumbs.db Makefile* *.pro.user* bin/* @@ -31,3 +32,4 @@ object_script.*.Release # project-specific **/.build tests/minimalCppApp/* +.qmake.stash diff --git a/global.pri b/global.pri index 028b2dc66..7398d91f6 100644 --- a/global.pri +++ b/global.pri @@ -1,10 +1,10 @@ -# Copyright 2014 - 2016 CyberTech Co. Ltd., Yurii Litvinov. +# Copyright 2014 - 2016 CyberTech Co. Ltd., Yurii Litvinov, Iakov Kirilenko # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -20,7 +20,7 @@ # # Uses environment variable INSTALL_ROOT as a root of a file structure for install rules. # -# Uses CONFIG variable to control support for Google Sanitizers (in linux-x86 debug mode only): +# Uses CONFIG variable to control support for Google Sanitizers: # - CONFIG+=sanitize-address will enable address sanitizer # - CONFIG+=sanitize-undefined will enable undefined behavior sanitizer # - CONFIG+=sanitize-thread will enable thread sanitizer @@ -37,17 +37,23 @@ count(COMPILER_IS_ARM, 1) { win32 { PLATFORM = windows -} else { +} + +unix:!macx { PLATFORM = linux } +macx { + PLATFORM = mac +} + CONFIG(debug, debug | release) { CONFIGURATION = $$ARCHITECTURE-debug CONFIGURATION_SUFFIX = -$$ARCHITECTURE-d QMAKE_CXXFLAGS += -coverage QMAKE_LFLAGS += -coverage # Address sanitizer is on by default - !CONFIG(no-sanitizers) { + !CONFIG(nosanitizers) { CONFIG += sanitize-address } } else { @@ -64,19 +70,81 @@ DESTDIR = $$PWD/bin/$$CONFIGURATION PROJECT_BASENAME = $$basename(_PRO_FILE_) PROJECT_NAME = $$section(PROJECT_BASENAME, ".", 0, 0) -TARGET = $$PROJECT_NAME$$CONFIGURATION_SUFFIX +isEmpty(TARGET) { + TARGET = $$PROJECT_NAME$$CONFIGURATION_SUFFIX +} else { + TARGET = $$TARGET$$CONFIGURATION_SUFFIX +} equals(TEMPLATE, app) { - !macx { - QMAKE_LFLAGS += -Wl,-O1,-rpath,. + unix:!macx { QMAKE_LFLAGS += -Wl,-rpath-link,$$DESTDIR + !CONFIG(no_rpath) QMAKE_LFLAGS += -Wl,-O1,-rpath,. + } +} + +macx-clang { + QMAKE_CXXFLAGS += -stdlib=libc++ + QMAKE_LFLAGS_SONAME = -Wl,-install_name,@executable_path/../../../ +} + +unix:!CONFIG(nosanitizers) { + + # seems like we want USan always, but are afraid of .... + !CONFIG(sanitize_address):!CONFIG(sanitize_thread):!CONFIG(sanitize_memory):!CONFIG(sanitize_kernel_address) { + # Ubsan is turned on by default + CONFIG += sanitizer sanitize_undefined + } + + CONFIG(debug, debug | release):!CONFIG(sanitize_address):!macx-clang { CONFIG += sanitize_leak } + + CONFIG(sanitize_leak) { + #LSan can be used without performance degrade even in release build + QMAKE_CFLAGS += -fsanitize=leak + QMAKE_CXXFLAGS += -fsanitize=leak + QMAKE_LFLAGS += -fsanitize=leak + } + + CONFIG(sanitize_undefined):macx-clang { + # sometimes runtime is missing in clang. this hack allows to avoid runtime dependency. + QMAKE_SANITIZE_UNDEFINED_CFLAGS += -fsanitize-trap=undefined + QMAKE_SANITIZE_UNDEFINED_CXXFLAGS += -fsanitize-trap=undefined + QMAKE_SANITIZE_UNDEFINED_LFLAGS += -fsanitize-trap=undefined + } + + + !clang:gcc:*-g++*:system($$QMAKE_CXX --version | grep -oe \'\\<5\\.[0-9]\\+\\.\' ){ + CONFIG(sanitize_undefined){ + # Ubsan has (had at least) known issues with false errors about calls of methods of the base class. + # That must be disabled. Variables for confguring ubsan are taken from here: + # https://codereview.qt-project.org/#/c/43420/17/mkspecs/common/sanitize.conf + # They can change in some version of Qt, keep track of it. + # By the way, simply setting QMAKE_CFLAGS, QMAKE_CXXFLAGS and QMAKE_LFLAGS instead of those used below + # will not work due to arguments order ("-fsanitize=undefined" must be declared before "-fno-sanitize=vptr"). + QMAKE_SANITIZE_UNDEFINED_CFLAGS += -fno-sanitize=vptr + QMAKE_SANITIZE_UNDEFINED_CXXFLAGS += -fno-sanitize=vptr + QMAKE_SANITIZE_UNDEFINED_LFLAGS += -fno-sanitize=vptr + } + } + + CONFIG(release, debug | release){ + !clang:gcc:*-g++*:system($$QMAKE_CXX --version | grep -oe \'\\<4\\.[0-9]\\+\\.\' ){ + message("Too old compiler: $$QMAKE_CXX") + } else { + QMAKE_CFLAGS += -fsanitize-recover=all + QMAKE_CXXFLAGS += -fsanitize-recover=all + } } + } -OBJECTS_DIR = .build/$$CONFIGURATION/.obj -MOC_DIR = .build/$$CONFIGURATION/.moc -RCC_DIR = .build/$$CONFIGURATION/.rcc -UI_DIR = .build/$$CONFIGURATION/.ui +OBJECTS_DIR = .build/$$CONFIGURATION/obj +MOC_DIR = .build/$$CONFIGURATION/moc +RCC_DIR = .build/$$CONFIGURATION/rcc +UI_DIR = .build/$$CONFIGURATION/ui + +PRECOMPILED_HEADER = $$PWD/pch.h +CONFIG += precompile_header INCLUDEPATH += $$_PRO_FILE_PWD_ \ $$_PRO_FILE_PWD_/include/$$PROJECT_NAME \ @@ -84,8 +152,7 @@ INCLUDEPATH += $$_PRO_FILE_PWD_ \ INCLUDEPATH += \ $$PWD/qslog \ -PRECOMPILED_HEADER = $$PWD/pch.h -CONFIG += precompile_header + LIBS += -L$$DESTDIR @@ -95,10 +162,12 @@ isEmpty(IS_QSLOG) { LIBS += -lqslog$$CONFIGURATION_SUFFIX } -QMAKE_CXXFLAGS += -fno-elide-constructors -pedantic-errors -ansi -std=c++11 +CONFIG += c++11 +QMAKE_CXXFLAGS += -fno-elide-constructors -pedantic-errors -Werror=pedantic -ansi -std=c++11 #I whant -Werror to be turned on, but Qt has problems QMAKE_CXXFLAGS += -Wextra -Wcast-qual -Wwrite-strings -Wredundant-decls -Wunreachable-code -Wnon-virtual-dtor -Woverloaded-virtual -Wuninitialized -Winit-self #-Wold-style-cast -Wmissing-declarations + GLOBAL_PWD = $$PWD # Useful function to copy additional files to destination, @@ -109,26 +178,26 @@ defineTest(copyToDestdir) { for(FILE, FILES) { DESTDIR_SUFFIX = + AFTER_SLASH = $$section(FILE, "/", -1, -1) isEmpty(QMAKE_SH) { # This ugly code is needed because xcopy requires to add source directory name to target directory name when copying directories win32 { - AFTER_SLASH = $$section(FILE, "/", -1, -1) BASE_NAME = $$section(FILE, "/", -2, -2) equals(AFTER_SLASH, ""):DESTDIR_SUFFIX = /$$BASE_NAME FILE ~= s,/$,,g - FILE ~= s,/,\,g + FILE ~= s,/,\\,g } DDIR = $$DESTDIR$$DESTDIR_SUFFIX/$$3 - win32:DDIR ~= s,/,\,g + win32:DDIR ~= s,/,\\,g } else { DDIR = $$DESTDIR$$DESTDIR_SUFFIX/$$3 } isEmpty(NOW) { # In case this is directory add "*" to copy contents of a directory instead of directory itself under linux. - !win32:equals(AFTER_SLASH, ""):FILE = $$FILE* + !win32:equals(AFTER_SLASH, ""):FILE = $$FILE'.' QMAKE_POST_LINK += $(COPY_DIR) $$quote($$FILE) $$quote($$DDIR) $$escape_expand(\\n\\t) } else { win32 { @@ -142,7 +211,7 @@ defineTest(copyToDestdir) { } macx { - system("cp -R $$FILE $$DDIR/$$FILE") + system("cp -af $$FILE $$DDIR/") } } } @@ -249,20 +318,21 @@ defineTest(noPch) { export(PRECOMPILED_HEADER) } +#seems obsolete, atleast for qmake-qt5 unix:equals(ARCHITECTURE, "x86") { CONFIG(debug) { QMAKE_CXXFLAGS += -fno-omit-frame-pointer - CONFIG(sanitize-address) { + CONFIG(sanitize_address) { QMAKE_CXXFLAGS += -fsanitize=address QMAKE_LFLAGS += -fsanitize=address } - CONFIG(sanitize-undefined) { + CONFIG(sanitize_undefined) { # UBSan does not play well with precompiled headers for some reason. noPch() QMAKE_CXXFLAGS += -fsanitize=undefined QMAKE_LFLAGS += -fsanitize=undefined } - CONFIG(sanitize-thread) { + CONFIG(sanitize_thread) { QMAKE_CXXFLAGS += -fsanitize=thread QMAKE_LFLAGS += -fsanitize=thread LIBS += -ltsan diff --git a/tests/common.pri b/tests/common.pri index d314502a3..4bfdc302e 100644 --- a/tests/common.pri +++ b/tests/common.pri @@ -29,7 +29,10 @@ LIBS += -lgmock$$CONFIGURATION_SUFFIX SOURCES = $$PWD/mainTest.cpp -QMAKE_CXXFLAGS += -Wno-unused-local-typedefs +QMAKE_CXXFLAGS += -Wno-unused-local-typedef -Wno-error=pedantic + +DEFINES += GTEST_USE_OWN_TR1_TUPLE + OTHER_FILES += \ $$PWD/test-system-config.xml \ diff --git a/tests/trikScriptRunnerTests/trikScriptRunnerTest.cpp b/tests/trikScriptRunnerTests/trikScriptRunnerTest.cpp index f89ba801f..e5421df6c 100644 --- a/tests/trikScriptRunnerTests/trikScriptRunnerTest.cpp +++ b/tests/trikScriptRunnerTests/trikScriptRunnerTest.cpp @@ -15,6 +15,7 @@ #include "trikScriptRunnerTest.h" #include +#include #include #include diff --git a/trikControl/src/analogSensor.h b/trikControl/src/analogSensor.h index fc7e56757..0da05045c 100644 --- a/trikControl/src/analogSensor.h +++ b/trikControl/src/analogSensor.h @@ -48,7 +48,7 @@ class AnalogSensor : public SensorInterface public slots: /// Returns current reading of a sensor. - int read(); + int read() override; /// Returns current raw reading of a sensor. int readRawData() override; diff --git a/trikControl/src/eventDevice.h b/trikControl/src/eventDevice.h index 05eadd1e2..5ef96c9c0 100644 --- a/trikControl/src/eventDevice.h +++ b/trikControl/src/eventDevice.h @@ -15,6 +15,7 @@ #pragma once #include +#include #include "eventDeviceInterface.h" #include "deviceState.h" diff --git a/trikControl/src/gyroSensor.cpp b/trikControl/src/gyroSensor.cpp index d1d000976..f2aa2e318 100644 --- a/trikControl/src/gyroSensor.cpp +++ b/trikControl/src/gyroSensor.cpp @@ -24,7 +24,7 @@ using namespace trikControl; static constexpr float GYRO_250DPS = 8.75; -static constexpr double pi() { return std::acos(-1); } +static constexpr double pi() { return 3.14159265358979323846;} static constexpr float RAD_TO_MDEG = 1000 * 180 / pi(); GyroSensor::GyroSensor(const QString &deviceName, const trikKernel::Configurer &configurer diff --git a/trikControl/src/vectorSensorWorker.h b/trikControl/src/vectorSensorWorker.h index bd2c51f68..f6c0f5609 100644 --- a/trikControl/src/vectorSensorWorker.h +++ b/trikControl/src/vectorSensorWorker.h @@ -19,6 +19,7 @@ #include #include #include +#include #include diff --git a/trikGui/mac/powerLevel.cpp b/trikGui/mac/powerLevel.cpp new file mode 100644 index 000000000..62df424bb --- /dev/null +++ b/trikGui/mac/powerLevel.cpp @@ -0,0 +1,22 @@ +/* Copyright 2016 CyberTech Labs Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + +#include "powerLevel.h" + +using namespace trikGui; + +PowerLevel::Level PowerLevel::currentLevel() +{ + return Level::twelveVolt; +} diff --git a/trikGui/motorsWidget.cpp b/trikGui/motorsWidget.cpp index 99b3af2dc..f0bbb3eb2 100644 --- a/trikGui/motorsWidget.cpp +++ b/trikGui/motorsWidget.cpp @@ -26,6 +26,8 @@ #include #endif +#include + #include "motorLever.h" using namespace trikGui; diff --git a/trikGui/scriptHolder.h b/trikGui/scriptHolder.h index 1c8f963cf..4e11374ff 100644 --- a/trikGui/scriptHolder.h +++ b/trikGui/scriptHolder.h @@ -17,7 +17,7 @@ #include #include - +#include namespace trikGui { /// Class which contains program from programming widget. diff --git a/trikHal/trikHal.pro b/trikHal/trikHal.pro index 9c8394349..bdc093563 100644 --- a/trikHal/trikHal.pro +++ b/trikHal/trikHal.pro @@ -26,7 +26,7 @@ PUBLIC_HEADERS += \ $$PWD/include/trikHal/outputDeviceFileInterface.h \ $$PWD/include/trikHal/systemConsoleInterface.h \ -!win32 { +!win32:!macx { HEADERS += \ $$PWD/src/trik/trikHardwareAbstraction.h \ $$PWD/src/trik/trikMspI2c.h \ @@ -50,7 +50,7 @@ HEADERS += \ $$PWD/src/stub/stubOutputDeviceFile.h \ $$PWD/src/stub/stubFifo.h \ -!win32 { +!win32:!macx { SOURCES += \ $$PWD/src/trik/trikHardwareAbstraction.cpp \ $$PWD/src/trik/trikMspI2c.cpp \ diff --git a/trikKernel/include/trikKernel/timeVal.h b/trikKernel/include/trikKernel/timeVal.h index 1c7384a1e..4e1d37882 100644 --- a/trikKernel/include/trikKernel/timeVal.h +++ b/trikKernel/include/trikKernel/timeVal.h @@ -47,7 +47,7 @@ class TimeVal /// It is a friend method for hiding default constructor. friend void *qMetaTypeConstructHelper(const TimeVal *t); #else - friend class QtMetaTypePrivate::QMetaTypeFunctionHelper; + friend struct QtMetaTypePrivate::QMetaTypeFunctionHelper; #endif /// "Minus" operator is for computing time interval between two timestamps, returns value in microsends. diff --git a/trikKernel/src/mac/coreDumping.cpp b/trikKernel/src/mac/coreDumping.cpp new file mode 100644 index 000000000..d355894b2 --- /dev/null +++ b/trikKernel/src/mac/coreDumping.cpp @@ -0,0 +1,19 @@ +/* Copyright 2014 - 2015 CyberTech Labs Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + +#include "coreDumping.h" + +void trikKernel::coreDumping::initCoreDumping() +{ +} diff --git a/trikWiFi/src/mac/wpaSupplicantCommunicator.cpp b/trikWiFi/src/mac/wpaSupplicantCommunicator.cpp new file mode 100644 index 000000000..b22561d3d --- /dev/null +++ b/trikWiFi/src/mac/wpaSupplicantCommunicator.cpp @@ -0,0 +1,74 @@ +/* Copyright 2013 Roman Kurbatov, Yurii Litvinov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + +#include "src/wpaSupplicantCommunicator.h" + +using namespace trikWiFi; + +struct sockaddr_un +{ + int x; +}; + +WpaSupplicantCommunicator::WpaSupplicantCommunicator( + const QString &interfaceFile + , const QString &daemonFile + , QObject *parent + ) + : QObject(parent) + , mLocal(new sockaddr_un()) + , mDest(new sockaddr_un()) +{ + Q_UNUSED(interfaceFile); + Q_UNUSED(daemonFile); +} + +WpaSupplicantCommunicator::~WpaSupplicantCommunicator() +{ +} + +int WpaSupplicantCommunicator::fileDescriptor() +{ + return -1; +} + +int WpaSupplicantCommunicator::attach() +{ + return -1; +} + +int WpaSupplicantCommunicator::detach() +{ + return -1; +} + +int WpaSupplicantCommunicator::request(const QString &command, QString &reply) +{ + Q_UNUSED(command); + Q_UNUSED(reply); + + return -1; +} + +bool WpaSupplicantCommunicator::isPending() +{ + return false; +} + +int WpaSupplicantCommunicator::receive(QString &message) +{ + Q_UNUSED(message); + + return 0; +}