From ed102d35f9831b6dde8e3c713bbc24a96d7fa28f Mon Sep 17 00:00:00 2001 From: Eduardo Ponz Segrelles Date: Wed, 6 Oct 2021 20:35:14 +0200 Subject: [PATCH] Refs #14: Export symbols Signed-off-by: Eduardo Ponz Segrelles --- cmake/modules/FindAsio.cmake | 2 ++ docs/Doxyfile.in | 4 ++- include/easynmea/Bitmask.hpp | 16 +++++---- include/easynmea/EasyNmea.hpp | 3 +- include/easynmea/data.hpp | 5 +-- include/easynmea/types.hpp | 5 +-- include/easynmea/visibility.hpp | 59 +++++++++++++++++++++++++++++++++ src/cpp/CMakeLists.txt | 21 ++++++++++-- test/CMakeLists.txt | 9 ++++- test/system/CMakeLists.txt | 6 ++++ 10 files changed, 114 insertions(+), 16 deletions(-) create mode 100644 include/easynmea/visibility.hpp diff --git a/cmake/modules/FindAsio.cmake b/cmake/modules/FindAsio.cmake index 2768bcb..07080fa 100644 --- a/cmake/modules/FindAsio.cmake +++ b/cmake/modules/FindAsio.cmake @@ -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() diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index 9154533..c18d7bf 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -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 #--------------------------------------------------------------------------- diff --git a/include/easynmea/Bitmask.hpp b/include/easynmea/Bitmask.hpp index 63cdde4..018718e 100644 --- a/include/easynmea/Bitmask.hpp +++ b/include/easynmea/Bitmask.hpp @@ -27,6 +27,8 @@ #include +#include "visibility.hpp" + namespace eduponz { namespace easynmea { @@ -67,7 +69,7 @@ namespace easynmea { * @tparam E The enumerated type for which the bitmask is constructed */ template -class Bitmask +class EASYNMEA_PUBLIC_TYPE Bitmask { private: @@ -77,7 +79,7 @@ class Bitmask public: Bitmask() - : mask_(0) + : mask_(static_cast(0)) { } @@ -114,7 +116,7 @@ class Bitmask static constexpr Bitmask none() { - return Bitmask(0); + return Bitmask(static_cast(0)); } static constexpr Bitmask all() @@ -124,7 +126,7 @@ class Bitmask bool is_none() const { - return (mask_ == 0); + return (mask_ == static_cast(0)); } Bitmask& operator &= ( @@ -222,7 +224,7 @@ class Bitmask }; template -Bitmask operator & ( +Bitmask EASYNMEA_PUBLIC operator & ( const E& lhs, const E& rhs) { @@ -231,7 +233,7 @@ Bitmask operator & ( } template -Bitmask operator | ( +Bitmask EASYNMEA_PUBLIC operator | ( const E& lhs, const E& rhs) { @@ -240,7 +242,7 @@ Bitmask operator | ( } template -Bitmask operator ^ ( +Bitmask EASYNMEA_PUBLIC operator ^ ( const E& lhs, const E& rhs) { diff --git a/include/easynmea/EasyNmea.hpp b/include/easynmea/EasyNmea.hpp index 796738d..accd495 100644 --- a/include/easynmea/EasyNmea.hpp +++ b/include/easynmea/EasyNmea.hpp @@ -31,6 +31,7 @@ #include "Bitmask.hpp" #include "data.hpp" #include "types.hpp" +#include "visibility.hpp" namespace eduponz { namespace easynmea { @@ -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: diff --git a/include/easynmea/data.hpp b/include/easynmea/data.hpp index 1d4ea75..964fe1f 100644 --- a/include/easynmea/data.hpp +++ b/include/easynmea/data.hpp @@ -28,6 +28,7 @@ #include #include "types.hpp" +#include "visibility.hpp" namespace eduponz { namespace easynmea { @@ -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 @@ -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 diff --git a/include/easynmea/types.hpp b/include/easynmea/types.hpp index 7df8215..b56b980 100644 --- a/include/easynmea/types.hpp +++ b/include/easynmea/types.hpp @@ -26,6 +26,7 @@ #define _EASYNMEA_TYPES_HPP_ #include "Bitmask.hpp" +#include "visibility.hpp" namespace eduponz { namespace easynmea { @@ -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, @@ -65,7 +66,7 @@ using NMEA0183DataKindMask = Bitmask; * * These return codes can be easily compared for applications to handle different scenarios. */ -class ReturnCode +class EASYNMEA_PUBLIC_TYPE ReturnCode { public: diff --git a/include/easynmea/visibility.hpp b/include/easynmea/visibility.hpp new file mode 100644 index 0000000..b55a224 --- /dev/null +++ b/include/easynmea/visibility.hpp @@ -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_ diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 5086217..71c29ae 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -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 @@ -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 $ @@ -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 ############################################################################### diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7557b2e..f9a72a9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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() + diff --git a/test/system/CMakeLists.txt b/test/system/CMakeLists.txt index 8fdd293..72d729f 100644 --- a/test/system/CMakeLists.txt +++ b/test/system/CMakeLists.txt @@ -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)