SimpleBLE
SimpleBLE copied to clipboard
Rewrite to allow GCC Compilation on Windows
Hello,
I'm using CMAKE to build your library and link it into my project. In Windows, if I use MSVC, it works fine. Out of curiosity, I tried to use G++ (mingw) on Windows and I encountered a few problems.
For some reason, these lines were being overridden by simpleble's CMAKE files, and it kept reverting back to an earlier C++ standard that doesn't have co-routine support. As a result, the winrt header files wouldn't compile.
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
I added this line which fixed the problem
target_compile_features(simpleble PUBLIC cxx_std_20)
Then some compilation errors started popping up, for example, I had to change this
GattDescriptor PeripheralBase::_fetch_descriptor(const BluetoothUUID& service_uuid, const BluetoothUUID& characteristic_uuid, const BluetoothUUID& descriptor_uuid);
To this
GattDescriptor _fetch_descriptor(const BluetoothUUID& service_uuid, const BluetoothUUID& characteristic_uuid, const BluetoothUUID& descriptor_uuid);
And I had to add const in a few places like this:
Here-->for (const auto& service_guid : service_data) {
std::string service_uuid = guid_to_uuid(service_guid);
data.service_data.emplace(std::make_pair(service_uuid, ByteArray()));
}
Then I encountered more problems because "roapi.h" was being included, and there are MSVC specific compiler macros that are needed to get this thing to build
#pragma region Desktop Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
RO_INIT_SINGLETHREADED = 0, // Single-threaded application
#endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
RO_INIT_MULTITHREADED = 1, // COM calls objects on any thread.
} RO_INIT_TYPE;
Anyway, I think this project could build with mingw on windows if some stuff was modified a bit. Just wondering what your thoughts are...