Commit 0b86b831 authored by Hurstel's avatar Hurstel

Initial commit

parents
IF(UNIX)
SET(LEAP_INCLUDE_SEARCH_DIRS
/usr/include
/usr/local/include
/opt/leap/include
/opt/leap_sdk/include
/opt/include INTERNAL)
SET(LEAP_LIBRARY_SEARCH_DIRS
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/leap/lib
/opt/leap/lib64
/opt/leap_sdk/lib
/opt/leap_sdk/lib64 INTERNAL)
SET(LEAP_INC_DIR_SUFFIXES PATH_SUFFIXES leap)
ELSE(UNIX)
#WIN32
SET(LEAP_INC_DIR_SUFFIXES PATH_SUFFIXES inc)
SET(LEAP_LIB_DIR_SUFFIXES PATH_SUFFIXES lib)
ENDIF(UNIX)
# Set name of the Leap library to use
IF(APPLE)
SET(LEAP_LIBRARY_NAME libLeap.dylib)
ELSE(APPLE)
IF(UNIX)
SET(LEAP_LIBRARY_NAME libLeap.so)
ELSE(UNIX)
# TODO Different libraries are provided for compile and runtime
SET(LEAP_LIBRARY_NAME libLeap.lib)
ENDIF(UNIX)
ENDIF(APPLE)
IF(NOT LEAP_FIND_QUIETLY)
MESSAGE(STATUS "Checking for Leap")
ENDIF(NOT LEAP_FIND_QUIETLY)
# Search for header files
FIND_PATH(LEAP_INCLUDE_DIR Leap.h
PATHS ${LEAP_INCLUDE_SEARCH_PATHS}
PATH_SUFFIXES ${LEAP_INC_DIR_SUFFIXES})
# Search for library
FIND_LIBRARY(LEAP_LIBRARY ${LEAP_LIBRARY_NAME}
PATHS ${LEAP_LIBRARY_SEARCH_DIRS}
PATH_SUFFIXES ${LEAP_LIB_DIR_SUFFIXES})
SET(LEAP_INCLUDE_DIR ${LEAP_INCLUDE_DIR} CACHE STRING
"Directory containing LEAP header files")
SET(LEAP_LIBRARY ${LEAP_LIBRARY} CACHE STRING "Library name of Leap
library")
SET(LEAP_INCLUDE_DIRS ${LEAP_INCLUDE_DIR} )
SET(LEAP_LIBRARIES ${LEAP_LIBRARY} )
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Leap DEFAULT_MSG LEAP_LIBRARY
LEAP_INCLUDE_DIR)
MARK_AS_ADVANCED(LEAP_INCLUDE_DIR LEAP_LIBRARY)
function(checkCpp11Support)
# ====== Check GCC VERSION FOR C++11 ======
if(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_LESS 4.8)
message(FATAL_ERROR "Full support of C++11 needed. Therefore a gcc/g++ compiler with a version at least 4.8 is needed.")
endif()
endif()
# ====== Check CLANG VERSION FOR C++11 ======
if (APPLE)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CLANG_VERSION)
if (CLANG_VERSION VERSION_LESS 3.1)
message(FATAL_ERROR "Full support of C++11 needed. Therefore a clang compiler with a version at least 3.1 is needed !!")
endif()
endif()
# ====== Check MSVC VERSION FOR C++11 ======
if(WIN32)
if(MSVC_VERSION LESS 1800)
message(FATAL_ERROR "Full support of C++11 needed. Therefore a microsoft compiler with a version at least 12 is needed.")
endif()
endif()
endfunction(checkCpp11Support)
function(checkCpp11Feature FEATURE RESULT IS_FATAL)
set(definitions "")
if (NOT MSVC)
set(definitions "-std=c++11")
endif(NOT MSVC)
set(source "${CMAKE_MODULE_PATH}/tests/cxx11-test-${FEATURE}.cpp")
set(bindir "${CMAKE_CURRENT_BINARY_DIR}/cxx11/cxx11_${FEATURE}")
try_run(run_result compile_result
${bindir} ${source}
COMPILE_DEFINITIONS ${definitions})
if (${run_result} EQUAL "1")
set(${RESULT} "True" PARENT_SCOPE)
message("Checking cpp11 feature support ${FEATURE} : OK")
else()
set(${RESULT} "False" PARENT_SCOPE)
if (${IS_FATAL})
message(FATAL_ERROR "Checking cpp11 feature support ${FEATURE} : Fail. Please update your compiler (GCC >= 4.9, Clang >= 3.5, VS 2013).")
else()
message("Checking cpp11 feature support ${FEATURE} : Fail.")
endif()
endif()
endfunction(checkCpp11Feature)
function(setBuildType)
IF (NOT (${CMAKE_BUILD_TYPE} MATCHES "Debug|Release"))
IF (${CMAKE_CURRENT_BINARY_DIR} MATCHES "(.*)Debug|(.*)debug|(.*)DEBUG")
SET(CMAKE_BUILD_TYPE "Debug" PARENT_SCOPE)
ELSE()
SET(CMAKE_BUILD_TYPE "Release" PARENT_SCOPE)
ENDIF()
ENDIF()
endfunction(setBuildType)
macro(ToRelativePath outFiles fromDirectory inFiles)
unset(tmpFiles)
foreach(inFile ${inFiles})
file(RELATIVE_PATH outFile "${fromDirectory}" "${inFile}")
list(APPEND tmpFiles "${outFile}")
endforeach()
set(${outFiles} ${tmpFiles})
endmacro()
function(module_comp_gen MOD_LIST GEN_FILE)
file(REMOVE ${GEN_FILE})
SET(MOD_FILE_CONTENT "#ifndef _MODULES_H_\n#define _MODULES_H_\n")
foreach(MOD_FILE ${MOD_LIST})
SET(MOD_FILE_CONTENT "${MOD_FILE_CONTENT}#include \"${MOD_FILE}/module.h\"\n")
endforeach(MOD_FILE ${MOD_LIST})
SET(MOD_FILE_CONTENT "${MOD_FILE_CONTENT}\n\nnamespace Modules{\n\tvoid Init(){\n")
foreach(MOD_FILE ${MOD_LIST})
get_filename_component(BASE_MOD ${MOD_FILE} NAME_WE)
SET(MOD_FILE_CONTENT "${MOD_FILE_CONTENT}\t\t${BASE_MOD}_Init();\n")
endforeach(MOD_FILE ${MOD_LIST})
SET(MOD_FILE_CONTENT "${MOD_FILE_CONTENT}\t}\n\n\tvoid Destroy(){\n")
foreach(MOD_FILE ${MOD_LIST})
get_filename_component(BASE_MOD ${MOD_FILE} NAME_WE)
SET(MOD_FILE_CONTENT "${MOD_FILE_CONTENT}\t\t${BASE_MOD}_Destroy();\n")
endforeach(MOD_FILE ${MOD_LIST})
SET(MOD_FILE_CONTENT "${MOD_FILE_CONTENT}\t}\n};\n\n#endif //_MODULES_H_\n")
file(WRITE ${GEN_FILE} "${MOD_FILE_CONTENT}")
endfunction(module_comp_gen)
function(add_mod_dependencies)
foreach(MOD_DEP ${ARGN})
SET(MOD_DEPENDENCIES ${MOD_DEPENDENCIES} ${MOD_DEP} )
INCLUDE_DIRECTORIES(
${MOD_DIR}/${MOD_DEP}/include
)
endforeach(MOD_DEP ${MOD})
SET(MOD_DEPENDENCIES ${MOD_DEPENDENCIES} PARENT_SCOPE)
endfunction(add_mod_dependencies)
function(base_mod_compile)
SET(MOD_DIRS ${MOD_DIRS} ${MOD_ROOT_DIR} PARENT_SCOPE)
SET(MODS ${MODS} ${MOD_NAME} PARENT_SCOPE)
ADD_LIBRARY(${MOD_NAME} SHARED
${MOD_FILES}
)
TARGET_LINK_LIBRARIES(${MOD_NAME} ${MOD_LINK_LIBS} Core)
if(MOD_DEPENDENCIES)
message(STATUS "Mod '${MOD_NAME}': acknowledged dependencies : ${MOD_DEPENDENCIES}")
ADD_DEPENDENCIES(${MOD_NAME} Core)
else(MOD_DEPENDENCIES)
message(STATUS "Mod '${MOD_NAME}': no acknowledged dependencies")
ADD_DEPENDENCIES(${MOD_NAME} Core ${MOD_DEPENDENCIES})
endif(MOD_DEPENDENCIES)
endfunction(base_mod_compile)
cmake_minimum_required (VERSION 3.1)
PROJECT(proto1_cpp)
#set( CMAKE_BUILD_TYPE Debug)
set ( CMAKE_VERBOSE_MAKEFILE true )
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/CMake/functions.cmake)
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/CMake/module_comp.cmake)
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
checkCpp11Support()
setBuildType()
message("Build type: ${CMAKE_BUILD_TYPE}")
IF ((${CMAKE_BUILD_TYPE} MATCHES "Debug"))
SET(COMPILE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/debug" CACHE STRING "compile directory (empty for default)")
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/debug)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libD)
ELSE ((${CMAKE_BUILD_TYPE} MATCHES "Debug"))
SET(COMPILE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin" CACHE STRING "compile directory (empty for default)")
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
ENDIF ((${CMAKE_BUILD_TYPE} MATCHES "Debug"))
# C++11
set (CMAKE_CXX_STANDARD 11)
SET(PYTHON_ENV_PATH "${COMPILE_DIRECTORY}" CACHE STRING "the default python working directory")
SET(DEV_PYTHON_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../py" CACHE STRING "the project's python modules directory" )
link_directories(${LIBRARY_OUTPUT_PATH})
SET(PY_LESS TRUE CACHE BOOL "Without python?")
IF(PY_LESS)
find_package(Boost)
add_definitions(-DNOPYTHON)
ELSE(PY_LESS)
find_package(Boost EXACT REQUIRED COMPONENTS python3)
find_package(PythonLibs)
ENDIF(PY_LESS)
SET(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
SET(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/includes)
SET(CORE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/core)
ADD_SUBDIRECTORY(${CORE_DIR})
SET(MODS "")
SET(MOD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/mods)
SET(MOD_DIRS "")
SET(COMPILE_MOD TRUE CACHE BOOL "Compile mods?")
IF(COMPILE_MOD)
ADD_SUBDIRECTORY(${MOD_DIR})
module_comp_gen("${MODS}" "${INCLUDE_DIR}/modules.h")
ENDIF(COMPILE_MOD)
INCLUDE_DIRECTORIES(${INCLUDE_DIR} ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ${MOD_DIR} ${MOD_DIRS} ${CORE_INCLUDE_DIR})
file(
GLOB_RECURSE
SOURCE_FILES
${SOURCE_DIR}/*.cpp
)
file(
GLOB_RECURSE
INCLUDE_FILES
${INCLUDE_DIR}/*.h
${INCLUDE_DIR}/*.hpp
)
IF( NOT PY_LESS )
file(
GLOB_RECURSE
PY_FILES
${SOURCE_DIR}/*.py
)
ENDIF( NOT PY_LESS )
link_directories(${LIBRARY_OUTPUT_PATH} ${Boost_LIBRARY_DIRS})
ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCE_FILES} ${INCLUDE_FILES} ${CORE_INCLUDE_FILES} ${MOD_DIR}/modLists.txt)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} pthread ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${MODS} Core)
IF(COMPILE_MOD)
ADD_DEPENDENCIES(${PROJECT_NAME} ${MODS} Core)
ELSE(COMPILE_MOD)
ADD_DEPENDENCIES(${PROJECT_NAME} Core)
ENDIF(COMPILE_MOD)
cmake_minimum_required (VERSION 3.1)
SET(CORE_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
SET(CORE_SRC_DIR ${CORE_ROOT}/src)
SET(CORE_INCLUDE_DIR ${CORE_ROOT}/include)
SET(PROTO1_CPP_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
SET(COMPILE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin" CACHE STRING "compile directory (empty for default)")
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
configure_file( "${CORE_SRC_DIR}/formatable/_pathStrings" "${CORE_SRC_DIR}/pathStrings.cpp")
INCLUDE_DIRECTORIES(
${CORE_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
)
file(
GLOB_RECURSE
CORE_SRC_FILES
${CORE_SRC_DIR}/*.cpp
)
file(
GLOB_RECURSE
CORE_INCLUDE_FILES
${CORE_INCLUDE_DIR}/*.h
${CORE_INCLUDE_DIR}/*.hpp
)
ADD_LIBRARY(Core SHARED
${CORE_SRC_FILES}
${CORE_INCLUDE_FILES}
)
link_directories(${Boost_LIBRARY_DIRS})
TARGET_LINK_LIBRARIES(Core ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} Threads::Threads)
SET(CORE_INCLUDE_DIR ${CORE_INCLUDE_DIR} PARENT_SCOPE)
#ifndef __CORE_H__
#define __CORE_H__
#include "state.h"
#include "messager.h"
#include "manager.h"
static const unsigned int CORE_ID= 1;
class Core : public StateReciever, public InAppMessager::Agent{
public:
inline Core(int argc, char** argv)
{
m_startArgs.argc= argc;
m_startArgs.argv= argv;
StateManager::addReciever(this);
InAppManager::addAgent(this);
}
void onStateChange(STATE current, STATE previous);
void Start();
protected:
void recieveMessage(const InAppMessage& iam);
inline unsigned int getId() const{return CORE_ID;}
private:
struct{
int argc; char** argv;
} m_startArgs;
};
#endif // __CORE_H__
#ifndef EVENT_H
#define EVENT_H
#include <thread>
class EventPass{
public:
static unsigned long int eventPass();
static void endEventPass(unsigned long int key);
static void waitToEnd();
protected:
static std::thread* s_eventThread;
static unsigned long int s_waitEvSrcEnd;
static unsigned long int s_counter;
static bool s_run;
};
#endif // EVENT_H
#ifndef __MANAGER_H__
#define __MANAGER_H__
#include "messager.h"
class InAppManager{
public:
static inline void Start(){ m_messager.Start();}
static inline void Join(){ m_messager.Join();}
static inline void Stop(){ m_messager.Stop();}
static inline bool addAgent(InAppMessager::Agent* agent){ return InAppManager::m_messager.addAgent(agent);}
static inline void broadcastMessage(const InAppMessage& iam){ InAppManager::m_messager.broadcastMessage(iam);}
static inline void removeAgent(InAppMessager::Agent* agent){ InAppManager::m_messager.removeAgent(agent);}
static inline bool isRegistered(unsigned int agentID){return InAppManager::m_messager.isRegistered(agentID);}
protected:
static InAppMessager m_messager;
};
#endif //__MANAGER_H__
#ifndef _MESSAGER_H_
#define _MESSAGER_H_
#include <stdio.h>
#include <list>
#include <vector>
#include <string>
#include <thread>
#include <iostream>
#include <boost/shared_ptr.hpp>
class InAppMessage{
public:
typedef unsigned int MESSAGE;
// enum MESSAGE{
static const MESSAGE EMPTY_MESSAGE= 0;
static const MESSAGE LAUNCH_APP= 1;
static const MESSAGE BASE_MESSAGE_LIMIT= 4096;
// };
class Args{
public:
Args(){}
Args(const Args& args) :
m_args(args.m_args)
{}
typedef boost::shared_ptr<void> ARG_T;
template<typename T>
Args& addArg(T arg){
m_args.push_back(
ARG_T(
static_cast<void*>(
new T{arg}
)
)
);
return (*this);
}
Args& operator=(const Args& o){
if(this!= &o){
m_args= o.m_args;
}
return (*this);
}
template<typename T>
T getArg(unsigned int index= 0) const{
assert(index<m_args.size() );
return (*(static_cast<T*>( m_args[index].get() )));
}
inline unsigned int count() const{return m_args.size();}
protected:
std::vector< ARG_T > m_args;
};
InAppMessage(MESSAGE msg_code= EMPTY_MESSAGE):
m_code(msg_code)
{}
InAppMessage(MESSAGE msg_code, const Args &args):
m_code(msg_code),
m_args(args)
{}
template<typename T>
void addArg(T arg){
m_args.addArg(arg);
}
inline static InAppMessage create(MESSAGE msg_code= EMPTY_MESSAGE){
return InAppMessage(msg_code);
}
inline static InAppMessage create(MESSAGE msg_code, const Args &args){
return InAppMessage(msg_code, args);
}
static InAppMessage create(std::string messageHead, const Args& args);
inline MESSAGE getCode() const{return m_code;}
inline bool isEmpty() const { return m_code==EMPTY_MESSAGE; }
inline const Args& getArgs() const{return m_args;}
inline unsigned int countArgs() const{return m_args.count();}
protected:
MESSAGE m_code;
Args m_args;
static MESSAGE strCodeConversion(std::string msg);
static void* strArgsConversion(MESSAGE msg_code, const Args& args);
};
class InAppMessager{
public:
inline InAppMessager(){}
class Agent{
friend class InAppMessager;
public:
typedef InAppMessage::MESSAGE OWN_MESSAGE;
Agent(InAppMessager* iam= NULL):
m_inAppMessager(iam)
{
if(iam){
iam->addAgent(this);
}
}
virtual ~Agent(){}
protected:
virtual void recieveMessage(const InAppMessage& iam){}
virtual unsigned int getId() const= 0;
inline void sendMessage(const InAppMessage& iam){
m_inAppMessager->broadcastMessage(iam);
}
inline bool isRegistered(unsigned int agentID){
return m_inAppMessager->isRegistered(agentID);
}
private:
static const unsigned int m_ownMessageLimit= 1024;
InAppMessager* m_inAppMessager;
};
bool addAgent(Agent* agent);
inline void removeAgent(Agent* agent){if(agent) l_agents.remove(agent);}
void broadcastMessage(const InAppMessage& iam);
void Start();
inline void Join(){if(m_msgThread){m_msgThread->join();}}
inline void Stop(){b_run= false;}
inline bool isRunning(){return b_run;}
bool isRegistered(unsigned int agentID);
protected:
std::list<Agent*> l_agents;
std::list<InAppMessage> m_msgQueue;
bool b_run= false;
std::thread* m_msgThread=NULL;
};
#endif //_MESSAGER_H_
#ifndef _MODULES_H_
#define _MODULES_H_
#include "LM/module.h"
namespace Modules{
void Init(){
LM_mod::Init();
}
void Destroy(){
LM_mod::Destroy();
}
};
#endif //_MODULES_H_
#ifndef _PATHSTRINGS_H_
#define _PATHSTRINGS_H_
namespace PathStrings{
extern const char* PYTHON_ENV_PATH;
extern const char* DEV_PYTHON_ROOT;
};
#endif //_PATHSTRINGS_H_
#ifndef _PYEMB_H_
#define _PYEMB_H_
#ifndef NOPYTHON
#include <iostream>
#include <boost/python.hpp>
#include <boost/python/import.hpp>
#include "pythonWrap.h"
using namespace boost::python;
class PyEmb {
private:
static bool b_isMainModuleSet;
static bool b_isMainNamespaceSet;
static bool b_isSysModuleSet;
static bool b_isSysNameSpaceSet;
static bool b_isInAppModuleSet;
static bool b_isInAppNameSpaceSet;
protected:
static object main_module;
static object main_namespace;
static object sys_module;
static object sys_namespace;
static object inApp_module;
static object inApp_namespace;
public:
static object getMainModule(){
if (!b_isMainModuleSet){
main_module= object((
handle<>(borrowed(PyImport_AddModule("__main__")))
));
b_isMainModuleSet= true;
}
return main_module;
}
static object getMainNamespace(){
if (b_isMainNamespaceSet) return main_namespace;
getMainModule();