From a4fb48eb950dfa5de47c12ea3786a20c17d39f7d Mon Sep 17 00:00:00 2001 From: vkotaru Date: Sun, 26 Jun 2022 09:10:21 -0700 Subject: [PATCH] Update cmake project to generate example executables --- .gitignore | 2 + C++/CMakeLists.txt | 26 ++++++++++++ C++/{Makefile => Makefile.bak} | 0 C++/Navio/CMakeLists.txt | 78 ++++++++++++++++++++-------------- C++/Navio/Common/I2Cdev.cpp | 24 +++++------ C++/Navio/Common/I2Cdev.h | 5 --- 6 files changed, 85 insertions(+), 50 deletions(-) create mode 100644 C++/CMakeLists.txt rename C++/{Makefile => Makefile.bak} (100%) diff --git a/.gitignore b/.gitignore index 9ba9d05f..3435aedf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.a /C++/Build build/ +C++/.idea/ +C++/cmake-build-release/ \ No newline at end of file diff --git a/C++/CMakeLists.txt b/C++/CMakeLists.txt new file mode 100644 index 00000000..5957f9a0 --- /dev/null +++ b/C++/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 2.8.3) +project(navio2_cpp) + +set (CMAKE_CXX_STANDARD 14) + +add_subdirectory(Navio) + +include_directories(Examples) + +set(EXMPL_SRCS + AccelGyroMag.cpp + ADC.cpp + AHRS.cpp + Barometer.cpp + LED.cpp + RCInput.cpp + Servo.cpp + threaded_baro.cpp) + +foreach( testsourcefile ${EXMPL_SRCS} ) + string( REPLACE ".cpp" "" testname ${testsourcefile} ) + add_executable( ${testname} Examples/${testsourcefile} ) + target_link_libraries( ${testname} navio pigpio pthread ) +endforeach( testsourcefile ${EXMPL_SRCS} ) + + diff --git a/C++/Makefile b/C++/Makefile.bak similarity index 100% rename from C++/Makefile rename to C++/Makefile.bak diff --git a/C++/Navio/CMakeLists.txt b/C++/Navio/CMakeLists.txt index c0901228..99c5ecff 100644 --- a/C++/Navio/CMakeLists.txt +++ b/C++/Navio/CMakeLists.txt @@ -1,48 +1,60 @@ cmake_minimum_required(VERSION 2.8.3) project(navio) -add_definitions(-std=c++11) + +set(CMAKE_CXX_STANDARD 14) include_directories( - Common - Navio+ - Navio2 + Common + Navio+ + Navio2 + pigpio ) set(DEFAULT_BUILD_TYPE "Release") -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") - set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE) - # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif() +if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") + set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif () include(GNUInstallDirs) +add_subdirectory(pigpio) + set(SOURCE_FILES - Common/I2Cdev.cpp - Common/MPU9250.cpp - Common/MS5611.cpp - Common/Ublox.cpp - Common/Util.cpp - Common/gpio.cpp - Navio2/ADC_Navio2.cpp - Navio2/LSM9DS1.cpp - Navio2/Led_Navio2.cpp - Navio2/PWM.cpp - Navio2/RCInput_Navio2.cpp - Navio2/RCOutput_Navio2.cpp - Navio2/RGBled.cpp - ) + Common/I2Cdev.cpp + Common/MPU9250.cpp + Common/MS5611.cpp + Common/Ublox.cpp + Common/Util.cpp + Common/gpio.cpp + Navio2/ADC_Navio2.cpp + Navio2/LSM9DS1.cpp + Navio2/Led_Navio2.cpp + Navio2/PWM.cpp + Navio2/RCInput_Navio2.cpp + Navio2/RCOutput_Navio2.cpp + Navio2/RGBled.cpp + Navio+/ADC_Navio.cpp + Navio+/ADS1115.cpp + Navio+/Led_Navio.cpp + Navio+/MB85RC256.cpp + Navio+/PCA9685.cpp + Navio+/RCInput_Navio.cpp + Navio+/RCOutput_Navio.cpp + ) add_library(navio SHARED ${SOURCE_FILES}) -target_include_directories(navio PUBLIC .) +target_include_directories(navio PUBLIC . Navio+ Navio2 Common pigpio) + # set_target_properties(navio PROPERTIES PUBLIC_HEADER ${HEADER_FILES}) -install(TARGETS navio - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -install(DIRECTORY "${CMAKE_SOURCE_DIR}/" # source directory - DESTINATION "include" # target directory - FILES_MATCHING # install only matched files - PATTERN "*.h" # select header files -) +#install(TARGETS navio +# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +# PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +#install(DIRECTORY "${CMAKE_SOURCE_DIR}/" # source directory +# DESTINATION "include" # target directory +# FILES_MATCHING # install only matched files +# PATTERN "*.h" # select header files +#) diff --git a/C++/Navio/Common/I2Cdev.cpp b/C++/Navio/Common/I2Cdev.cpp index 00b985ef..5d69c10c 100644 --- a/C++/Navio/Common/I2Cdev.cpp +++ b/C++/Navio/Common/I2Cdev.cpp @@ -375,18 +375,18 @@ bool I2Cdev::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_ if (length > 127) { fprintf(stderr, "Byte write count (%d) > 127\n", length); - return(FALSE); + return(false); } fd = open(I2CDEV , O_RDWR); if (fd < 0) { fprintf(stderr, "Failed to open device: %s\n", strerror(errno)); - return(FALSE); + return(false); } if (ioctl(fd, I2C_SLAVE, devAddr) < 0) { fprintf(stderr, "Failed to select device: %s\n", strerror(errno)); close(fd); - return(FALSE); + return(false); } buf[0] = regAddr; memcpy(buf+1,data,length); @@ -394,15 +394,15 @@ bool I2Cdev::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_ if (count < 0) { fprintf(stderr, "Failed to write device(%d): %s\n", count, ::strerror(errno)); close(fd); - return(FALSE); + return(false); } else if (count != length+1) { fprintf(stderr, "Short write to device, expected %d, got %d\n", length+1, count); close(fd); - return(FALSE); + return(false); } close(fd); - return TRUE; + return true; } /** Write multiple words to a 16-bit device register. @@ -422,18 +422,18 @@ bool I2Cdev::writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16 if (length > 63) { fprintf(stderr, "Word write count (%d) > 63\n", length); - return(FALSE); + return(false); } fd = open(I2CDEV, O_RDWR); if (fd < 0) { fprintf(stderr, "Failed to open device: %s\n", strerror(errno)); - return(FALSE); + return(false); } if (ioctl(fd, I2C_SLAVE, devAddr) < 0) { fprintf(stderr, "Failed to select device: %s\n", strerror(errno)); close(fd); - return(FALSE); + return(false); } buf[0] = regAddr; for (i = 0; i < length; i++) { @@ -444,14 +444,14 @@ bool I2Cdev::writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16 if (count < 0) { fprintf(stderr, "Failed to write device(%d): %s\n", count, ::strerror(errno)); close(fd); - return(FALSE); + return(false); } else if (count != length*2+1) { fprintf(stderr, "Short write to device, expected %d, got %d\n", length+1, count); close(fd); - return(FALSE); + return(false); } close(fd); - return TRUE; + return true; } /** Default timeout value for read operations. diff --git a/C++/Navio/Common/I2Cdev.h b/C++/Navio/Common/I2Cdev.h index ea32d1ed..b75b2706 100644 --- a/C++/Navio/Common/I2Cdev.h +++ b/C++/Navio/Common/I2Cdev.h @@ -49,11 +49,6 @@ THE SOFTWARE. #define I2CDEV RASPBERRY_PI_I2C -#ifndef TRUE -#define TRUE (1==1) -#define FALSE (0==1) -#endif - #include class I2Cdev {