From 21300a602474497711056a5b0cfaab61ed6fa6fb Mon Sep 17 00:00:00 2001
From: "leire.querejeta" <leire.querejeta@tecnalia.com>
Date: Mon, 17 Oct 2022 09:22:15 +0200
Subject: [PATCH] included python wrappers generation

---
 README.md                                |  2 +
 serial_port_class_api/CMakeLists.txt     | 27 +++++++++-
 serial_port_class_api/README.md          | 52 ++++++++++++++++---
 serial_port_class_api/src/CMakeLists.txt | 63 +++++++++++++++++++-----
 serial_port_class_api/src/main.cpp       |  6 ---
 5 files changed, 125 insertions(+), 25 deletions(-)

diff --git a/README.md b/README.md
index c64c891..87650fa 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,7 @@ For building this project in both Windows and Linux the following tools must be
 - [cmake](https://cmake.org/download/): Download .msi file and execute it.
 - [swig](http://www.swig.org/survey.html): Download the .zip and unzip it. Include the folder into `path` environemnt variable.
 - [doxygen](https://www.doxygen.nl/download.html): Download .exe file and execute it.
+- [python 3.7.9](https://www.python.org/downloads/release/python-379/): Download .msi file and execute it.
 
 ## Linux
 ```
@@ -21,6 +22,7 @@ sudo snap install cmake --classic
 sudo apt-get install swig 
 sudo apt-get install doxygen
 sudo apt install graphviz
+sudo apt-get install python3.7
 ```
 
 # Build project
diff --git a/serial_port_class_api/CMakeLists.txt b/serial_port_class_api/CMakeLists.txt
index b102bab..e6263a2 100644
--- a/serial_port_class_api/CMakeLists.txt
+++ b/serial_port_class_api/CMakeLists.txt
@@ -3,11 +3,13 @@ cmake_minimum_required(VERSION 3.14)
 project(class_api)
 
 add_subdirectory(src)
+add_subdirectory(libreria_LQL)
 
 find_package(SWIG REQUIRED)
 include(${SWIG_USE_FILE})
 
 set(NET_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/csharpwrapper")
+set(PYTHON_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/pythonwrapper")
 
 set(CMAKE_SWIG_FLAGS "")
 
@@ -15,12 +17,12 @@ set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i PROP
 
 swig_add_library(CLASS_SerialPort
   TYPE SHARED
-  LANGUAGE CSharp
+  LANGUAGE csharp
   SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i
   OUTPUT_DIR ${NET_PROJECT_DIR} 
   OUTFILE_DIR ${NET_PROJECT_DIR} 
   )
-  swig_link_libraries(CLASS_SerialPort class_serial_port)
+swig_link_libraries(CLASS_SerialPort class_serial_port)
 
 set_target_properties(CLASS_SerialPort
     PROPERTIES
@@ -30,6 +32,27 @@ set_target_properties(CLASS_SerialPort
     INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}
     )
 
+find_package(PythonInterp)
+find_package(PythonLibs REQUIRED)
+
+include_directories(${PYTHON_INCLUDE_DIRS})
+include_directories(${PYTHON_INCLUDE_PATH})
+
+swig_add_library(CLASS_SerialPortPython 
+    TYPE SHARED 
+    LANGUAGE python 
+    SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i 
+    OUTPUT_DIR ${PYTHON_PROJECT_DIR} 
+    OUTFILE_DIR ${PYTHON_PROJECT_DIR})
+
+swig_link_libraries(CLASS_SerialPortPython class_serial_port ${PYTHON_LIBRARIES})
+set_target_properties(CLASS_SerialPortPython 
+    PROPERTIES SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE
+    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PYTHON_PROJECT_DIR}
+    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PYTHON_PROJECT_DIR}
+    LIBRARY_OUTPUT_DIRECTORY ${PYTHON_PROJECT_DIR})
+
+
 option(BUILD_DOC "Build documentation" ON)
 message(STATUS "Build documentation: ${BUILD_DOC}")
 if (BUILD_DOC)
diff --git a/serial_port_class_api/README.md b/serial_port_class_api/README.md
index a3e4b9d..87650fa 100644
--- a/serial_port_class_api/README.md
+++ b/serial_port_class_api/README.md
@@ -1,7 +1,47 @@
-# Project structure
-Project is structured with the following folders:
-  * docs : documentation is automatically produced from comments by doxygen once a built is done, it will be found in docs/documentation/index.html.
-  * include : it contains header files for the API.
-  * src : contains API functions in CLASS_SerialPort.cpp and main.cpp file as example of how to use those funtions. 
-  * wrappers : wrappers are automatically produced by swig. It generates files to be used in C# scripts.
+This repo contains the source code to communicate with CLASS device through serial port.
 
+For building this project in both Windows and Linux the following tools must be installed:
+
+- Building tools
+- cmake: for building the project
+- swig: for the generation of wrappers
+- doxygen: for the generation of the documentation
+- graphviz: required by doxygen
+
+## Windows
+- [this](https://aka.ms/vs/15/release/vs_buildtools.exe) Build tools for Visual Studio (2017), needed for compiling C++.
+- [cmake](https://cmake.org/download/): Download .msi file and execute it.
+- [swig](http://www.swig.org/survey.html): Download the .zip and unzip it. Include the folder into `path` environemnt variable.
+- [doxygen](https://www.doxygen.nl/download.html): Download .exe file and execute it.
+- [python 3.7.9](https://www.python.org/downloads/release/python-379/): Download .msi file and execute it.
+
+## Linux
+```
+sudo apt-get install build-essential
+sudo snap install cmake --classic
+sudo apt-get install swig 
+sudo apt-get install doxygen
+sudo apt install graphviz
+sudo apt-get install python3.7
+```
+
+# Build project
+This code has been programmed in C++. Wrappers for C# are generated automatically by swig.
+## C++ building with CMake
+* Create a build folder and enter the folder
+* Execute the following commands to configure the platform
+
+
+  -Windows 
+
+
+  cmake -G "Visual Studio 15 2017 Win64" CMAKE_BUILD_TYPE=Release ../
+
+  cmake --build . --target ALL_BUILD --config Release
+  
+
+  -Linux
+  
+  cmake ../
+
+  make
diff --git a/serial_port_class_api/src/CMakeLists.txt b/serial_port_class_api/src/CMakeLists.txt
index 4e2d415..e6263a2 100644
--- a/serial_port_class_api/src/CMakeLists.txt
+++ b/serial_port_class_api/src/CMakeLists.txt
@@ -1,19 +1,60 @@
-
 cmake_minimum_required(VERSION 3.14)
-project (class_serial_port VERSION 0.1.0)
 
-add_executable(class_api_exe
-               CLASS_SerialPort.cpp
-               main.cpp)
+project(class_api)
+
+add_subdirectory(src)
+add_subdirectory(libreria_LQL)
+
+find_package(SWIG REQUIRED)
+include(${SWIG_USE_FILE})
+
+set(NET_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/csharpwrapper")
+set(PYTHON_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wrappers/pythonwrapper")
+
+set(CMAKE_SWIG_FLAGS "")
+
+set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i PROPERTY CPLUSPLUS ON)
+
+swig_add_library(CLASS_SerialPort
+  TYPE SHARED
+  LANGUAGE csharp
+  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i
+  OUTPUT_DIR ${NET_PROJECT_DIR} 
+  OUTFILE_DIR ${NET_PROJECT_DIR} 
+  )
+swig_link_libraries(CLASS_SerialPort class_serial_port)
+
+set_target_properties(CLASS_SerialPort
+    PROPERTIES
+    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${NET_PROJECT_DIR}
+    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${NET_PROJECT_DIR}
+    LIBRARY_OUTPUT_DIRECTORY ${NET_PROJECT_DIR}
+    INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}
+    )
 
-target_link_libraries(class_api_exe ${CMAKE_CURRENT_SOURCE_DIR}/../commands.lib)
+find_package(PythonInterp)
+find_package(PythonLibs REQUIRED)
 
+include_directories(${PYTHON_INCLUDE_DIRS})
+include_directories(${PYTHON_INCLUDE_PATH})
 
-set(class_files_local ${CMAKE_CURRENT_SOURCE_DIR}/CLASS_SerialPort.cpp)
+swig_add_library(CLASS_SerialPortPython 
+    TYPE SHARED 
+    LANGUAGE python 
+    SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/CLASS_SerialPort.i 
+    OUTPUT_DIR ${PYTHON_PROJECT_DIR} 
+    OUTFILE_DIR ${PYTHON_PROJECT_DIR})
 
-set(class_files ${class_files_local} PARENT_SCOPE)
+swig_link_libraries(CLASS_SerialPortPython class_serial_port ${PYTHON_LIBRARIES})
+set_target_properties(CLASS_SerialPortPython 
+    PROPERTIES SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE
+    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PYTHON_PROJECT_DIR}
+    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PYTHON_PROJECT_DIR}
+    LIBRARY_OUTPUT_DIRECTORY ${PYTHON_PROJECT_DIR})
 
-add_library(class_serial_port ${class_files_local})
 
-target_link_libraries(class_serial_port ${CMAKE_CURRENT_SOURCE_DIR}/../commands.lib)
-set_target_properties(class_serial_port PROPERTIES FOLDER class)
+option(BUILD_DOC "Build documentation" ON)
+message(STATUS "Build documentation: ${BUILD_DOC}")
+if (BUILD_DOC)
+    add_subdirectory(docs)
+endif()
\ No newline at end of file
diff --git a/serial_port_class_api/src/main.cpp b/serial_port_class_api/src/main.cpp
index 83ae980..a477975 100644
--- a/serial_port_class_api/src/main.cpp
+++ b/serial_port_class_api/src/main.cpp
@@ -26,12 +26,6 @@ int main(void)
 
     cout << "Port Status :";
     cout << port_status <<endl;
-
-
-
-
-
-
  
     if(port_status == 1)
     {
-- 
GitLab