Skip to content

Windows compatability #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 29 additions & 119 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project(ISO_object LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.14)
project(ISO_object LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -8,7 +8,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# RPATH/RUNPATH tells a binary where to look for libraries at runtime
# It is useful e.g. when multiple copies of the same shared library exist in various paths (such as LD_LIBRARY_PATH, /usr/local/lib, etc..).
# However, RPATH has higher priority than LD_LIBRARY_PATH, while RUNPATH has lower priority
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--disable-new-dtags")
#set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--disable-new-dtags") #throws error?


# Build flags
Expand Down Expand Up @@ -45,41 +45,50 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

include(GNUInstallDirs)

if (BUILDING_FOR_ANDROID) # Boost is found in variables set by android toolchain upstream
add_library(boost_system SHARED IMPORTED)
set_target_properties(boost_system PROPERTIES IMPORTED_LOCATION
${ANDROID_BOOST_LIB_DIR}/libboost_system.so)

include_directories(${ANDROID_BOOST_INCLUDE_DIR})
else() # Find boost normally
find_package(Boost REQUIRED COMPONENTS system)


find_package(Boost 1.83.0 REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
if(Boost_FOUND)
set(BOOST_INCLUDE_DIR "${Boost_ROOT}")
set(Boost_DEBUG ON)
set(Boost_USE_STATIC_LIBS OFF) #Set to on
message(STATUS "Boost found: ${Boost_VERSION}")
message(STATUS "Boost include dirs: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost libraries: ${Boost_LIBRARIES}")
else()
message(FATAL_ERROR "Boost not found")
endif()
# add_definitions(-DBOOST_ALL_NO_LIB)
# add_subdirectory(${Boost_INSTALL_DIR}/boost)
set(Boost_USE_STATIC_ ON)


# Library target
add_library(${ISOOBJECT_LIBRARY} SHARED
${CMAKE_CURRENT_SOURCE_DIR}/src/iso22133object.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/iso22133state.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/trajDecoder.cpp
)
target_compile_definitions(${ISOOBJECT_LIBRARY} PRIVATE ISO_OBJECT_EXPORTS)

target_include_directories(${ISOOBJECT_LIBRARY} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/inc
${CMAKE_CURRENT_SOURCE_DIR}/sigslot/include/sigslot
${CMAKE_CURRENT_SOURCE_DIR}/iso22133
${Boost_INCLUDE_DIRS}
)
set(ISO_OBJ_LIBS
${ISO22133_LIBRARY} atomic pthread Boost::system)
set(ISO_OBJ_LIBS_ANDROID
${ISO22133_LIBRARY} atomic ${boost_system})
if (BUILDING_FOR_ANDROID)
target_link_libraries(${ISOOBJECT_LIBRARY}
${ISO_OBJ_LIBS_ANDROID}
)
else()
target_link_libraries(${ISOOBJECT_LIBRARY}
${ISO_OBJ_LIBS}
${ISO22133_LIBRARY})# Boost::system)

target_link_libraries(${ISOOBJECT_LIBRARY}
${ISO_OBJ_LIBS}
${Boost_LIBRARIES}
)
endif()


set(CMAKE_VERBOSE_MAKEFILE ON)

set_property(TARGET ${ISOOBJECT_LIBRARY} PROPERTY
PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/inc/iso22133object.hpp
Expand Down Expand Up @@ -109,109 +118,10 @@ set_property(TARGET ${ISOOBJECT_LIBRARY} APPEND PROPERTY
PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/inc/udpServer.hpp
)

if (NOT WITH_SWIG AND NOT BUILDING_FOR_ANDROID)
find_package(Boost REQUIRED COMPONENTS program_options)

# Demo target, only build if not swigging
add_executable(${ISOOBJECT_TEST} demoIsoObject.cpp)

target_include_directories(${ISOOBJECT_TEST} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/inc
)

target_link_libraries(${ISOOBJECT_TEST} LINK_PUBLIC
${ISOOBJECT_LIBRARY}
Boost::program_options
)

endif()

install(CODE "MESSAGE(STATUS \"Installing target ${ISOOBJECT_LIBRARY}\")")
install(TARGETS ${ISOOBJECT_LIBRARY}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

# SWIG
if (WITH_SWIG)
find_package(SWIG REQUIRED)
if(NOT SWIG_FOUND)
message(WARNING "SWIG not found")
else()
#Policy for swig_add_library to put target inside first argument to the function
cmake_policy(SET CMP0078 NEW)
#Policy for passing SWIG_MODULE_NAME to swig compiler as -module <name>
cmake_policy(SET CMP0086 NEW)

include(${SWIG_USE_FILE})

if(SWIG_WITH_JAVA)
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Android")
find_package(JNI REQUIRED)
endif()
SET(CMAKE_SWIG_FLAGS -package org.asta.isoObject)
elseif(SWIG_WITH_PYTHON)
find_package(Python COMPONENTS Development)
SET(CMAKE_SWIG_FLAGS "-threads")
endif()

set(ISO22133_SWIGGED isoObject_wrap)

set_property(SOURCE isoObject.i PROPERTY CPLUSPLUS ON)
set_property(SOURCE isoObject.i PROPERTY INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/inc
${CMAKE_CURRENT_SOURCE_DIR}/sigslot/include/sigslot
${CMAKE_CURRENT_SOURCE_DIR}/iso22133
${Python_INCLUDE_DIRS} #Note that cmake ignored empty variables
${JNI_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
swig_add_library(${ISO22133_SWIGGED}
TYPE SHARED
LANGUAGE ${SWIG_TARGET_LANG}
SOURCES isoObject.i
)
set_property(TARGET ${ISO22133_SWIGGED} PROPERTY USE_TARGET_INCLUDE_DIRECTORIES TRUE)
target_include_directories(${ISO22133_SWIGGED} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/inc
${CMAKE_CURRENT_SOURCE_DIR}/sigslot/include/sigslot
${CMAKE_CURRENT_SOURCE_DIR}/iso22133
${Python_INCLUDE_DIRS}
${JNI_INCLUDE_DIRS}
)

target_link_libraries(${ISO22133_SWIGGED}
${ISOOBJECT_LIBRARY}
${ISO22133_LIBRARY}
atomic
${Python_LIBRARIES}
${JNI_LIBRARIES}
)

if(SWIG_WITH_PYTHON)
execute_process(COMMAND python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
install(TARGETS ${ISO22133_SWIGGED} DESTINATION ${PYTHON_SITE_PACKAGES})
install(FILES ${CMAKE_BINARY_DIR}/isoObject_wrap.py DESTINATION ${PYTHON_SITE_PACKAGES})
endif()
endif()
endif()

# Build tests
if (BUILD_TESTING)
enable_testing()
file(GLOB TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp)
add_executable(${ISOOBJECT_LIBRARY}_test
${TEST_SOURCES}
)
target_link_libraries(${ISOOBJECT_LIBRARY}_test
gtest_main
${ISOOBJECT_LIBRARY}
)
target_include_directories(${ISOOBJECT_LIBRARY}_test PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/inc
)
include(GoogleTest)
gtest_discover_tests(${ISOOBJECT_LIBRARY}_test)
endif()
42 changes: 38 additions & 4 deletions inc/iso22133object.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
#pragma once

#ifdef ISO_OBJECT_EXPORTS
#define ISO22133OBJECT_API __declspec(dllexport)
#else
#define ISO22133OBJECT_API __declspec(dllimport)
#endif

#include <string>
#include <iostream>
#include <thread>
#include <mutex>
#include <atomic>
#include <chrono>

#include "header.h"
#include "iso22133.h"
#include "iso22133state.hpp"
#include "trajDecoder.hpp"
#include "signal.hpp"
#include "tcpServer.hpp"
#include "udpServer.hpp"
#ifndef __INTELLISENSE__
#include "tcpServer.hpp"
#include "udpServer.hpp"
#endif
#ifdef __INTELLISENSE__ // Workaround for intellisense bug with boost for VS2017
#include "tcpServer_temp.hpp"
#include "udpServer_temp.hpp"
#endif

namespace ISO22133 {
class State;
Expand All @@ -36,7 +49,7 @@ class PreRunning;
* the inheriting class must implement the pure
* virtual functions.
*/
class TestObject {
class ISO22133OBJECT_API TestObject {
friend class State;
friend class Unknown;
friend class Off;
Expand Down Expand Up @@ -97,6 +110,27 @@ class TestObject {
void startHEABCheck() { heabTimeoutThread = std::thread(&TestObject::checkHeabLoop, this); }
void startSendMonr() { monrThread = std::thread(&TestObject::sendMonrLoop, this); }

void abortRunning()
{

try {
state->handleEvent(*this, ISO22133::Events::W);
}
catch(const std::runtime_error& e) {
std::cerr << e.what() << '\n';
}
}

void confirmArming()
{
try {
state->handleEvent(*this, ISO22133::Events::N);
}
catch(const std::runtime_error& e) {
std::cerr << e.what() << '\n';
}
}

protected:
//! Wrapper for handling function that converts to char vector
int handleMessage(char *buffer, int bufferLen);
Expand Down Expand Up @@ -248,7 +282,7 @@ class TestObject {

namespace std::chrono {
template <typename Duration>
struct timeval to_timeval(Duration&& d) {
timeval to_timeval(Duration&& d) {
std::chrono::seconds const sec = std::chrono::duration_cast<std::chrono::seconds>(d);
struct timeval tv;
tv.tv_sec = sec.count();
Expand Down
13 changes: 10 additions & 3 deletions inc/iso22133state.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#pragma once

#ifdef ISO_OBJECT_EXPORTS
#define ISO22133STATE_API __declspec(dllexport)
#define ISO22133DISARMED_API __declspec(dllexport)
#else
#define ISO22133STATE_API __declspec(dllimport)
#define ISO22133DISARMED_API __declspec(dllimport)
#endif

#include <set>
#include <map>
#include <mutex>
#include <iostream>
#include <functional>
#include <atomic>
extern "C"{
#include "iso22133.h"
#include "header.h"
Expand Down Expand Up @@ -91,7 +98,7 @@ static const std::map<ObjectStateID, std::string> stateNames = {
* ISO 22133. It is not intended to be used outside of
* iso22133object.h
*/
class State {
class ISO22133STATE_API State {
friend class TestObject;
public:
State() {}
Expand Down Expand Up @@ -163,7 +170,7 @@ class Armed : public State {
virtual ObjectStateID getStateID() const final override { return ISO_OBJECT_STATE_ARMED; }
};

class Disarmed : public State {
class ISO22133DISARMED_API Disarmed : public State {
public:
virtual ObjectStateID getStateID() const final override { return ISO_OBJECT_STATE_DISARMED; }
virtual void onEnter(TestObject& obj);
Expand Down
2 changes: 1 addition & 1 deletion inc/tcpServer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#include <malloc.h> // Workaround for include issue caused by some boost lib?
#include <boost/asio.hpp>
#include <boost/system/system_error.hpp>
#include <vector>
Expand Down
4 changes: 4 additions & 0 deletions inc/tcpServer_temp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

class TcpServer {
};
4 changes: 2 additions & 2 deletions inc/trajDecoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <mutex>
#include <atomic>

#include "iso22133.h"
#include "traj.h"
#include "iso22133.h"

/**
* @brief Class for decoding TRAJ messages. Stores TRAJ data and
Expand All @@ -16,7 +16,7 @@ class TrajDecoder {
public:
TrajDecoder(bool debug) : debug(debug), expectingTRAJPoints(false) {};
TrajDecoder() : debug(false), expectingTRAJPoints(false) {};
ssize_t DecodeTRAJ(std::vector<char>&, bool debug = false);
size_t DecodeTRAJ(std::vector<char>&, bool debug = false);
bool ExpectingTrajPoints() const { return this->expectingTRAJPoints; }
TrajectoryHeaderType getTrajHeader() const;
std::vector<TrajectoryWaypointType> getTraj() const;
Expand Down
4 changes: 4 additions & 0 deletions inc/udpServer_temp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workaround for intellisense bug


class UdpServer {
};
4 changes: 2 additions & 2 deletions isoObject.i
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%rename(LessThan) operator<(const Transition &lhs, const Transition &rhs);

%typemap(in) (char *buffer, int bufferLen) {
Py_ssize_t len;
Py_size_t len;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file was probably not meant to be changed

PyBytes_AsStringAndSize($input, &$1, &len);
$2 = (int)len;
}
Expand Down Expand Up @@ -50,7 +50,7 @@ namespace std {
};

typedef double double_t;
typedef long int ssize_t;
typedef long int size_t;

struct timeval {
long int tv_sec;
Expand Down
Loading