diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d7c22d..e6d3c7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,53 +1,15 @@ project(SparrowInput) cmake_minimum_required(VERSION 2.8) -if(WIN32) - set(SYSTEM_LIB_PATH "win32") -else(WIN32) - set(SYSTEM_LIB_PATH "linux") -endif(WIN32) +# choose source file +file(GLOB LIB_SRC_LIST src/*.cpp) +file(GLOB LIB_HEAD_LIST src/*.h) +list(REMOVE_ITEM LIB_SRC_LIST src/main.cpp) +set(EXEC_SRC_LIST src/main.cpp) -set(LIB_SRC_LIST input.cpp keybindings.cpp textbuffer.cpp) +#set compilation option +set(IS_LIBRARY True) +set(USE_OPENGL True) +set(USE_SFML True) -set(EXECUTABLE_NAME "test${PROJECT_NAME}") -set(LIBRARY_NAME ${PROJECT_NAME}) - -set(DEPENDENCIES_ROOT ${PROJECT_SOURCE_DIR}/../cpp_dependencies) -set(INCLUDE_ROOT ${DEPENDENCIES_ROOT}/include) -set(LIB_ROOT ${DEPENDENCIES_ROOT}/lib/${SYSTEM_LIB_PATH}) - -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_ROOT}) #for SHARED -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_ROOT}) #for STATIC - -add_library(${LIBRARY_NAME} STATIC ${LIB_SRC_LIST}) -add_executable(${EXECUTABLE_NAME} main.cpp) -add_definitions(-std=c++11) - -include_directories( - ${INCLUDE_ROOT} -) - -find_library(SFML_LIBRARY_WINDOW - NAMES - sfml-window - PATHS - ${LIB_ROOT} -) - -find_library(SFML_LIBRARY_SYSTEM - NAMES - sfml-system - PATHS - ${LIB_ROOT} -) - -target_link_libraries( - ${LIBRARY_NAME} - ${SFML_LIBRARY_WINDOW} - ${SFML_LIBRARY_SYSTEM} -) - -target_link_libraries( - ${EXECUTABLE_NAME} - ${LIBRARY_NAME} -) +include(template.cmake) diff --git a/input.cpp b/src/input.cpp similarity index 95% rename from input.cpp rename to src/input.cpp index 4f2a364..4ad9e2e 100644 --- a/input.cpp +++ b/src/input.cpp @@ -1,167 +1,167 @@ -/** -* @author: Thomas Brandého -*/ - -#include "input.h" - -#include -#include -#include - -Input::Input(sf::Window *w): window(w) -{ - heldkeys = std::vector(); - action_file = std::queue(); - window->setKeyRepeatEnabled(false); -} - -void Input::setKeysMap(IKeysMap km){ - keysmap = km; -} - -void Input::updateEvents(){ - sf::Event event; - KeyBindings kb; - char c; - - /* reset variables */ - closeRequested = false; - hasBeenResized = false; - delta_vertical_scroll = 0; - - /* global affectation */ - kb = keybindings[current_context]; - - /* event-parsing loop */ - while(window->pollEvent(event)){ - switch(event.type){ - case sf::Event::Closed: - closeRequested = true; - break; - case sf::Event::TextEntered: - c = (char) event.text.unicode; - buffer.append(&c); - break; - case sf::Event::KeyPressed: - action_file.push(kb.getPressedAction(event.key.code)); - heldkeys.push_back(event.key.code); - break; - case sf::Event::KeyReleased: - action_file.push(kb.getReleasedAction(event.key.code)); - releaseHeldKeys(event.key.code); - break; - case sf::Event::MouseButtonPressed: - action_file.push(kb.getPressedAction(sf::Keyboard::KeyCount + event.mouseButton.button)); - heldkeys.push_back((sf::Keyboard::Key) (sf::Keyboard::KeyCount + event.mouseButton.button)); - break; - case sf::Event::MouseButtonReleased: - action_file.push(kb.getReleasedAction(sf::Keyboard::KeyCount + event.mouseButton.button)); - releaseHeldKeys((sf::Keyboard::Key) (sf::Keyboard::KeyCount + event.mouseButton.button)); - break; - case sf::Event::MouseWheelScrolled: - if (event.mouseWheelScroll.wheel == sf::Mouse::VerticalWheel) - delta_vertical_scroll = event.mouseWheelScroll.delta; - break; - case sf::Event::MouseMoved: - last_mouse_position = mouse_position; - mouse_position = sf::Mouse::getPosition(); - break; - case sf::Event::MouseEntered: - // action MouseEntered - break; - case sf::Event::MouseLeft: - //action MouseLeft - break; - case sf::Event::Resized: - hasBeenResized = true; - break; - } - } - for (auto key: heldkeys){ - action_file.push(kb.getHoldAction(key)); - } -} - - -int Input::getAction() -{ - if (action_file.empty()) - return -1; - int val = action_file.front(); - action_file.pop(); - return val; -} - - -/* context-related functions */ -void Input::addContext(Context context) -{ - contexts.push_back(context); -} - -void Input::setCurrentContext(std::string context_name){ - current_context = context_name; -} - -void Input::updateKeyBindings(){ - keybindings.clear(); - for (auto iter= contexts.begin(); iter != contexts.end(); ++iter) - keybindings[iter->getName()]= KeyBindings(*iter,keysmap); -} - - -/* window-related function */ - -bool Input::isCloseRequested() const -{ - return closeRequested; -} - -bool Input::isResized() const -{ - return hasBeenResized; -} - -/* keyboard-related functions */ - -bool Input::isKeyPressed(int key) const -{ - return sf::Keyboard::isKeyPressed((sf::Keyboard::Key) key); -} - -void Input::releaseHeldKeys(sf::Keyboard::Key keycode){ - auto iter = heldkeys.begin(); - while(*iter != keycode) ++iter; - heldkeys.erase(iter); -} - -/* mouse-related functions */ - -sf::Vector2i Input::getPosition() const -{ - return mouse_position; -} - -sf::Vector2i Input::getDeltaPosition() const -{ - return mouse_position - last_mouse_position; -} - -float Input::getDeltaVerticalScroll() const -{ - return delta_vertical_scroll; -} - -/* ------ */ - -void Input::test() -{ - KeyBindings kb = keybindings[current_context]; - int action; - action = kb.getPressedAction(sf::Keyboard::I); - if (action != NO_ACTION) - std::cerr << action << std::endl; - action = kb.getPressedAction(sf::Keyboard::O); - if (action != NO_ACTION) - std::cerr << action << std::endl; -} +/** +* @author: Thomas Brandého +*/ + +#include "input.h" + +#include +#include +#include + +Input::Input(sf::Window *w): window(w) +{ + heldkeys = std::vector(); + action_file = std::queue(); + window->setKeyRepeatEnabled(false); +} + +void Input::setKeysMap(IKeysMap km){ + keysmap = km; +} + +void Input::updateEvents(){ + sf::Event event; + KeyBindings kb; + char c; + + /* reset variables */ + closeRequested = false; + hasBeenResized = false; + delta_vertical_scroll = 0; + + /* global affectation */ + kb = keybindings[current_context]; + + /* event-parsing loop */ + while(window->pollEvent(event)){ + switch(event.type){ + case sf::Event::Closed: + closeRequested = true; + break; + case sf::Event::TextEntered: + c = (char) event.text.unicode; + buffer.append(&c); + break; + case sf::Event::KeyPressed: + action_file.push(kb.getPressedAction(event.key.code)); + heldkeys.push_back(event.key.code); + break; + case sf::Event::KeyReleased: + action_file.push(kb.getReleasedAction(event.key.code)); + releaseHeldKeys(event.key.code); + break; + case sf::Event::MouseButtonPressed: + action_file.push(kb.getPressedAction(sf::Keyboard::KeyCount + event.mouseButton.button)); + heldkeys.push_back((sf::Keyboard::Key) (sf::Keyboard::KeyCount + event.mouseButton.button)); + break; + case sf::Event::MouseButtonReleased: + action_file.push(kb.getReleasedAction(sf::Keyboard::KeyCount + event.mouseButton.button)); + releaseHeldKeys((sf::Keyboard::Key) (sf::Keyboard::KeyCount + event.mouseButton.button)); + break; + case sf::Event::MouseWheelScrolled: + if (event.mouseWheelScroll.wheel == sf::Mouse::VerticalWheel) + delta_vertical_scroll = event.mouseWheelScroll.delta; + break; + case sf::Event::MouseMoved: + last_mouse_position = mouse_position; + mouse_position = sf::Mouse::getPosition(); + break; + case sf::Event::MouseEntered: + // action MouseEntered + break; + case sf::Event::MouseLeft: + //action MouseLeft + break; + case sf::Event::Resized: + hasBeenResized = true; + break; + } + } + for (auto key: heldkeys){ + action_file.push(kb.getHoldAction(key)); + } +} + + +int Input::getAction() +{ + if (action_file.empty()) + return -1; + int val = action_file.front(); + action_file.pop(); + return val; +} + + +/* context-related functions */ +void Input::addContext(Context context) +{ + contexts.push_back(context); +} + +void Input::setCurrentContext(std::string context_name){ + current_context = context_name; +} + +void Input::updateKeyBindings(){ + keybindings.clear(); + for (auto iter= contexts.begin(); iter != contexts.end(); ++iter) + keybindings[iter->getName()]= KeyBindings(*iter,keysmap); +} + + +/* window-related function */ + +bool Input::isCloseRequested() const +{ + return closeRequested; +} + +bool Input::isResized() const +{ + return hasBeenResized; +} + +/* keyboard-related functions */ + +bool Input::isKeyPressed(int key) const +{ + return sf::Keyboard::isKeyPressed((sf::Keyboard::Key) key); +} + +void Input::releaseHeldKeys(sf::Keyboard::Key keycode){ + auto iter = heldkeys.begin(); + while(*iter != keycode) ++iter; + heldkeys.erase(iter); +} + +/* mouse-related functions */ + +sf::Vector2i Input::getPosition() const +{ + return mouse_position; +} + +sf::Vector2i Input::getDeltaPosition() const +{ + return mouse_position - last_mouse_position; +} + +float Input::getDeltaVerticalScroll() const +{ + return delta_vertical_scroll; +} + +/* ------ */ + +void Input::test() +{ + KeyBindings kb = keybindings[current_context]; + int action; + action = kb.getPressedAction(sf::Keyboard::I); + if (action != NO_ACTION) + std::cerr << action << std::endl; + action = kb.getPressedAction(sf::Keyboard::O); + if (action != NO_ACTION) + std::cerr << action << std::endl; +} diff --git a/input.h b/src/input.h similarity index 95% rename from input.h rename to src/input.h index 26abf36..d71bc42 100644 --- a/input.h +++ b/src/input.h @@ -1,75 +1,75 @@ -/** -* @author: Thomas Brandého -*/ - -#ifndef INPUT_H -#define INPUT_H -#include "keybindings.h" -#include -#include -#include -#include "textbuffer.h" - -class Input{ - public: - /* Constructors */ - Input(sf::Window *w); - - /* general action-mapping functions */ - void setKeysMap(IKeysMap km); - void updateEvents(); - int getAction(); - - /* context-related functions */ - void addContext(Context context); - void setCurrentContext(std::string context_name); - void updateKeyBindings(); - - /* window-related function */ - bool isCloseRequested() const; - bool isResized() const; - - /* keyboard-related functions */ - bool isKeyPressed(int key) const; - - /* mouse-related function */ - sf::Vector2i getPosition() const; - sf::Vector2i getDeltaPosition() const; - float getDeltaVerticalScroll() const; - - /* text-related function */ - std::string getText(); - - void test(); - - private: - /* window-related variables */ - sf::Window* window; - bool closeRequested; - bool hasBeenResized; - - /* general action-mapping variables */ - IKeysMap keysmap; - std::queue action_file; - int nb_actions; - - /* context-related variables */ - std::string current_context; - //std::unordered_map> contexts; - std::vector contexts; - std::unordered_map keybindings; - - /* keyboard-related variables */ - std::vector heldkeys; - void releaseHeldKeys(sf::Keyboard::Key keycode); - - /* mouse-related variables */ - sf::Vector2i mouse_position; - sf::Vector2i last_mouse_position; - float delta_vertical_scroll; - - /* text-related variable */ - std::string buffer; -}; - -#endif //INPUT_H +/** +* @author: Thomas Brandého +*/ + +#ifndef INPUT_H +#define INPUT_H +#include "keybindings.h" +#include +#include +#include +#include "textbuffer.h" + +class Input{ + public: + /* Constructors */ + Input(sf::Window *w); + + /* general action-mapping functions */ + void setKeysMap(IKeysMap km); + void updateEvents(); + int getAction(); + + /* context-related functions */ + void addContext(Context context); + void setCurrentContext(std::string context_name); + void updateKeyBindings(); + + /* window-related function */ + bool isCloseRequested() const; + bool isResized() const; + + /* keyboard-related functions */ + bool isKeyPressed(int key) const; + + /* mouse-related function */ + sf::Vector2i getPosition() const; + sf::Vector2i getDeltaPosition() const; + float getDeltaVerticalScroll() const; + + /* text-related function */ + std::string getText(); + + void test(); + + private: + /* window-related variables */ + sf::Window* window; + bool closeRequested; + bool hasBeenResized; + + /* general action-mapping variables */ + IKeysMap keysmap; + std::queue action_file; + int nb_actions; + + /* context-related variables */ + std::string current_context; + //std::unordered_map> contexts; + std::vector contexts; + std::unordered_map keybindings; + + /* keyboard-related variables */ + std::vector heldkeys; + void releaseHeldKeys(sf::Keyboard::Key keycode); + + /* mouse-related variables */ + sf::Vector2i mouse_position; + sf::Vector2i last_mouse_position; + float delta_vertical_scroll; + + /* text-related variable */ + std::string buffer; +}; + +#endif //INPUT_H diff --git a/keybindings.cpp b/src/keybindings.cpp similarity index 95% rename from keybindings.cpp rename to src/keybindings.cpp index 69c8b05..5178c45 100644 --- a/keybindings.cpp +++ b/src/keybindings.cpp @@ -1,107 +1,107 @@ -/** -* @author: Thomas Brandého -*/ - -#include "keybindings.h" -#include - -/* Implementation of IKeysMap class - * @author: Thomas Brandého - * @info: This class register all the association between key and action. - */ - -IKeysMap::IKeysMap() -{ - -} - -std::vector IKeysMap::getBindings(int action) const { - std::vector bindings; - for (auto binding : keys) - if (binding.action == action) bindings.push_back(binding); - return bindings; -} - -/* Implementation of KeyBindings class - * @author: Thomas Brandého - * @info: This class map a list of action with the associated keys, for a quick access in-game. - * The map is read-only, so if you want to add of remove action from the map, you have to create a new instance of KeyBindings - */ - -KeyBindings::KeyBindings() -{ -} -KeyBindings::KeyBindings(const Context &context, const IKeysMap &keysmap) -{ - std::vector actions = context.getActions(); - for (int action : actions){ - for (Binding binding : keysmap.getBindings(action)){ - switch(binding.type){ - case IKeysMap::PRESSED: - setPressedAction(binding.key,binding.action); - break; - case IKeysMap::RELEASED: - setReleasedAction(binding.key,binding.action); - break; - case IKeysMap::HOLD: - setHoldAction(binding.key,binding.action); - break; - default: - //raiseError; - break; - } - } - } -} - -int KeyBindings::getPressedAction(int key) const -{ - return bindings_pressed.count(key) == 1? bindings_pressed.at(key) : -1; -} -int KeyBindings::getReleasedAction(int key) const -{ - return bindings_released.count(key) == 1? bindings_released.at(key) : -1; -} -int KeyBindings::getHoldAction(int key) const -{ - return bindings_hold.count(key) == 1? bindings_hold.at(key) : -1; -} - -void KeyBindings::setPressedAction(int key, int action) -{ - bindings_pressed[key]=action; -} -void KeyBindings::setReleasedAction(int key, int action) -{ - bindings_released[key]=action; -} - -void KeyBindings::setHoldAction(int key, int action) -{ - bindings_hold[key]=action; -} - -/* Implementation of Context class - * @author: Thomas Brandého - * @info: This class contains a list of actions available in a given situation (context). - */ - -/* Implementation of Context class - * @author: Thomas Brandého - * @info: This class contains a list of action associated to a given situation (context). - */ - - -Context::Context(std::string _name, std::vector _actions): name(_name), actions(_actions) -{ - -} - -std::string Context::getName() -{ - return name; -} -std::vector Context::getActions() const -{ - return actions; -} +/** +* @author: Thomas Brandého +*/ + +#include "keybindings.h" +#include + +/* Implementation of IKeysMap class + * @author: Thomas Brandého + * @info: This class register all the association between key and action. + */ + +IKeysMap::IKeysMap() +{ + +} + +std::vector IKeysMap::getBindings(int action) const { + std::vector bindings; + for (auto binding : keys) + if (binding.action == action) bindings.push_back(binding); + return bindings; +} + +/* Implementation of KeyBindings class + * @author: Thomas Brandého + * @info: This class map a list of action with the associated keys, for a quick access in-game. + * The map is read-only, so if you want to add of remove action from the map, you have to create a new instance of KeyBindings + */ + +KeyBindings::KeyBindings() +{ +} +KeyBindings::KeyBindings(const Context &context, const IKeysMap &keysmap) +{ + std::vector actions = context.getActions(); + for (int action : actions){ + for (Binding binding : keysmap.getBindings(action)){ + switch(binding.type){ + case IKeysMap::PRESSED: + setPressedAction(binding.key,binding.action); + break; + case IKeysMap::RELEASED: + setReleasedAction(binding.key,binding.action); + break; + case IKeysMap::HOLD: + setHoldAction(binding.key,binding.action); + break; + default: + //raiseError; + break; + } + } + } +} + +int KeyBindings::getPressedAction(int key) const +{ + return bindings_pressed.count(key) == 1? bindings_pressed.at(key) : -1; +} +int KeyBindings::getReleasedAction(int key) const +{ + return bindings_released.count(key) == 1? bindings_released.at(key) : -1; +} +int KeyBindings::getHoldAction(int key) const +{ + return bindings_hold.count(key) == 1? bindings_hold.at(key) : -1; +} + +void KeyBindings::setPressedAction(int key, int action) +{ + bindings_pressed[key]=action; +} +void KeyBindings::setReleasedAction(int key, int action) +{ + bindings_released[key]=action; +} + +void KeyBindings::setHoldAction(int key, int action) +{ + bindings_hold[key]=action; +} + +/* Implementation of Context class + * @author: Thomas Brandého + * @info: This class contains a list of actions available in a given situation (context). + */ + +/* Implementation of Context class + * @author: Thomas Brandého + * @info: This class contains a list of action associated to a given situation (context). + */ + + +Context::Context(std::string _name, std::vector _actions): name(_name), actions(_actions) +{ + +} + +std::string Context::getName() +{ + return name; +} +std::vector Context::getActions() const +{ + return actions; +} diff --git a/keybindings.h b/src/keybindings.h similarity index 95% rename from keybindings.h rename to src/keybindings.h index d202f1a..03e0e80 100644 --- a/keybindings.h +++ b/src/keybindings.h @@ -1,57 +1,57 @@ -/** -* @author: Thomas Brandého -*/ - -#ifndef KEYBINDINGS_H -#define KEYBINDINGS_H - -#include - -#include - -#define NO_KEY -1 -#define NO_ACTION -1 - -typedef struct{ - int action; - int key; - int type; -} Binding; - -class IKeysMap{ -public: - enum {PRESSED, RELEASED, HOLD}; - IKeysMap(); - std::vector getBindings(int action) const; -protected: - std::vector keys; -}; - -class Context { - public: - Context(std::string name, std::vector actions); - std::string getName(); - std::vector getActions() const; - private: - std::string name; - std::vector actions; -}; - -class KeyBindings { - public: - KeyBindings(); - KeyBindings(const Context &context, const IKeysMap &keysmap); - int getPressedAction(int key) const; - int getReleasedAction(int key) const; - int getHoldAction(int key) const; - - private: - std::unordered_map bindings_pressed; - std::unordered_map bindings_released; - std::unordered_map bindings_hold; - void setPressedAction(int key, int action); - void setReleasedAction(int key, int action); - void setHoldAction(int key, int action); -}; - -#endif +/** +* @author: Thomas Brandého +*/ + +#ifndef KEYBINDINGS_H +#define KEYBINDINGS_H + +#include + +#include + +#define NO_KEY -1 +#define NO_ACTION -1 + +typedef struct{ + int action; + int key; + int type; +} Binding; + +class IKeysMap{ +public: + enum {PRESSED, RELEASED, HOLD}; + IKeysMap(); + std::vector getBindings(int action) const; +protected: + std::vector keys; +}; + +class Context { + public: + Context(std::string name, std::vector actions); + std::string getName(); + std::vector getActions() const; + private: + std::string name; + std::vector actions; +}; + +class KeyBindings { + public: + KeyBindings(); + KeyBindings(const Context &context, const IKeysMap &keysmap); + int getPressedAction(int key) const; + int getReleasedAction(int key) const; + int getHoldAction(int key) const; + + private: + std::unordered_map bindings_pressed; + std::unordered_map bindings_released; + std::unordered_map bindings_hold; + void setPressedAction(int key, int action); + void setReleasedAction(int key, int action); + void setHoldAction(int key, int action); +}; + +#endif diff --git a/main.cpp b/src/main.cpp similarity index 100% rename from main.cpp rename to src/main.cpp diff --git a/textbuffer.cpp b/src/textbuffer.cpp similarity index 100% rename from textbuffer.cpp rename to src/textbuffer.cpp diff --git a/textbuffer.h b/src/textbuffer.h similarity index 100% rename from textbuffer.h rename to src/textbuffer.h diff --git a/template.cmake b/template.cmake new file mode 100644 index 0000000..f9ac78c --- /dev/null +++ b/template.cmake @@ -0,0 +1,216 @@ +# Variable that you need to define to use this template +# USE_SFML, USE_RENDERER, USE_INPUT, USE_BULLET, USE_OPENGL, USE_QT5 +# +# Container for list of file to be compiled : +# LIB_SRC_LIST, LIB_HEAD_LIST, EXEC_SRC_LIST, EXEC_HEAD_LIST +# +# If you want to specify a supplementary folder for include, use : +# EXTRA_INCLUDE_PATHS + +cmake_minimum_required(VERSION 2.8) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +#detect system and version +if(WIN32) + set(LIB_DEBUG_FOLDER "libDebug/mingw32") + set(LIB_RELEASE_FOLDER "libRelease/mingw32") +elseif(UNIX) + if(${CMAKE_SYSTEM_VERSION} MATCHES "i686") + set(LIB_DEBUG_FOLDER "libDebug/i686") + set(LIB_RELEASE_FOLDER "libRelease/i686") + elseif(${CMAKE_SYSTEM_VERSION} MATCHES "x86_64") + set(LIB_DEBUG_FOLDER "libDebug/x86_64") + set(LIB_RELEASE_FOLDER "libRelease/x86_64") + endif() +endif() + +#set dependencies paths +set(DEPENDENCIES_ROOT ${PROJECT_SOURCE_DIR}/../cpp_dependencies) +set(INCLUDE_ROOT ${DEPENDENCIES_ROOT}/include) + +set(LIB_DEBUG_PATH ${DEPENDENCIES_ROOT}/${LIB_DEBUG_FOLDER}) +set(LIB_RELEASE_PATH ${DEPENDENCIES_ROOT}/${LIB_RELEASE_FOLDER}) + +if(${CMAKE_BUILD_TYPE} MATCHES "Debug") + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_DEBUG_PATH}) #for STATIC + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_DEBUG_PATH}) #for SHARED + + list(APPEND LIB_PATHS ${LIB_DEBUG_PATH}) + list(APPEND LIB_PATHS "\n" ${LIB_RELEASE_PATH}) +else() + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_RELEASE_PATH}) #for STATIC + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_RELEASE_PATH}) #for SHARED + + list(APPEND LIB_PATHS ${LIB_RELEASE_PATH}) +endif() + +#create library and executable +if(LIB_SRC_LIST) + set(IS_LIBRARY True) + set(LIBRARY_NAME ${PROJECT_NAME}) + add_library(${LIBRARY_NAME} STATIC ${LIB_SRC_LIST} ${RESOURCES_FILES}) + if(EXEC_SRC_LIST) + set(EXECUTABLE_NAME "test${PROJECT_NAME}") + add_executable(${EXECUTABLE_NAME} ${EXEC_SRC_LIST} ${RESOURCES_FILES}) + endif() +elseif(EXEC_SRC_LIST) + set(EXECUTABLE_NAME "${PROJECT_NAME}") + add_executable(${EXECUTABLE_NAME} ${EXEC_SRC_LIST} ${RESOURCES_FILES}) +else() + message(WARNING "NO SOURCE FILE PROVIDED") +endif() + + +add_definitions(-std=c++11) + +#find libraries +set(LIB_DEPENDENCIES_LIST "") +set(INCLUDE_PATHS ${INCLUDE_ROOT}) + +# not used for now +# foreach(EXTENSION ${INCLUDE_PATHS_EXTENSION}) +# LIST(APPEND INCLUDE_PATHS ${INCLUDE_ROOT}${EXTENSION} " ") +# endforeach() + +# TODO: Complete SFML +if(USE_SFML) + find_library(SFML_LIBRARY_WINDOW + NAMES + sfml-window + PATHS + ${LIB_PATHS} + ) + + find_library(SFML_LIBRARY_SYSTEM + NAMES + sfml-system + PATHS + ${LIB_PATHS} + ) + + find_library(SFML_LIBRARY_AUDIO + NAMES + sfml-audio + PATHS + ${LIB_PATHS} + ) + + find_library(SFML_LIBRARY_GRAPHICS + NAMES + sfml-graphics + PATHS + ${LIB_PATHS} + ) + + add_definitions(-DSFML_STATIC) + LIST(APPEND LIB_DEPENDENCIES_LIST ${SFML_LIBRARY_AUDIO} ${SFML_LIBRARY_GRAPHICS} ${SFML_LIBRARY_WINDOW} ${SFML_LIBRARY_SYSTEM}) +endif() + +if(USE_RENDERER) + find_library(SPARROW_RENDERER_LIBRARY + NAMES + SparrowRenderer + PATHS + ${LIB_PATHS} + ) + LIST(APPEND INCLUDE_PATHS "\n" ${PROJECT_SOURCE_DIR}/../sparrowrenderer/src) + LIST(APPEND LIB_DEPENDENCIES_LIST ${SPARROW_RENDERER_LIBRARY}) +endif() + +if(USE_INPUT) + find_library(SPARROW_INPUT_LIBRARY + NAMES + SparrowInput + PATHS + ${LIB_PATHS} + ) + LIST(APPEND INCLUDE_PATHS "\n" ${PROJECT_SOURCE_DIR}/../sparrowinput/src) + LIST(APPEND LIB_DEPENDENCIES_LIST ${SPARROW_INPUT_LIBRARY}) +endif() + +if(USE_BULLET) + find_library(BULLET_COLLISION_LIBRARY + NAMES + BulletCollision + PATHS + ${LIB_PATHS} + ) + + find_library(BULLET_DYNAMICS_LIBRARY + NAMES + BulletDynamics + PATHS + ${LIB_PATHS} + ) + + find_library(LINEAR_MATH_LIBRARY + NAMES + LinearMath + PATHS + ${LIB_PATHS} + ) + LIST(APPEND LIB_DEPENDENCIES_LIST ${BULLET_COLLISION_LIBRARY} ${BULLET_DYNAMICS_LIBRARY} ${LINEAR_MATH_LIBRARY}) + LIST(APPEND INCLUDE_PATHS "\n" ${INCLUDE_ROOT}/bullet) +endif() + +if(USE_OPENGL) + find_package(OpenGL REQUIRED) + if(OPENGL_FOUND) + LIST(APPEND LIB_DEPENDENCIES_LIST ${OPENGL_LIBRARIES}) + endif() +endif() + +# TODO: Complete QT5 +if(USE_QT5) + if(${QT_MODULE} MATCHES "core") + + endif() + if(${QT_MODULE} MATCHES "gui") + + endif() + if(${QT_MODULE} MATCHES "opengl") + find_package(Qt5OpenGL REQUIRED) + if(QT5OPENGL_FOUND) + LIST(APPEND LIB_DEPENDENCIES_LIST ${Qt5OpenGL_LIBRARIES}) + add_definitions(${Qt5OpenGL_DEFINITIONS}) + LIST(APPEND INCLUDE_PATHS "\n" ${Qt5OpenGL_INCLUDES}) + endif() + endif() + if(${QT_MODULE} MATCHES "widgets") + find_package(Qt5Widgets REQUIRED) + if(QT5WIDGETS_FOUND) + LIST(APPEND LIB_DEPENDENCIES_LIST ${Qt5Widgets_LIBRARIES}) + add_definitions(${Qt5Widgets_DEFINITIONS}) + LIST(APPEND INCLUDE_PATHS "\n" ${Qt5Widgets_INCLUDES}) + endif() + endif() + if(${QT_MODULE} MATCHES "network") + + endif() +endif() + +include_directories( + ${INCLUDE_PATHS} + ${EXTRA_INCLUDE} +) + +if(LIB_SRC_LIST) + target_link_libraries( + ${LIBRARY_NAME} + ${LIB_DEPENDENCIES_LIST} + ) + if(EXEC_SRC_LIST) + target_link_libraries( + ${EXECUTABLE_NAME} + ${LIBRARY_NAME} + ) + endif() +elseif(EXEC_SRC_LIST) + target_link_libraries( + ${EXECUTABLE_NAME} + ${LIB_DEPENDENCIES_LIST} + ) +endif()