Skip to content

Commit

Permalink
Update cmake project to generate example executables
Browse files Browse the repository at this point in the history
  • Loading branch information
vkotaru committed Jun 26, 2022
1 parent 91575e1 commit 95c54bb
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.a
/C++/Build
build/
C++/.idea/
C++/cmake-build-release/
28 changes: 28 additions & 0 deletions C++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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} )
# I used a simple string replace, to cut off .cpp.
string( REPLACE ".cpp" "" testname ${testsourcefile} )
add_executable( ${testname} Examples/${testsourcefile} )
# Make sure YourLib is linked to each app
target_link_libraries( ${testname} navio pigpio pthread )
endforeach( testsourcefile ${EXMPL_SRCS} )


File renamed without changes.
78 changes: 45 additions & 33 deletions C++/Navio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
#)
24 changes: 12 additions & 12 deletions C++/Navio/Common/I2Cdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,34 +375,34 @@ 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);
count = write(fd, buf, length+1);
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.
Expand All @@ -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++) {
Expand All @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions C++/Navio/Common/I2Cdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ THE SOFTWARE.

#define I2CDEV RASPBERRY_PI_I2C

#ifndef TRUE
#define TRUE (1==1)
#define FALSE (0==1)
#endif

#include <stdint.h>

class I2Cdev {
Expand Down

0 comments on commit 95c54bb

Please sign in to comment.