From 147d61a59ff78eab47f38134febcd8acec33218b Mon Sep 17 00:00:00 2001 From: Dale Phurrough Date: Tue, 30 May 2023 17:17:58 +0200 Subject: [PATCH] fix add_flag() to correctly add flags to C++ files - fixes https://github.com/luxonis/XLink/issues/68 --- CMakeLists.txt | 3 ++- cmake/Flags.cmake | 6 ++++++ src/pc/PlatformDeviceSearchDynamic.cpp | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 402a3dd..07f6890 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # With additions of Luxonis -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.3) include("cmake/HunterGate.cmake") HunterGate( @@ -152,6 +152,7 @@ else() endif() # Add flags +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) add_default_flags(${TARGET_NAME}) # Check if pthread_getname_np exists diff --git a/cmake/Flags.cmake b/cmake/Flags.cmake index 08c1e2f..41b2f75 100644 --- a/cmake/Flags.cmake +++ b/cmake/Flags.cmake @@ -1,13 +1,19 @@ ## setup compilation flags # conditionally applies flag. If flag is supported by current compiler, it will be added to compile options. include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) function(add_flag target flag) check_c_compiler_flag(${flag} FLAG_${flag}) if (FLAG_${flag} EQUAL 1) target_compile_options(${target} PRIVATE $<$:${flag}>) endif () + check_cxx_compiler_flag(${flag} FLAGXX_${flag}) + if (FLAGXX_${flag} EQUAL 1) + target_compile_options(${target} PRIVATE $<$:${flag}>) + endif () endfunction() +# only works for C source files function(add_flag_source source flag) check_c_compiler_flag(${flag} FLAG_${flag}) if (FLAG_${flag} EQUAL 1) diff --git a/src/pc/PlatformDeviceSearchDynamic.cpp b/src/pc/PlatformDeviceSearchDynamic.cpp index e78c760..c9e785c 100644 --- a/src/pc/PlatformDeviceSearchDynamic.cpp +++ b/src/pc/PlatformDeviceSearchDynamic.cpp @@ -138,9 +138,9 @@ xLinkPlatformErrorCode_t XLinkPlatformFindDevicesDynamic(const deviceDesc_t in_d { deviceDesc_t* devices = out_foundDevices; int write_index = 0; - for(int i = 0; i < *out_amountOfFoundDevices; i++){ + for(int i = 0, amountBound = static_cast(*out_amountOfFoundDevices); i < amountBound; ++i){ bool duplicate = false; - for(int j = i - 1; j >= 0; j--){ + for(int j = i - 1; j >= 0; --j){ // Check if duplicate if(devices[i].protocol == devices[j].protocol && strcmp(devices[i].name, devices[j].name) == 0 && strcmp(devices[i].mxid, devices[j].mxid) == 0){ duplicate = true;