Commit b32ea7e2 authored by Shervin Nourbakhsh's avatar Shervin Nourbakhsh
Browse files

(split) Fixed Rapidjson download from GIT if not installed in the system

parent 330d7e63
......@@ -3,6 +3,7 @@ if(NOT DEFINED PROJECT_NAME)
# Project name and version
project(cameo VERSION 1.0.1 LANGUAGES CXX)
#cmake_policy(SET CMP0048 NEW)
endif()
message("========================================")
......@@ -10,9 +11,11 @@ message("Project ${PROJECT_NAME}, major version: ${PROJECT_VERSION_MAJOR}, versi
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(FetchContent)
if(NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS True)
option(BUILD_SHARED_LIBS "Building dynamic (ON) or static (OFF)" ON)
#set(BUILD_SHARED_LIBS True)
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD)
......@@ -32,9 +35,22 @@ endif()
#------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(ZeroMQ REQUIRED)
find_package(Rapidjson REQUIRED)
find_package(Rapidjson QUIET)
if(NOT Rapidjson_FOUND)
message(WARNING "Using Rapidjson from GIT repository")
FetchContent_Declare(rapidjson
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
GIT_TAG v1.1.0
GIT_SHALLOW True
#INSTALL_COMMAND "make install"
)
FetchContent_GetProperties(rapidjson)
FetchContent_Populate(rapidjson)
set(Rapidjson_ROOT ${rapidjson_SOURCE_DIR})
find_package(Rapidjson REQUIRED)
endif()
message(${Rapidjson_INCLUDE_DIRS})
#------------------------------------------------------------
# Libraries
#------------------------------------------------------------
......@@ -42,9 +58,6 @@ find_package(Rapidjson REQUIRED)
#---------------
# Files
file(GLOB_RECURSE CAMEO_SOURCE_FILES "src/*.cpp")
#file(GLOB CAMEO_PUBLIC_HEADER_FILES "./*.h")
#message(${CAMEO_PUBLIC_HEADER_FILES})
#message(${CAMEO_SOURCE_FILES})
add_library(cameo ${CAMEO_SOURCE_FILES})
target_link_libraries(cameo PRIVATE zmq)
......@@ -53,6 +66,9 @@ target_include_directories(cameo
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_include_directories(cameo
SYSTEM PRIVATE ${Rapidjson_INCLUDE_DIRS}/
)
#target_include_directories(cameo PRIVATE ${DOCTEST_INCLUDE_DIR})
#target_compile_features(cameo PUBLIC cxx_std_11)
......@@ -156,7 +172,7 @@ if (DOXYGEN_FOUND)
message("Doxygen build started")
# note the option ALL which allows to build the docs together with the application
add_custom_target( doc
add_custom_target( cameo_doc
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
......
......@@ -40,8 +40,8 @@
namespace cameo {
enum Option {
NONE = 0,
OUTPUTSTREAM = 1
NONE = 0,
OUTPUTSTREAM = 1
};
class Server;
......@@ -72,23 +72,23 @@ typedef int32_t State;
#undef ERROR
const State UNKNOWN = 0;
const State STARTING = 1;
const State RUNNING = 2;
const State STOPPING = 4;
const State KILLING = 8;
const State UNKNOWN = 0;
const State STARTING = 1;
const State RUNNING = 2;
const State STOPPING = 4;
const State KILLING = 8;
const State PROCESSING_ERROR = 16;
const State FAILURE = 32;
const State SUCCESS = 64;
const State STOPPED = 128;
const State KILLED = 256;
/** \class This
* \brief class managing the current CAMEO application.
*
* \details The application has to be launched by CAMEO command line or another CAMEO app
* \todo why this does not inherit from the Instance class?
*/
const State FAILURE = 32;
const State SUCCESS = 64;
const State STOPPED = 128;
const State KILLED = 256;
/** \class This
* \brief class managing the current CAMEO application.
*
* \details The application has to be launched by CAMEO command line or another CAMEO app
* \todo why this does not inherit from the Instance class?
*/
class This : private Services, private EventListener {
friend class cameo::application::Publisher;
......@@ -103,7 +103,7 @@ class This : private Services, private EventListener {
friend class cameo::Server;
friend std::ostream& operator<<(std::ostream&, const cameo::application::This&);
typedef std::function<void ()> StopFunctionType;
typedef std::function<void()> StopFunctionType;
public:
/**
......@@ -123,25 +123,27 @@ public:
void releasePort(int port) const;
private:
Com(Server * server, int applicationId);
Com(Server* server, int applicationId);
Server * m_server;
Server* m_server;
int m_applicationId;
};
This();
~This();
static void init(int argc, char *argv[]);
static void init(int argc, char* argv[]);
static void init(const std::string& name, const std::string& endpoint);
/**
* The terminate call is not necessary unless the static instance of This is not destroyed automatically.
* The terminate call is not necessary unless the static instance of This is not destroyed
* automatically.
*/
static void terminate();
static const std::string& getName(); ///< returns the name of the CAMEO application corresponding to this instance
static int getId(); ///< returns the ID number of the instance
/// \brief returns the name of the CAMEO application corresponding to this instance
static const std::string& getName();
static int getId(); ///< returns the ID number of the instance
static void setTimeout(int timeout);
static int getTimeout();
static const Endpoint& getEndpoint(); ///< returns the TCP address of this instance
......@@ -156,9 +158,10 @@ public:
static bool isStopping();
/**
* Sets the stop handler with stopping time that overrides the one that may be defined in the configuration of the server.
* Sets the stop handler with stopping time that overrides the one that may be defined in the
* configuration of the server.
*/
template<typename Type>
template <typename Type>
static void handleStop(Type function, int stoppingTime = -1) {
m_instance.handleStopImpl(function, stoppingTime);
}
......@@ -179,7 +182,7 @@ public:
static std::unique_ptr<Instance> connectToStarter();
private:
void initApplication(int argc, char *argv[]);
void initApplication(int argc, char* argv[]);
void initApplication(const std::string& name, const std::string& endpoint);
static State parseState(const std::string& value);
......@@ -222,7 +225,7 @@ class Instance : private EventListener {
friend std::ostream& operator<<(std::ostream&, const Instance&);
public:
typedef std::function<void (State)> StateHandlerType;
typedef std::function<void(State)> StateHandlerType;
class Com {
......@@ -232,9 +235,9 @@ public:
std::string getKeyValue(const std::string& key) const;
private:
Com(Server * server);
Com(Server* server);
Server * m_server;
Server* m_server;
int m_applicationId;
};
......@@ -291,7 +294,7 @@ public:
std::shared_ptr<OutputStreamSocket> getOutputStreamSocket();
private:
Instance(Server * server);
Instance(Server* server);
void setId(int id);
void setErrorMessage(const std::string& message);
......@@ -300,7 +303,7 @@ private:
void setInitialState(State state);
State waitFor(int states, const std::string& eventName, KeyValue& keyValue, StateHandlerType handler, bool blocking);
Server * m_server;
Server* m_server;
std::shared_ptr<OutputStreamSocket> m_outputStreamSocket;
int m_id;
std::string m_errorMessage;
......@@ -379,7 +382,8 @@ public:
bool isEnded() const;
private:
Publisher(application::This * application, int publisherPort, int synchronizerPort, const std::string& name, int numberOfSubscribers);
Publisher(application::This* application, int publisherPort, int synchronizerPort,
const std::string& name, int numberOfSubscribers);
std::unique_ptr<PublisherImpl> m_impl;
std::unique_ptr<WaitingImpl> m_waiting;
......@@ -397,7 +401,7 @@ class Subscriber {
public:
~Subscriber();
static std::unique_ptr<Subscriber> create(Instance & instance, const std::string& publisherName);
static std::unique_ptr<Subscriber> create(Instance& instance, const std::string& publisherName);
const std::string& getPublisherName() const;
const std::string& getInstanceName() const;
......@@ -423,7 +427,9 @@ public:
void cancel();
private:
Subscriber(Server * server, int publisherPort, int synchronizerPort, const std::string& publisherName, int numberOfSubscribers, const std::string& instanceName, int instanceId, const std::string& instanceEndpoint, const std::string& statusEndpoint);
Subscriber(Server* server, int publisherPort, int synchronizerPort, const std::string& publisherName,
int numberOfSubscribers, const std::string& instanceName, int instanceId,
const std::string& instanceEndpoint, const std::string& statusEndpoint);
void init();
std::unique_ptr<SubscriberImpl> m_impl;
......@@ -461,7 +467,7 @@ public:
std::unique_ptr<Server> getServer();
private:
Request(std::unique_ptr<RequestImpl> & impl);
Request(std::unique_ptr<RequestImpl>& impl);
std::unique_ptr<RequestImpl> m_impl;
std::unique_ptr<Server> m_requesterServer;
......@@ -487,7 +493,7 @@ public:
void cancel();
/** \brief Receive a request
/** \brief Receive a request
* blocking command
*/
std::unique_ptr<Request> receive();
......@@ -496,7 +502,7 @@ public:
bool isCanceled() const;
private:
Responder(application::This * application, int responderPort, const std::string& name);
Responder(application::This* application, int responderPort, const std::string& name);
std::unique_ptr<ResponderImpl> m_impl;
std::unique_ptr<WaitingImpl> m_waiting;
......@@ -507,7 +513,7 @@ private:
class Requester {
friend std::ostream& operator<<(std::ostream&, const Requester&);
friend std::ostream& operator<<(std::ostream&, const Requester&);
public:
~Requester();
......@@ -516,7 +522,7 @@ public:
* Returns the responder with name.
* throws RequesterCreationException.
*/
static std::unique_ptr<Requester> create(Instance & instance, const std::string& name);
static std::unique_ptr<Requester> create(Instance& instance, const std::string& name);
const std::string& getName() const;
......@@ -532,7 +538,8 @@ public:
bool isCanceled() const;
private:
Requester(application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId, int requesterId);
Requester(application::This* application, const std::string& url, int requesterPort,
int responderPort, const std::string& name, int responderId, int requesterId);
std::unique_ptr<RequesterImpl> m_impl;
std::unique_ptr<WaitingImpl> m_waiting;
......@@ -546,7 +553,8 @@ class Configuration {
friend std::ostream& operator<<(std::ostream&, const Configuration&);
public:
Configuration(const std::string& name, const std::string& description, bool singleInfo, bool restart, int startingTime, int stoppingTime);
Configuration(const std::string& name, const std::string& description, bool singleInfo, bool restart,
int startingTime, int stoppingTime);
const std::string& getName() const;
const std::string& getDescription() const;
......@@ -572,7 +580,8 @@ class Info {
friend std::ostream& operator<<(std::ostream&, const Info&);
public:
Info(const std::string& name, int id, int pid, State applicationState, State pastApplicationStates, const std::string& args);
Info(const std::string& name, int id, int pid, State applicationState, State pastApplicationStates,
const std::string& args);
int getId() const;
State getState() const;
......@@ -623,9 +632,7 @@ std::ostream& operator<<(std::ostream&, const cameo::application::Configuration&
std::ostream& operator<<(std::ostream&, const cameo::application::Info&);
std::ostream& operator<<(std::ostream&, const cameo::application::Port&);
}
}
} // namespace application
} // namespace cameo
#endif
......@@ -19,6 +19,10 @@ target_link_libraries(testapplicationidentity
target_include_directories(testapplicationidentity
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/
)
target_include_directories(testapplicationidentity
SYSTEM PRIVATE ${Rapidjson_INCLUDE_DIRS}/
)
add_test(applicationidentity testapplicationidentity)
......@@ -30,5 +34,8 @@ target_link_libraries(testapplicationwithstarteridentity PRIVATE
target_include_directories(testapplicationwithstarteridentity
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/
)
target_include_directories(testapplicationwithstarteridentity
SYSTEM PRIVATE ${Rapidjson_INCLUDE_DIRS}/
)
add_test(applicationwithstarteridentity testapplicationwithstarteridentity)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment