diff --git a/.gitignore b/.gitignore index 9959229f5f..8ea2698e72 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ tags *.orig Firmware.zip unittests/build +*.generated.h diff --git a/.travis.yml b/.travis.yml index f75d034eb4..fd2a6b6d1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,6 +42,7 @@ script: - arm-none-eabi-gcc --version - echo 'Running Tests..' && echo -en 'travis_fold:start:script.1\\r' - make tests + - cat src/modules/systemlib/mixer/mixer_multirotor.generated.h - echo -en 'travis_fold:end:script.1\\r' - echo 'Building NuttX..' && echo -en 'travis_fold:start:script.2\\r' - make archives diff --git a/src/modules/px4iofirmware/module.mk b/src/modules/px4iofirmware/module.mk index eb99e8a966..844e493cd4 100644 --- a/src/modules/px4iofirmware/module.mk +++ b/src/modules/px4iofirmware/module.mk @@ -1,5 +1,4 @@ - SRCS = adc.c \ controls.c \ dsm.c \ @@ -24,3 +23,7 @@ ifeq ($(BOARD),px4io-v2) SRCS += serial.c \ ../systemlib/hx_stream.c endif + +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(SELF_DIR)../systemlib/mixer/multi_tables.mk + \ No newline at end of file diff --git a/src/modules/systemlib/mixer/mixer.h b/src/modules/systemlib/mixer/mixer.h index 1fe4380ade..864ce21a58 100644 --- a/src/modules/systemlib/mixer/mixer.h +++ b/src/modules/systemlib/mixer/mixer.h @@ -441,6 +441,15 @@ private: SimpleMixer operator=(const SimpleMixer&); }; + +/** + * Supported multirotor geometries. + * + * Values are generated by the multi_tables script and placed to mixer_multirotor.generated.h + */ +typedef unsigned int MultirotorGeometryUnderlyingType; +enum class MultirotorGeometry : MultirotorGeometryUnderlyingType; + /** * Multi-rotor mixer for pre-defined vehicle geometries. * @@ -450,27 +459,6 @@ private: class __EXPORT MultirotorMixer : public Mixer { public: - /** - * Supported multirotor geometries. - * - * XXX add more - */ - enum Geometry { - QUAD_X = 0, /**< quad in X configuration */ - QUAD_PLUS, /**< quad in + configuration */ - QUAD_V, /**< quad in V configuration */ - QUAD_WIDE, /**< quad in wide configuration */ - HEX_X, /**< hex in X configuration */ - HEX_PLUS, /**< hex in + configuration */ - HEX_COX, - OCTA_X, - OCTA_PLUS, - OCTA_COX, - TWIN_ENGINE, /**< VTOL: one engine on each wing */ - - MAX_GEOMETRY - }; - /** * Precalculated rotor mix. */ @@ -498,7 +486,7 @@ public: */ MultirotorMixer(ControlCallback control_cb, uintptr_t cb_handle, - Geometry geometry, + MultirotorGeometry geometry, float roll_scale, float pitch_scale, float yaw_scale, diff --git a/src/modules/systemlib/mixer/mixer_multirotor.cpp b/src/modules/systemlib/mixer/mixer_multirotor.cpp index eb1aef6c1c..5cfbe47f07 100644 --- a/src/modules/systemlib/mixer/mixer_multirotor.cpp +++ b/src/modules/systemlib/mixer/mixer_multirotor.cpp @@ -55,6 +55,9 @@ #include "mixer.h" +// This file is generated by the multi_tables script which is invoked during the build process +#include "mixer_multirotor.generated.h" + #define debug(fmt, args...) do { } while(0) //#define debug(fmt, args...) do { printf("[mixer] " fmt "\n", ##args); } while(0) //#include @@ -72,125 +75,11 @@ float constrain(float val, float min, float max) { return (val < min) ? min : ((val > max) ? max : val); } - -/* - * These tables automatically generated by multi_tables - do not edit. - */ - -const MultirotorMixer::Rotor _config_quad_x[] = { - { -0.707107, 0.707107, 1.000000 }, - { 0.707107, -0.707107, 1.000000 }, - { 0.707107, 0.707107, -1.000000 }, - { -0.707107, -0.707107, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_quad_plus[] = { - { -1.000000, 0.000000, 1.000000 }, - { 1.000000, 0.000000, 1.000000 }, - { 0.000000, 1.000000, -1.000000 }, - { -0.000000, -1.000000, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_quad_v[] = { - { -0.322266, 0.946649, 0.424200 }, - { 0.322266, 0.946649, 1.000000 }, - { 0.322266, 0.946649, -0.424200 }, - { -0.322266, 0.946649, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_quad_wide[] = { - { -0.927184, 0.374607, 1.000000 }, - { 0.777146, -0.629320, 1.000000 }, - { 0.927184, 0.374607, -1.000000 }, - { -0.777146, -0.629320, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_hex_x[] = { - { -1.000000, 0.000000, -1.000000 }, - { 1.000000, 0.000000, 1.000000 }, - { 0.500000, 0.866025, -1.000000 }, - { -0.500000, -0.866025, 1.000000 }, - { -0.500000, 0.866025, 1.000000 }, - { 0.500000, -0.866025, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_hex_plus[] = { - { 0.000000, 1.000000, -1.000000 }, - { -0.000000, -1.000000, 1.000000 }, - { 0.866025, -0.500000, -1.000000 }, - { -0.866025, 0.500000, 1.000000 }, - { 0.866025, 0.500000, 1.000000 }, - { -0.866025, -0.500000, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_hex_cox[] = { - { -0.866025, 0.500000, -1.000000 }, - { -0.866025, 0.500000, 1.000000 }, - { -0.000000, -1.000000, -1.000000 }, - { -0.000000, -1.000000, 1.000000 }, - { 0.866025, 0.500000, -1.000000 }, - { 0.866025, 0.500000, 1.000000 }, -}; -const MultirotorMixer::Rotor _config_octa_x[] = { - { -0.382683, 0.923880, -1.000000 }, - { 0.382683, -0.923880, -1.000000 }, - { -0.923880, 0.382683, 1.000000 }, - { -0.382683, -0.923880, 1.000000 }, - { 0.382683, 0.923880, 1.000000 }, - { 0.923880, -0.382683, 1.000000 }, - { 0.923880, 0.382683, -1.000000 }, - { -0.923880, -0.382683, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_octa_plus[] = { - { 0.000000, 1.000000, -1.000000 }, - { -0.000000, -1.000000, -1.000000 }, - { -0.707107, 0.707107, 1.000000 }, - { -0.707107, -0.707107, 1.000000 }, - { 0.707107, 0.707107, 1.000000 }, - { 0.707107, -0.707107, 1.000000 }, - { 1.000000, 0.000000, -1.000000 }, - { -1.000000, 0.000000, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_octa_cox[] = { - { -0.707107, 0.707107, 1.000000 }, - { 0.707107, 0.707107, -1.000000 }, - { 0.707107, -0.707107, 1.000000 }, - { -0.707107, -0.707107, -1.000000 }, - { 0.707107, 0.707107, 1.000000 }, - { -0.707107, 0.707107, -1.000000 }, - { -0.707107, -0.707107, 1.000000 }, - { 0.707107, -0.707107, -1.000000 }, -}; -const MultirotorMixer::Rotor _config_twin_engine[] = { - { -1.000000, 0.000000, 0.000000 }, - { 1.000000, 0.000000, 0.000000 }, -}; -const MultirotorMixer::Rotor *_config_index[MultirotorMixer::MAX_GEOMETRY] = { - &_config_quad_x[0], - &_config_quad_plus[0], - &_config_quad_v[0], - &_config_quad_wide[0], - &_config_hex_x[0], - &_config_hex_plus[0], - &_config_hex_cox[0], - &_config_octa_x[0], - &_config_octa_plus[0], - &_config_octa_cox[0], - &_config_twin_engine[0], -}; -const unsigned _config_rotor_count[MultirotorMixer::MAX_GEOMETRY] = { - 4, /* quad_x */ - 4, /* quad_plus */ - 4, /* quad_v */ - 4, /* quad_wide */ - 6, /* hex_x */ - 6, /* hex_plus */ - 6, /* hex_cox */ - 8, /* octa_x */ - 8, /* octa_plus */ - 8, /* octa_cox */ - 2, /* twin_engine */ -}; - } MultirotorMixer::MultirotorMixer(ControlCallback control_cb, uintptr_t cb_handle, - Geometry geometry, + MultirotorGeometry geometry, float roll_scale, float pitch_scale, float yaw_scale, @@ -200,8 +89,8 @@ MultirotorMixer::MultirotorMixer(ControlCallback control_cb, _pitch_scale(pitch_scale), _yaw_scale(yaw_scale), _idle_speed(-1.0f + idle_speed * 2.0f), /* shift to output range here to avoid runtime calculation */ - _rotor_count(_config_rotor_count[geometry]), - _rotors(_config_index[geometry]) + _rotor_count(_config_rotor_count[(MultirotorGeometryUnderlyingType)geometry]), + _rotors(_config_index[(MultirotorGeometryUnderlyingType)geometry]) { } @@ -212,7 +101,7 @@ MultirotorMixer::~MultirotorMixer() MultirotorMixer * MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen) { - MultirotorMixer::Geometry geometry; + MultirotorGeometry geometry; char geomname[8]; int s[4]; int used; @@ -252,37 +141,37 @@ MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handl debug("remaining in buf: %d, first char: %c", buflen, buf[0]); if (!strcmp(geomname, "4+")) { - geometry = MultirotorMixer::QUAD_PLUS; + geometry = MultirotorGeometry::QUAD_PLUS; } else if (!strcmp(geomname, "4x")) { - geometry = MultirotorMixer::QUAD_X; + geometry = MultirotorGeometry::QUAD_X; } else if (!strcmp(geomname, "4v")) { - geometry = MultirotorMixer::QUAD_V; + geometry = MultirotorGeometry::QUAD_V; } else if (!strcmp(geomname, "4w")) { - geometry = MultirotorMixer::QUAD_WIDE; + geometry = MultirotorGeometry::QUAD_WIDE; } else if (!strcmp(geomname, "6+")) { - geometry = MultirotorMixer::HEX_PLUS; + geometry = MultirotorGeometry::HEX_PLUS; } else if (!strcmp(geomname, "6x")) { - geometry = MultirotorMixer::HEX_X; + geometry = MultirotorGeometry::HEX_X; } else if (!strcmp(geomname, "6c")) { - geometry = MultirotorMixer::HEX_COX; + geometry = MultirotorGeometry::HEX_COX; } else if (!strcmp(geomname, "8+")) { - geometry = MultirotorMixer::OCTA_PLUS; + geometry = MultirotorGeometry::OCTA_PLUS; } else if (!strcmp(geomname, "8x")) { - geometry = MultirotorMixer::OCTA_X; + geometry = MultirotorGeometry::OCTA_X; } else if (!strcmp(geomname, "8c")) { - geometry = MultirotorMixer::OCTA_COX; + geometry = MultirotorGeometry::OCTA_COX; } else if (!strcmp(geomname, "2-")) { - geometry = MultirotorMixer::TWIN_ENGINE; + geometry = MultirotorGeometry::TWIN_ENGINE; } else { debug("unrecognised geometry '%s'", geomname); return nullptr; diff --git a/src/modules/systemlib/mixer/module.mk b/src/modules/systemlib/mixer/module.mk index fc7485e202..3fd07f5ba1 100644 --- a/src/modules/systemlib/mixer/module.mk +++ b/src/modules/systemlib/mixer/module.mk @@ -31,13 +31,17 @@ # ############################################################################ + # # mixer library # LIBNAME = mixerlib - + SRCS = mixer.cpp \ mixer_group.cpp \ mixer_multirotor.cpp \ mixer_simple.cpp \ mixer_load.c + +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(SELF_DIR)multi_tables.mk diff --git a/src/modules/systemlib/mixer/multi_tables b/src/modules/systemlib/mixer/multi_tables deleted file mode 100755 index bdb62f812d..0000000000 --- a/src/modules/systemlib/mixer/multi_tables +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/tclsh -# -# Generate multirotor mixer scale tables compatible with the ArduCopter layout -# - -proc rad {a} { expr ($a / 360.0) * 2 * acos(-1) } -proc rcos {a} { expr cos([rad $a])} - - -set quad_x { - 45 CCW - -135 CCW - -45 CW - 135 CW -} - -set quad_plus { - 90 CCW - -90 CCW - 0 CW - 180 CW -} - -set quad_v { - 18.8 0.4242 - -18.8 1.0 - -18.8 -0.4242 - 18.8 -1.0 -} - -set quad_wide { - 68 CCW - -129 CCW - -68 CW - 129 CW -} - -set hex_x { - 90 CW - -90 CCW - -30 CW - 150 CCW - 30 CCW - -150 CW -} - -set hex_plus { - 0 CW - 180 CCW - -120 CW - 60 CCW - -60 CCW - 120 CW -} - -set hex_cox { - 60 CW - 60 CCW - 180 CW - 180 CCW - -60 CW - -60 CCW -} - -set octa_x { - 22.5 CW - -157.5 CW - 67.5 CCW - 157.5 CCW - -22.5 CCW - -112.5 CCW - -67.5 CW - 112.5 CW -} - -set octa_plus { - 0 CW - 180 CW - 45 CCW - 135 CCW - -45 CCW - -135 CCW - -90 CW - 90 CW -} - -set octa_cox { - 45 CCW - -45 CW - -135 CCW - 135 CW - -45 CCW - 45 CW - 135 CCW - -135 CW -} - -set twin_engine { - 90 0.0 - -90 0.0 -} - -set tables {quad_x quad_plus quad_v quad_wide hex_x hex_plus hex_cox octa_x octa_plus octa_cox twin_engine} - -proc factors {a d} { puts [format "\t{ %9.6f, %9.6f, %9.6f }," [rcos [expr $a + 90]] [rcos $a] [expr $d]]} - -foreach table $tables { - puts [format "const MultirotorMixer::Rotor _config_%s\[\] = {" $table] - - upvar #0 $table angles - foreach {angle dir} $angles { - if {$dir == "CW"} { - set dd -1.0 - } elseif {$dir == "CCW"} { - set dd 1.0 - } else { - set dd $dir - } - factors $angle $dd - } - puts "};" -} - -puts "const MultirotorMixer::Rotor *_config_index\[MultirotorMixer::MAX_GEOMETRY\] = {" -foreach table $tables { - puts [format "\t&_config_%s\[0\]," $table] -} -puts "};" - -puts "const unsigned _config_rotor_count\[MultirotorMixer::MAX_GEOMETRY\] = {" -foreach table $tables { - upvar #0 $table angles - puts [format "\t%u, /* %s */" [expr [llength $angles] / 2] $table] -} -puts "};" diff --git a/src/modules/systemlib/mixer/multi_tables.mk b/src/modules/systemlib/mixer/multi_tables.mk new file mode 100644 index 0000000000..c537c83a47 --- /dev/null +++ b/src/modules/systemlib/mixer/multi_tables.mk @@ -0,0 +1,42 @@ +############################################################################ +# +# Copyright (c) 2014 Anton Matosov . All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + + +SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +MULTI_TABLES := $(SELF_DIR)multi_tables.py + +# Add explicit dependency, as implicit one doesn't work often. +$(SELF_DIR)mixer_multirotor.cpp : $(SELF_DIR)mixer_multirotor.generated.h + +$(SELF_DIR)mixer_multirotor.generated.h : $(MULTI_TABLES) + $(Q) $(PYTHON) $(MULTI_TABLES) > $(SELF_DIR)mixer_multirotor.generated.h diff --git a/src/modules/systemlib/mixer/multi_tables.py b/src/modules/systemlib/mixer/multi_tables.py new file mode 100755 index 0000000000..21c0affd95 --- /dev/null +++ b/src/modules/systemlib/mixer/multi_tables.py @@ -0,0 +1,200 @@ +#!/usr/bin/env python +############################################################################ +# +# Copyright (c) 2013, 2014 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# +# Generate multirotor mixer scale tables compatible with the ArduCopter layout +# + +# for python2.7 compatibility +from __future__ import print_function + +import math + +print("/*") +print("* This file is automatically generated by multi_tables - do not edit.") +print("*/") +print("") +print("#ifndef _MIXER_MULTI_TABLES") +print("#define _MIXER_MULTI_TABLES") +print("") + +def rcos(angleInRadians): + return math.cos(math.radians(angleInRadians)) + +CCW = 1.0 +CW = -CCW + +quad_x = [ + [ 45, CCW], + [-135, CCW], + [-45, CW], + [135, CW], +] + +quad_plus = [ + [ 90, CCW], + [ -90, CCW], + [ 0, CW], + [ 180, CW], +] + +quad_v = [ + [ 18.8, 0.4242], + [ -18.8, 1.0], + [ -18.8, -0.4242], + [ 18.8, -1.0], +] + +quad_wide = [ + [ 68, CCW], + [ -129, CCW], + [ -68, CW], + [ 129, CW], +] + +hex_x = [ + [ 90, CW], + [ -90, CCW], + [ -30, CW], + [ 150, CCW], + [ 30, CCW], + [-150, CW], +] + +hex_plus = [ + [ 0, CW], + [ 180, CCW], + [-120, CW], + [ 60, CCW], + [ -60, CCW], + [ 120, CW], +] + +hex_cox = [ + [ 60, CW], + [ 60, CCW], + [ 180, CW], + [ 180, CCW], + [ -60, CW], + [ -60, CCW], +] + +octa_x = [ + [ 22.5, CW], + [-157.5, CW], + [ 67.5, CCW], + [ 157.5, CCW], + [ -22.5, CCW], + [-112.5, CCW], + [ -67.5, CW], + [ 112.5, CW], +] + +octa_plus = [ + [ 0, CW], + [ 180, CW], + [ 45, CCW], + [ 135, CCW], + [ -45, CCW], + [-135, CCW], + [ -90, CW], + [ 90, CW], +] + +octa_cox = [ + [ 45, CCW], + [ -45, CW], + [-135, CCW], + [ 135, CW], + [ -45, CCW], + [ 45, CW], + [ 135, CCW], + [-135, CW], +] + +twin_engine = [ + [ 90, 0.0], + [-90, 0.0], +] + +def variableName(variable): + for variableName, value in list(globals().items()): + if value is variable: + return variableName + +tables = [quad_x, quad_plus, quad_v, quad_wide, hex_x, hex_plus, hex_cox, octa_x, octa_plus, octa_cox, twin_engine] + + +def printEnum(): + print("enum class MultirotorGeometry : MultirotorGeometryUnderlyingType {") + for table in tables: + print("\t{},".format(variableName(table).upper())) + + print("\n\tMAX_GEOMETRY") + print("}; // enum class MultirotorGeometry\n") + +def printScaleTables(): + for table in tables: + print("const MultirotorMixer::Rotor _config_{}[] = {{".format(variableName(table))) + for (angle, yawScale) in table: + rollScale = rcos(angle + 90) + pitchScale = rcos(angle) + print("\t{{ {:9f}, {:9f}, {:9f} }},".format(rollScale, pitchScale, yawScale)) + print("};\n") + +def printScaleTablesIndex(): + print("const MultirotorMixer::Rotor *_config_index[] = {") + for table in tables: + print("\t&_config_{}[0],".format(variableName(table))) + print("};\n") + + +def printScaleTablesCounts(): + print("const unsigned _config_rotor_count[] = {") + for table in tables: + print("\t{}, /* {} */".format(len(table), variableName(table))) + print("};\n") + + + +printEnum() + +print("namespace {") +printScaleTables() +printScaleTablesIndex() +printScaleTablesCounts() + +print("} // anonymous namespace\n") +print("#endif /* _MIXER_MULTI_TABLES */") +print("") diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 02e2a4d902..05d5fb214e 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -2,6 +2,17 @@ cmake_minimum_required(VERSION 2.8) project(unittests) enable_testing() +include(CheckCXXCompilerFlag) +CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) +CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) +if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +elseif(COMPILER_SUPPORTS_CXX0X) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") +else() + message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") +endif() + set(GTEST_DIR gtest) add_subdirectory(${GTEST_DIR}) include_directories(${GTEST_DIR}/include) @@ -11,8 +22,6 @@ include_directories(${CMAKE_SOURCE_DIR}/../src/modules) include_directories(${CMAKE_SOURCE_DIR}/../src/lib) add_definitions(-D__EXPORT=) -set(CMAKE_C_FLAGS "-std=c99") -set(CMAKE_CXX_FLAGS "-std=c++11 -Wno-write-strings") # check add_custom_target(unittests COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)