-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Panduza/develop
Release v0.1.0
- Loading branch information
Showing
62 changed files
with
3,087 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Build and test | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.9' | ||
|
||
- name: Conan installation | ||
id: conan | ||
uses: turtlebrowser/get-conan@v1.2 | ||
|
||
- name: Install platform deps | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y mosquitto mosquitto-clients | ||
sudo mosquitto -d -c /etc/mosquitto/mosquitto.conf | ||
echo "loguru paho-mqtt pyserial pyudev pymodbus" | xargs -n1 > requirements.txt | ||
pip install -r requirements.txt | ||
- name: Fetch platform | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: 'Panduza/panduza-py' | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
path: panduza-py | ||
ref: 28-remonter-de-la-consommation-courante-hm310t | ||
|
||
- name: Run platform | ||
run: | | ||
sudo mkdir -p /etc/panduza/log | ||
sudo chown -R $(whoami):$(whoami) /etc/panduza | ||
cd panduza-py | ||
pip install -e ./platform | ||
nohup python3 platform/deploy/pza-py-platform-run.py ../test/tree.json & | ||
- name: Build Debug and Test | ||
run: | | ||
rm -rf build | ||
./scripts/build.sh | ||
cd build | ||
make test | ||
- name: Build Release and Test | ||
run: | | ||
rm -rf build | ||
./scripts/build.sh Release | ||
cd build | ||
make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
build* | ||
examples/build* | ||
examples/CMakeUserPresets.json | ||
CMakeUserPresets.json | ||
.vscode | ||
Testing | ||
conan_imports_manifest.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
cmake_minimum_required(VERSION 3.25) | ||
|
||
project(PZACXX VERSION 0.1.0) | ||
set(LIBRARY_NAME pza-cxx) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
include(cmake/cppcheck.cmake) | ||
|
||
add_compile_options(-Wall -Wextra) | ||
|
||
set(SPDLOG_FMT_EXTERNAL 1) | ||
find_package(spdlog REQUIRED) | ||
find_package(nlohmann_json REQUIRED) | ||
find_package(PahoMqttCpp REQUIRED) | ||
find_package(magic_enum REQUIRED) | ||
|
||
if (CMAKE_SYSTEM_NAME MATCHES "Linux") | ||
find_package(GTest REQUIRED) | ||
find_package(cppcheck REQUIRED) | ||
endif() | ||
|
||
if (CMAKE_SYSTEM_NAME MATCHES "Windows") | ||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--allow-multiple-definition") | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-multiple-definition") | ||
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT BUILD_SHARED_LIBS) | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-multiple-definition") | ||
endif() | ||
|
||
if (CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT BUILD_SHARED_LIBS) | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") | ||
endif() | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
add_library(${LIBRARY_NAME}) | ||
|
||
add_subdirectory(source) | ||
#add_subdirectory(test) | ||
|
||
option(BUILD_EXAMPLES "Build examples" OFF) | ||
if(BUILD_EXAMPLES) | ||
add_subdirectory(examples) | ||
endif() | ||
|
||
target_include_directories(${LIBRARY_NAME} PUBLIC | ||
${CMAKE_CURRENT_LIST_DIR} | ||
${CMAKE_BINARY_DIR} | ||
) | ||
|
||
target_link_libraries(${LIBRARY_NAME} | ||
$<$<BOOL:${BUILD_SHARED_LIBS}>:PahoMqttCpp::paho-mqttpp3> | ||
$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:PahoMqttCpp::paho-mqttpp3-static> | ||
spdlog::spdlog | ||
nlohmann_json::nlohmann_json | ||
magic_enum::magic_enum | ||
) | ||
|
||
if (CMAKE_SYSTEM_NAME MATCHES "Windows" AND BUILD_SHARED_LIBS) | ||
message(STATUS "Copying DLLs from ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin to ${CMAKE_BINARY_DIR}/bin") | ||
add_custom_command(TARGET ${LIBRARY_NAME} POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin/*.dll | ||
$<TARGET_FILE_DIR:${LIBRARY_NAME}> | ||
) | ||
endif() | ||
|
||
set_target_properties(${LIBRARY_NAME} PROPERTIES | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION ${PROJECT_VERSION_MAJOR} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2023 Panduza | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Panduza C++ Library | ||
|
||
User library to develop C++ applications following Panduza API. | ||
|
||
## Dependencies | ||
|
||
### Build Deps | ||
|
||
| Package | Version | | ||
| ------- | -------- | | ||
| GCC | 13 | | ||
| conan | 1.60 | | ||
| cmake | >=3.25.0 | | ||
|
||
Library dependencies are managed wih Conan. | ||
|
||
To install conan, https://conan.io/downloads.html. | ||
|
||
### Library Deps | ||
|
||
| Package | Version | Runtime | | ||
| ------------- | ------------ | -------- | | ||
| paho-mqtt-cpp | 1.2.0 | ✔ | | ||
| nlohmann JSON | 3.11.2 | ✔ | | ||
| spdlog | 1.11.0 | ✔ | | ||
| Google test | cci.20210126 | | | ||
| cppcheck | 2.10 | | | ||
|
||
## Build | ||
|
||
``` | ||
./scripts/install_dependencies.sh | ||
./scripts/build.sh | ||
``` | ||
|
||
``` | ||
$ ./scripts/install_dependencies.sh --help | ||
Usage: ./scripts/install_dependencies.sh [-t <target>] [-l <lib>] [-b <build>] [-h] | ||
-t --target Target platform (Windows or Linux). Default is Linux | ||
-l --lib Library mode (Static or Shared). Default is Shared | ||
-b --build Build mode (Debug or Release). Default is Debug | ||
-h --help Display this help message | ||
``` | ||
``` | ||
$ ./scripts/build.sh --help | ||
Usage: ./scripts/build.sh [-t <target>] [-l <lib>] [-b <build>] [-h] | ||
-t --target Target platform (Windows or Linux). Default is Linux | ||
-l --lib Library mode (Static or Shared). Default is Shared | ||
-b --build Build mode (Debug or Release). Default is Debug | ||
-h --help Display this help message | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
if (CMAKE_SYSTEM_NAME MATCHES "Linux") | ||
find_program(CPPCHECK_EXECUTABLE cppcheck) | ||
if(CPPCHECK_EXECUTABLE) | ||
add_custom_target(check | ||
${CPPCHECK_EXECUTABLE} --enable=all --suppress=missingIncludeSystem --suppress=unusedFunction | ||
--template "{file}:{line}:{severity}:{id}:{message}" | ||
-I ${CMAKE_SOURCE_DIR}/source | ||
${CMAKE_SOURCE_DIR}/source | ||
COMMENT "Running Cppcheck static analysis tool" | ||
) | ||
else() | ||
message(WARNING "Cppcheck not found, can't run static analysis") | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
set(CMAKE_DEBUG_POSTFIX -debug) | ||
set_target_properties(${LIBRARY_NAME} | ||
PROPERTIES | ||
VERSION "${LIBRARY_VERSION}" | ||
SOVERSION "${LIBRARY_VERSION_MAJOR}" | ||
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
target_host=x86_64-w64-mingw32 | ||
|
||
[env] | ||
CHOST=$target_host | ||
AR=$target_host-ar | ||
AS=$target_host-as | ||
RANLIB=$target_host-ranlib | ||
CC=$target_host-gcc | ||
CXX=$target_host-g++ | ||
STRIP=$target_host-strip | ||
RC=$target_host-windres | ||
|
||
[conf] | ||
tools.build:compiler_executables={"cpp": "$target_host-g++", "c": "$target_host-gcc"} | ||
|
||
# We are cross building to Windows | ||
[settings] | ||
os=Windows | ||
arch=x86_64 | ||
compiler=gcc | ||
compiler.version=13 | ||
compiler.libcxx=libstdc++11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[settings] | ||
os=Linux | ||
arch=x86_64 | ||
compiler=gcc | ||
compiler.version=13 | ||
compiler.libcxx=libstdc++11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from conans import ConanFile | ||
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout | ||
import os | ||
import re | ||
|
||
class PzaCxx(ConanFile): | ||
name = "libpza-cxx" | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = { | ||
"shared": [True, False], | ||
"build_examples": [True, False] | ||
} | ||
default_options = { | ||
"shared": True, | ||
"build_examples": True | ||
} | ||
generators = "CMakeDeps", "CMakeToolchain", "virtualrunenv" | ||
exports_sources = "CMakeLists.txt", "source/*", "version.h.in", "CHANGELOG.md", "test/*", "cmake/*", "examples/*", "LICENSE" | ||
|
||
def requirements(self): | ||
self.requires("paho-mqtt-cpp/[>=1.2.0]") | ||
self.requires("spdlog/[>=1.11.0]") | ||
self.requires("nlohmann_json/[>=3.11.2]") | ||
self.requires("magic_enum/[>=0.9.2]") | ||
if self.settings.os == "Linux": | ||
self.requires("gtest/cci.20210126") | ||
self.requires("cppcheck/[>=2.10]") | ||
|
||
def layout(self): | ||
cmake_layout(self, build_folder=os.getcwd()) | ||
|
||
def configure(self): | ||
self.options["*"].shared = self.options.shared | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["BUILD_EXAMPLES"] = self.options.build_examples | ||
tc.filename = "pzacxx_toolchain.cmake" | ||
tc.generate() | ||
deps = CMakeDeps(self) | ||
deps.generate() | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
def imports(self): | ||
if self.settings.os == "Windows" and self.options.shared: | ||
folder = f"{self.build_folder}/bin" | ||
self.copy("*.dll", dst=folder, src="bin") | ||
mingw_dlls = ["libgcc_s_seh-1.dll", "libwinpthread-1.dll", "libstdc++-6.dll"] | ||
mingw_dll_path = "/usr/x86_64-w64-mingw32/bin" | ||
for dll in mingw_dlls: | ||
self.copy(dll, dst=folder, src=mingw_dll_path) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
FROM archlinux:base-devel-20231001.0.182270 | ||
|
||
RUN echo -e "\n[multilib]\nInclude = /etc/pacman.d/mirrorlist" | sudo tee -a /etc/pacman.conf | ||
RUN pacman -Syu --noconfirm | ||
RUN pacman -Sy --noconfirm \ | ||
git \ | ||
ninja \ | ||
cmake \ | ||
python \ | ||
python-pip \ | ||
wget \ | ||
clang \ | ||
libunwind \ | ||
wine | ||
|
||
RUN python -m venv /opt/venv | ||
ENV PATH="/opt/venv/bin:$PATH" | ||
RUN pip install conan==1.60 | ||
RUN conan profile new default --detect | ||
RUN conan profile update settings.compiler.libcxx=libstdc++11 default | ||
|
||
RUN useradd -m mingw && echo "mingw:password" | chpasswd | ||
RUN echo "mingw ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/myuser | ||
USER mingw | ||
WORKDIR /home/mingw | ||
RUN git clone https://aur.archlinux.org/paru.git | ||
RUN cd paru && makepkg -si --noconfirm | ||
RUN paru -S --noconfirm mingw-w64-cmake mingw-w64-zstd mingw-w64-zlib | ||
|
||
USER root | ||
RUN ln -s /usr/x86_64-w64-mingw32/lib/librpcrt4.a /usr/x86_64-w64-mingw32/lib/libRpcRT4.a | ||
RUN userdel -r mingw | ||
WORKDIR / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
set(examples | ||
bps | ||
) | ||
|
||
foreach(example ${examples}) | ||
add_executable(${example} ${example}.cxx) | ||
set_target_properties(${example} PROPERTIES | ||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples/bin" | ||
) | ||
target_link_libraries(${example} ${LIBRARY_NAME}) | ||
if (CMAKE_SYSTEM_NAME MATCHES "Windows" AND BUILD_SHARED_LIBS) | ||
add_custom_command(TARGET ${example} POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different | ||
${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin/*.dll | ||
$<TARGET_FILE_DIR:${example}> | ||
) | ||
endif() | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Examples | ||
|
||
TBD |
Oops, something went wrong.