From 9701a2d39321daf082ceee8abd4bcd5f3b5040d3 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Thu, 6 Jun 2013 17:07:22 -0400 Subject: [PATCH] [Positioner] Allow building with clang++ This patch is to have clang++ (>= 3.2) happily build OwlPS Positioner. For some reason it doesn't work on NetBSD, but it is fine on GNU/Linux and (a couple of warnings apart) on DragonFly BSD. --- CMakeLists.txt | 40 ++++++++++++++-------- INSTALL.t2t | 3 +- owlps-positioner/src/calibrationrequest.cc | 2 +- owlps-positioner/src/calibrationrequest.hh | 2 +- owlps-positioner/src/request.hh | 17 ++++++--- owlps-positioner/src/wifidevice.hh | 16 ++++----- 6 files changed, 51 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32b9e7e..a436510 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,26 +177,38 @@ endif() ## Positioner ## -# OwlPS Positioner can be built only with GCC, and with a minimal -# version. CMAKE_CXX_COMPILER_VERSION is not guaranteed to be set, -# so we will test GCC's version number only if possible. +# OwlPS Positioner can be built only with a minimal version of GCC, or +# Clang++. CMAKE_CXX_COMPILER_VERSION is not guaranteed to be set, so we +# will test the version number only if possible. set(POSITIONER_MIN_GCC_VERSION 4.7) -if (CMAKE_COMPILER_IS_GNUCXX) +set(POSITIONER_MIN_CLANG_VERSION 3.2) + +if (CMAKE_CXX_COMPILER_ID STREQUAL GNU) # Are we using GCC? # Test the compiler version if we can - if (${CMAKE_CXX_COMPILER_VERSION}) - if (${CMAKE_CXX_COMPILER_VERSION} VERSION_EQUAL ${POSITIONER_MIN_GCC_VERSION} OR - ${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER ${POSITIONER_MIN_GCC_VERSION}) - add_subdirectory(owlps-positioner) - else() # GCC's version is too low - message(WARNING - "OwlPS Positioner requires GCC >= ${POSITIONER_MIN_GCC_VERSION}") - endif() - else() # we couldn't get GCC's version, let's try to build anyway + if (${CMAKE_CXX_COMPILER_VERSION} AND + ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS ${POSITIONER_MIN_GCC_VERSION}) + # GCC's version is too low + message(WARNING + "OwlPS Positioner requires GCC >= ${POSITIONER_MIN_GCC_VERSION}") + else() + # GCC's version is OK or we couldn'd get it add_subdirectory(owlps-positioner) endif() + +elseif (CMAKE_CXX_COMPILER_ID STREQUAL Clang) # Are we using Clang? + if (${CMAKE_CXX_COMPILER_VERSION} AND + ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS ${POSITIONER_MIN_CLANG_VERSION}) + # Clang's version is too low + message(WARNING + "OwlPS Positioner requires GCC >= ${POSITIONER_MIN_GCC_VERSION}") + else() + # Clang's version is OK or we couldn'd get it + add_subdirectory(owlps-positioner) + endif() + else() # we're not using GCC message(WARNING - "OwlPS Positioner requires GCC (>= ${POSITIONER_MIN_GCC_VERSION})") + "OwlPS Positioner requires GCC (>= ${POSITIONER_MIN_GCC_VERSION}) or Clang (>= ${POSITIONER_MIN_CLANG_VERSION})") endif() ## UDP-to-HTTP ## diff --git a/INSTALL.t2t b/INSTALL.t2t index 40cd21a..e797851 100644 --- a/INSTALL.t2t +++ b/INSTALL.t2t @@ -17,7 +17,8 @@ systems” below) with the following development libraries installed: You also need support for POSIX threads, which should be provided by default by your system in most cases, and the GCC C++ compiler (g++) -version 4.7 or above. +version 4.7 or above; the Clang C++ compiler (clang++) version 3.2 or +above should also work in most cases. If you miss one or more of the requirements, the concerned modules will not be built, but the others can still be. diff --git a/owlps-positioner/src/calibrationrequest.cc b/owlps-positioner/src/calibrationrequest.cc index 1b2a5d5..894f058 100644 --- a/owlps-positioner/src/calibrationrequest.cc +++ b/owlps-positioner/src/calibrationrequest.cc @@ -20,7 +20,7 @@ CalibrationRequest:: -CalibrationRequest(uint_fast8_t _type = OWL_REQUEST_AUTOCALIBRATION): +CalibrationRequest(uint_fast8_t _type): reference_point(NULL), direction(Direction()) { type = _type ; diff --git a/owlps-positioner/src/calibrationrequest.hh b/owlps-positioner/src/calibrationrequest.hh index 6a1ef53..b62c4ab 100644 --- a/owlps-positioner/src/calibrationrequest.hh +++ b/owlps-positioner/src/calibrationrequest.hh @@ -30,7 +30,7 @@ protected: Direction direction ; public: - CalibrationRequest(uint_fast8_t _type) ; + CalibrationRequest(uint_fast8_t _type = OWL_REQUEST_AUTOCALIBRATION) ; CalibrationRequest(const CalibrationRequest &source): Request(source), reference_point(source.reference_point), diff --git a/owlps-positioner/src/request.hh b/owlps-positioner/src/request.hh index 08a73ba..beaa97f 100644 --- a/owlps-positioner/src/request.hh +++ b/owlps-positioner/src/request.hh @@ -54,20 +54,29 @@ protected: void clear_real_position(void) ; //@} + /// Measurements' list type + /** + * This really is just an alias to work-around clang++ that doesn't + * handle the following syntax: + * + * Request(..., const std::unordered_map + * &_measurements = std::unordered_map()) ; + */ + typedef std::unordered_map measurements_list ; + public: Request(const Mobile *_mobile = NULL, const Timestamp &_time_sent = Timestamp(), const std::unordered_map - &_measurements = - std::unordered_map()) ; + &_measurements = measurements_list()) ; Request(const std::unordered_map &_measurements) ; Request(const Timestamp &_time_sent, const std::unordered_map - &_measurements = - std::unordered_map()) ; + &_measurements = measurements_list()) ; Request(const Request &source) ; diff --git a/owlps-positioner/src/wifidevice.hh b/owlps-positioner/src/wifidevice.hh index ed8818f..b362a5b 100644 --- a/owlps-positioner/src/wifidevice.hh +++ b/owlps-positioner/src/wifidevice.hh @@ -37,10 +37,10 @@ protected: float trx_power ; ///< Transmit power in dBm public: - WifiDevice(const std::string &_ip_addr, - const std::string &_mac_addr, - const float _antenna_gain, - const float _trx_power) ; + WifiDevice(const std::string &_ip_addr = "", + const std::string &_mac_addr = "", + const float _antenna_gain = WIFIDEVICE_DEFAULT_ANTENNA_GAIN, + const float _trx_power = WIFIDEVICE_DEFAULT_TRX_POWER) ; WifiDevice(const WifiDevice &source): ip_addr(source.ip_addr), mac_addr(source.mac_addr), @@ -81,10 +81,10 @@ public: inline WifiDevice:: -WifiDevice(const std::string &_ip_addr = "", - const std::string &_mac_addr = "", - const float _antenna_gain = WIFIDEVICE_DEFAULT_ANTENNA_GAIN, - const float _trx_power = WIFIDEVICE_DEFAULT_TRX_POWER): +WifiDevice(const std::string &_ip_addr, + const std::string &_mac_addr, + const float _antenna_gain, + const float _trx_power): ip_addr(_ip_addr), mac_addr(_mac_addr), antenna_gain(_antenna_gain), trx_power(_trx_power) {