From b772b91e6ec1dc3d3d472f450967cc2201bc75ee Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Fri, 18 Jul 2025 09:34:41 +0200 Subject: [PATCH] fixes for build on windows --- client/main.cpp | 2 ++ server/gpio/gpio.cpp | 16 +++++++++++----- server/gpio/gpio.hpp | 4 +++- server/simulator_base.hpp | 3 ++- tests/CMakeLists.txt | 7 +++++-- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/client/main.cpp b/client/main.cpp index 01f3c6e..de0951d 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -63,6 +63,7 @@ int main(int argc, char *argv[]) url.setHost(QString::fromStdString(location["href"].as())); #else url.setHost(parser.value(host_option)); +#if defined(__linux__) if (parser.value(host_option).endsWith(".local")) { QProcess p; @@ -85,6 +86,7 @@ int main(int argc, char *argv[]) ret[1].removeLast(); url.setHost(ret[1]); } +#endif #endif url.setPort(parser.value(port_option).toInt()); QString default_sim = parser.value(default_sim_option); diff --git a/server/gpio/gpio.cpp b/server/gpio/gpio.cpp index 45ecf34..b483599 100644 --- a/server/gpio/gpio.cpp +++ b/server/gpio/gpio.cpp @@ -1,9 +1,6 @@ #include "gpio.hpp" #include "spdlog/spdlog.h" #include -#if __aarch64__ -#else -#endif GPIO::GPIO(QObject *parent) : QObject(parent), m_offset(0) { @@ -11,13 +8,16 @@ GPIO::GPIO(QObject *parent) : QObject(parent), m_offset(0) GPIO::~GPIO() { +#if defined(__linux__) && (defined(__aarch64__) || defined(__x86_64__)) if (!m_request.get()) return; m_request->release(); +#endif } void GPIO::configure_pin(Direction dir, uint8_t gpio) { + #if defined(__linux__) && (defined(__aarch64__) || defined(__x86_64__)) if (m_request.get() != nullptr) return; std::filesystem::path chip_path("/dev/gpiochip0"); @@ -56,19 +56,25 @@ void GPIO::configure_pin(Direction dir, uint8_t gpio) SPDLOG_CRITICAL("Could not set gpio {} as input, run binary as root", gpio); } } +#else + Q_UNUSED(dir); + Q_UNUSED(gpio); +#endif } void GPIO::set_value(bool value) { -#if defined(__aarch64__) || defined(__x86_64__) +#if defined(__linux__) && (defined(__aarch64__) || defined(__x86_64__)) if (!m_request.get()) return; m_request->set_value(m_offset, (gpiod::line::value)value); +#else + Q_UNUSED(value); #endif } bool GPIO::value() { -#if defined(__aarch64__) || defined(__x86_64__) +#if defined(__linux__) && (defined(__aarch64__) || defined(__x86_64__)) if (!m_request.get()) return false; return (bool)m_request->get_value(m_offset); diff --git a/server/gpio/gpio.hpp b/server/gpio/gpio.hpp index 2abfbc3..dca8956 100644 --- a/server/gpio/gpio.hpp +++ b/server/gpio/gpio.hpp @@ -2,7 +2,7 @@ #define GPIO_HPP #include -#if defined(__aarch64__) || defined(__x86_64__) +#if defined(__linux__) && (defined(__aarch64__) || defined(__x86_64__)) #include #else @@ -24,7 +24,9 @@ class GPIO : public QObject bool value(); private: +#if defined(__linux__) && (defined(__aarch64__) || defined(__x86_64__)) std::unique_ptr m_request; +#endif unsigned int m_offset; }; diff --git a/server/simulator_base.hpp b/server/simulator_base.hpp index bc29e68..a739157 100644 --- a/server/simulator_base.hpp +++ b/server/simulator_base.hpp @@ -14,8 +14,9 @@ return new sim(com, parent); \ } -struct Communication +class Communication { + public: CAN_Wrapper *c_if1 = nullptr; CAN_Wrapper *c_if2 = nullptr; QSerialPort *s_if1 = nullptr; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2be2265..b22b091 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,5 @@ # Third Party -find_package(GTest REQUIRED) +find_package(GTest) find_package(Qt6 REQUIRED COMPONENTS Core) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) @@ -7,7 +7,9 @@ set(CMAKE_AUTORCC ON) # tests file(GLOB_RECURSE TEST_SOURCES "*.[hc]pp") -add_executable(tests ${TEST_SOURCES}) +file(GLOB_RECURSE CAN "../server/CAN/to_id.cpp") +if (GTest_FOUND) +add_executable(tests ${TEST_SOURCES} ${CAN}) target_compile_options(tests PRIVATE $<$: -Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion @@ -31,3 +33,4 @@ target_include_directories(tests include(GoogleTest) gtest_discover_tests(tests) +endif()