cmake: Dependency refactoring for includes and libs

This commit attempts to use a more cmake-friendly approach when
handling inter-target dependencies.  A combination of macros and
include_directories usage provided overzealous compile -I/blah
entries which equates to large catch-all build commands.  For
example, the last CXX target contains include directories for nearly
all preceeding targets (~190).  Library dependencies were also often
wrong or missing.

    * Removed nearly all used of include_directories (swig cmake
      commands still appear to need these for generating the swig
      command line)
    * Updated usage of target_link_libraries in upm_module_init,
      also changed to using target_include_directories per target.
      This greatly simplifies upm/mixed_module_init usage for libraries
      which depend on other libraries (in this project).

        example (src/tb7300/CMakeLists.txt)
            old:
                 # upm-libbacnetmstp will bring in libbacnet, I hope
                 set (reqlibname "upm-bacnetmstp")
                 include_directories(${BACNET_INCLUDE_DIRS})
                 include_directories("../bacnetmstp")
                 upm_module_init()
                 upm_target_link_libraries(${libname} bacnetmstp)
            new:
                 upm_module_init(bacnetmstp)

      The reason here, is that tb7300 depends on bacnetmstp, which
      depends on BACNET includes/libs, so tb7300 gets the headers and
      libraries transitively via its dependency on bacnetmstp.
    * Updated pkg-config .pc file generation flow to reflect changes
      with dependencies.
    * Create a real target for the interfaces (CXX abstract sensor
      classes).  Renamed the directory from 'upm/src/upm' to
      'upm/src/interfaces'  Also changed the install location of the
      interface headers to include/upm/interfaces.  Updated interface
      header usage to reflect this.
    * Updated a few sensor libs to use fwd declarations for mraa.
      Ideally the UPM libs would do more of this which eases the
      burden on anyone building on top of the sensor libraries since
      they would not need to know about mraa headers.
    * Fixed examples which use symbols not defined in local includes

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2017-01-30 18:14:48 -08:00
parent 7f0e03b0e3
commit d345006c03
97 changed files with 326 additions and 202 deletions

View File

@ -0,0 +1,18 @@
set (libname "interfaces")
set (libdescription "CXX interface library")
set (module_src ${libname}.cxx)
upm_module_init()
# Don't add the hpp files with upm_module_init, this allows
# them to be installed separately
set (module_hpp iADC.hpp
iCO2Sensor.hpp
iHumiditySensor.hpp
iLightController.hpp
iLightSensor.hpp
iModuleStatus.hpp
iPressureSensor.hpp
iTemperatureSensor.hpp)
# Install interfaces headers a bit differently
install (FILES ${module_hpp} DESTINATION include/upm/${libname} COMPONENT ${libname})

49
src/interfaces/iADC.hpp Normal file
View File

@ -0,0 +1,49 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <stdint.h>
#include "mraa/common.h"
#include "iModuleStatus.hpp"
namespace upm
{
/**
* @brief Interface for ADC Sensors
*/
class IADC : public IModuleStatus
{
public:
virtual unsigned int getResolutionInBits() = 0;
virtual unsigned int getNumInputs() = 0;
virtual uint16_t getRawValue(unsigned int input) = 0;
virtual float getVoltage(unsigned int input) = 0;
virtual ~IADC() {}
};
}

View File

@ -0,0 +1,44 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "iModuleStatus.hpp"
namespace upm
{
/**
* @brief Interface for CO Sensor
*/
class ICO2Sensor : public IModuleStatus
{
public:
virtual uint16_t getPpm() = 0;
virtual ~ICO2Sensor() {}
};
}

View File

@ -0,0 +1,42 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "iModuleStatus.hpp"
namespace upm
{
/**
* @brief Interface for Humidity Sensors
*/
class IHumiditySensor : public IModuleStatus
{
public:
virtual int getHumidityRelative () = 0;
virtual ~IHumiditySensor() {}
};
}

View File

@ -0,0 +1,94 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "iModuleStatus.hpp"
namespace upm
{
/**
* @brief ILightController Interface for Light Controllers
*/
/**
*
* @brief Interface for Light Controllers
* This interface is used to represent light controllers
* @snippet light-controllers.cxx Interesting
*/
class ILightController : public IModuleStatus
{
public:
/**
* Turn on power
*
* @throws std::runtime_error
*/
virtual void setPowerOn() = 0;
/**
* Turn off power
*
* @throws std::runtime_error
*/
virtual void setPowerOff() = 0;
/**
* Get power state
*
* @return true if powered, false otherwise
*
* @throws std::runtime_error
*/
virtual bool isPowered() = 0;
/**
* Set brightness
*
* @param brightness as percentage
*
* @throws std::runtime_error
*/
virtual void setBrightness(int percent) = 0;
/**
* Get brightness
*
* @return brightness as percentage
*
* @throws std::runtime_error
*/
virtual int getBrightness() = 0;
virtual ~ILightController() {}
};
}

View File

@ -0,0 +1,61 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <stdint.h>
#include "iModuleStatus.hpp"
namespace upm
{
/**
* @brief ILightSensor Interface for Light Sensors
*/
/**
*
* @brief Interface for Light Sensors
* This interface is used to represent light sensors
* @snippet light-sensor.cxx Interesting
*/
class ILightSensor : public IModuleStatus
{
public:
/**
* Get visible illuminance in Lux.
*
* @return double visible illuminance in Lux
*/
virtual double getVisibleLux() = 0;
virtual ~ILightSensor() {}
};
}

View File

@ -0,0 +1,53 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <stdexcept>
namespace upm
{
/**
* @brief Interface for Module Status. Sensor and Actuactor Interfaces Derive from this Interface.
*/
#define UPM_THROW(msg) throw std::runtime_error(std::string(__FUNCTION__) + ": " + (msg))
class IModuleStatus
{
public:
/**
* Returns name of module. This is the string in library name after libupm_
* @return name of module
*/
virtual const char* getModuleName() = 0;
virtual ~IModuleStatus() {}
};
}

View File

@ -0,0 +1,46 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <stdint.h>
#include "mraa/common.h"
#include "iModuleStatus.hpp"
namespace upm
{
/**
* @brief Interface for Pressue Sensors
*/
class IPressureSensor : public IModuleStatus
{
public:
virtual int getPressurePa() = 0;
virtual ~IPressureSensor() {}
};
}

View File

@ -0,0 +1,42 @@
/*
* Author: Henry Bruce <henry.bruce@intel.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include "iModuleStatus.hpp"
namespace upm
{
/**
* @brief Interface for Temperature Sensors
*/
class ITemperatureSensor : public IModuleStatus
{
public:
virtual int getTemperatureCelsius () = 0;
virtual ~ITemperatureSensor() {}
};
}

View File

@ -0,0 +1 @@
#include "iLightSensor.hpp"

View File

@ -0,0 +1,27 @@
%module(directors="1") javaupm_interfaces
%feature("director") IModuleStatus;
%feature("director") ILightSensor;
%feature("director") ILightController;
%{
#include "iModuleStatus.hpp"
#include "iLightSensor.hpp"
#include "iLightController.hpp"
%}
%include "iModuleStatus.hpp"
%include "iLightSensor.hpp"
%include "iLightController.hpp"
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("javaupm_interfaces");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
}
%}

View File

@ -0,0 +1,26 @@
%module(directors="1") javaupm_light_sensor
%{
#include "iLightSensor.hpp"
%}
/*
%include "../iModuleStatus.hpp"
*/
%include "iLightSensor.hpp"
%feature("director") IModuleStatus;
%feature("director") ILightSensor;
%include "iLightSensor.hpp"
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("javaupm_light_sensor");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
}
}
%}

View File

@ -0,0 +1,11 @@
%module jsupm_interfaces
%include "../upm.i"
%{
#include "iLightSensor.hpp"
#include "iLightController.hpp"
%}
%include "iModuleStatus.hpp"
%include "iLightSensor.hpp"
%include "iLightController.hpp"

View File

@ -0,0 +1,15 @@
%module pyupm_interfaces
%include "../upm.i"
// Include doxygen-generated documentation
%include "pyupm_doxy2swig.i"
%feature("autodoc", "3");
%{
#include "iLightSensor.hpp"
#include "iLightController.hpp"
%}
%include "iModuleStatus.hpp"
%include "iLightSensor.hpp"
%include "iLightController.hpp"