Skip to content

Commit

Permalink
Refs #14: Export symbols
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Ponz Segrelles <[email protected]>
  • Loading branch information
EduPonz committed Oct 13, 2021
1 parent c55c2c1 commit ed102d3
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 16 deletions.
2 changes: 2 additions & 0 deletions cmake/modules/FindAsio.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ if(Asio_INCLUDE_DIR AND (NOT Asio_FOUND_PACKAGE))
find_package_handle_standard_args(Asio DEFAULT_MSG Asio_INCLUDE_DIR)
mark_as_advanced(Asio_INCLUDE_DIR)
message(STATUS "Found Asio ${ASIO_VERSION}: ${Asio_INCLUDE_DIR}")
elseif(Asio_FOUND_PACKAGE)
message(STATUS "Found Aio ${ASIO_VERSION}: ${Asio_INCLUDE_DIR}")
else()
message(STATUS "Cannot find package Asio")
endif()
4 changes: 3 additions & 1 deletion docs/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ EXPAND_ONLY_PREDEF = YES
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED = "DOXYGEN_DOCUMENTATION=1"
PREDEFINED = "DOXYGEN_DOCUMENTATION=1" \
EASYNMEA_PUBLIC= \
EASYNMEA_PUBLIC_TYPE=
EXPAND_AS_DEFINED = YES
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
Expand Down
16 changes: 9 additions & 7 deletions include/easynmea/Bitmask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include <type_traits>

#include "visibility.hpp"

namespace eduponz {
namespace easynmea {

Expand Down Expand Up @@ -67,7 +69,7 @@ namespace easynmea {
* @tparam E The enumerated type for which the bitmask is constructed
*/
template <typename E>
class Bitmask
class EASYNMEA_PUBLIC_TYPE Bitmask
{

private:
Expand All @@ -77,7 +79,7 @@ class Bitmask
public:

Bitmask()
: mask_(0)
: mask_(static_cast<underlying_type>(0))
{
}

Expand Down Expand Up @@ -114,7 +116,7 @@ class Bitmask

static constexpr Bitmask none()
{
return Bitmask(0);
return Bitmask(static_cast<underlying_type>(0));
}

static constexpr Bitmask all()
Expand All @@ -124,7 +126,7 @@ class Bitmask

bool is_none() const
{
return (mask_ == 0);
return (mask_ == static_cast<underlying_type>(0));
}

Bitmask<E>& operator &= (
Expand Down Expand Up @@ -222,7 +224,7 @@ class Bitmask
};

template<typename E>
Bitmask<E> operator & (
Bitmask<E> EASYNMEA_PUBLIC operator & (
const E& lhs,
const E& rhs)
{
Expand All @@ -231,7 +233,7 @@ Bitmask<E> operator & (
}

template<typename E>
Bitmask<E> operator | (
Bitmask<E> EASYNMEA_PUBLIC operator | (
const E& lhs,
const E& rhs)
{
Expand All @@ -240,7 +242,7 @@ Bitmask<E> operator | (
}

template<typename E>
Bitmask<E> operator ^ (
Bitmask<E> EASYNMEA_PUBLIC operator ^ (
const E& lhs,
const E& rhs)
{
Expand Down
3 changes: 2 additions & 1 deletion include/easynmea/EasyNmea.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "Bitmask.hpp"
#include "data.hpp"
#include "types.hpp"
#include "visibility.hpp"

namespace eduponz {
namespace easynmea {
Expand All @@ -48,7 +49,7 @@ class EasyNmeaImpl;
* * Wait for specific NMEA sentences to be received.
* * Read incoming NMEA data in a parsed and understandable manner.
*/
class EasyNmea
class EASYNMEA_PUBLIC_TYPE EasyNmea
{
public:

Expand Down
5 changes: 3 additions & 2 deletions include/easynmea/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <string>

#include "types.hpp"
#include "visibility.hpp"

namespace eduponz {
namespace easynmea {
Expand All @@ -38,7 +39,7 @@ namespace easynmea {
*
* @brief Base struct for all NMEA 0183 Data types
*/
struct NMEA0183Data
struct EASYNMEA_PUBLIC_TYPE NMEA0183Data
{
/**
* Default constructor; it empty-initializes the struct
Expand Down Expand Up @@ -95,7 +96,7 @@ struct NMEA0183Data
*
* @brief Struct for data from GPGGA sentences
*/
struct GPGGAData : NMEA0183Data
struct EASYNMEA_PUBLIC_TYPE GPGGAData : NMEA0183Data
{
/**
* Default constructor; it empty-initializes the struct, setting \c kind to
Expand Down
5 changes: 3 additions & 2 deletions include/easynmea/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define _EASYNMEA_TYPES_HPP_

#include "Bitmask.hpp"
#include "visibility.hpp"

namespace eduponz {
namespace easynmea {
Expand All @@ -35,7 +36,7 @@ namespace easynmea {
*
* @brief Holds all the supported NMEA 0183 sentences.
*/
enum class NMEA0183DataKind : int32_t
enum class EASYNMEA_PUBLIC_TYPE NMEA0183DataKind : int32_t
{
//! Represents no valid data kind
INVALID = 0,
Expand Down Expand Up @@ -65,7 +66,7 @@ using NMEA0183DataKindMask = Bitmask<NMEA0183DataKind>;
*
* These return codes can be easily compared for applications to handle different scenarios.
*/
class ReturnCode
class EASYNMEA_PUBLIC_TYPE ReturnCode
{
public:

Expand Down
59 changes: 59 additions & 0 deletions include/easynmea/visibility.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2021 Eduardo Ponz Segrelles.
//
// 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.

/**
* @file visibility.hpp
*/

#ifndef _EASYNMEA_VISIBILITY_HPP_
#define _EASYNMEA_VISIBILITY_HPP_

/*
* This logic was borrowed from the examples on the gcc wiki: https://gcc.gnu.org/wiki/Visibility
*/
#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define EASYNMEA_EXPORT __attribute__ ((dllexport))
#define EASYNMEA_IMPORT __attribute__ ((dllimport))
#else
#define EASYNMEA_EXPORT __declspec(dllexport)
#define EASYNMEA_IMPORT __declspec(dllimport)
#endif
#ifdef EASYNMEA_BUILDING_LIBRARY
#define EASYNMEA_PUBLIC EASYNMEA_EXPORT
#else
#define EASYNMEA_PUBLIC EASYNMEA_IMPORT
#endif
#define EASYNMEA_PUBLIC_TYPE EASYNMEA_PUBLIC
#define EASYNMEA_LOCAL
#else
#define EASYNMEA_EXPORT __attribute__ ((visibility("default")))
#define EASYNMEA_IMPORT
#if __GNUC__ >= 4
#define EASYNMEA_PUBLIC __attribute__ ((visibility("default")))
#define EASYNMEA_LOCAL __attribute__ ((visibility("hidden")))
#else
#define EASYNMEA_PUBLIC
#define EASYNMEA_LOCAL
#endif
#define EASYNMEA_PUBLIC_TYPE
#endif

#endif // _EASYNMEA_VISIBILITY_HPP_
21 changes: 19 additions & 2 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# Include WiringPi headers
include_directories(${WIRINGPI_INCLUDE_DIRS})
# Include Asio headers
include_directories(${Asio_INCLUDE_DIRS})

# Project sources
set(${PROJECT_NAME}_SOURCES
Expand All @@ -31,6 +31,10 @@ add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR})

target_compile_definitions(${PROJECT_NAME} PRIVATE
BOOST_ASIO_STANDALONE
ASIO_STANDALONE)

# Define public headers
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
Expand All @@ -42,6 +46,19 @@ target_include_directories(${PROJECT_NAME} PUBLIC
target_link_libraries(${PROJECT_NAME}
Threads::Threads)

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "EASYNMEA_BUILDING_LIBRARY")

if(MSVC)
target_compile_definitions(${PROJECT_NAME}
INTERFACE
_CRT_DECLARE_NONSTDC_NAMES=0
PRIVATE
_WIN32_WINNT=0X0603
_CRT_DECLARE_NONSTDC_NAMES=0)
endif()

###############################################################################
# Installation
###############################################################################
Expand Down
9 changes: 8 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@
# THE SOFTWARE.

add_subdirectory(unit)
add_subdirectory(system)

# For now, only add System Tests in Linux. This is because they currently rely on socat.
# TODO: Evaluate Windows alternatives to socat (Virtual Serial Port Driver, Null-modem emulator,
# etc).
if(UNIX AND NOT APPLE)
add_subdirectory(system)
endif()

6 changes: 6 additions & 0 deletions test/system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

find_package(PythonInterp 3 REQUIRED)

find_program(SOCAT socat REQUIRED)
if(${SOCAT} STREQUAL "SOCAT-NOTFOUND")
message(FATAL_ERROR "socat not found")
endif()
message(STATUS "Found socat: ${SOCAT}")

add_executable(system_tests system_tests.cpp)
target_link_libraries(system_tests easynmea)

Expand Down

0 comments on commit ed102d3

Please sign in to comment.