Skip to content

Commit a4fb48e

Browse files
committed
Update cmake project to generate example executables
1 parent 91575e1 commit a4fb48e

File tree

6 files changed

+85
-50
lines changed

6 files changed

+85
-50
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
*.a
33
/C++/Build
44
build/
5+
C++/.idea/
6+
C++/cmake-build-release/

C++/CMakeLists.txt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cmake_minimum_required(VERSION 2.8.3)
2+
project(navio2_cpp)
3+
4+
set (CMAKE_CXX_STANDARD 14)
5+
6+
add_subdirectory(Navio)
7+
8+
include_directories(Examples)
9+
10+
set(EXMPL_SRCS
11+
AccelGyroMag.cpp
12+
ADC.cpp
13+
AHRS.cpp
14+
Barometer.cpp
15+
LED.cpp
16+
RCInput.cpp
17+
Servo.cpp
18+
threaded_baro.cpp)
19+
20+
foreach( testsourcefile ${EXMPL_SRCS} )
21+
string( REPLACE ".cpp" "" testname ${testsourcefile} )
22+
add_executable( ${testname} Examples/${testsourcefile} )
23+
target_link_libraries( ${testname} navio pigpio pthread )
24+
endforeach( testsourcefile ${EXMPL_SRCS} )
25+
26+

C++/Makefile C++/Makefile.bak

File renamed without changes.

C++/Navio/CMakeLists.txt

+45-33
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,60 @@
11
cmake_minimum_required(VERSION 2.8.3)
22
project(navio)
3-
add_definitions(-std=c++11)
3+
4+
set(CMAKE_CXX_STANDARD 14)
45

56
include_directories(
6-
Common
7-
Navio+
8-
Navio2
7+
Common
8+
Navio+
9+
Navio2
10+
pigpio
911
)
1012

1113

1214
set(DEFAULT_BUILD_TYPE "Release")
13-
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
14-
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
15-
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
16-
# Set the possible values of build type for cmake-gui
17-
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
18-
endif()
15+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
16+
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
17+
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
18+
# Set the possible values of build type for cmake-gui
19+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
20+
endif ()
1921

2022
include(GNUInstallDirs)
2123

24+
add_subdirectory(pigpio)
25+
2226
set(SOURCE_FILES
23-
Common/I2Cdev.cpp
24-
Common/MPU9250.cpp
25-
Common/MS5611.cpp
26-
Common/Ublox.cpp
27-
Common/Util.cpp
28-
Common/gpio.cpp
29-
Navio2/ADC_Navio2.cpp
30-
Navio2/LSM9DS1.cpp
31-
Navio2/Led_Navio2.cpp
32-
Navio2/PWM.cpp
33-
Navio2/RCInput_Navio2.cpp
34-
Navio2/RCOutput_Navio2.cpp
35-
Navio2/RGBled.cpp
36-
)
27+
Common/I2Cdev.cpp
28+
Common/MPU9250.cpp
29+
Common/MS5611.cpp
30+
Common/Ublox.cpp
31+
Common/Util.cpp
32+
Common/gpio.cpp
33+
Navio2/ADC_Navio2.cpp
34+
Navio2/LSM9DS1.cpp
35+
Navio2/Led_Navio2.cpp
36+
Navio2/PWM.cpp
37+
Navio2/RCInput_Navio2.cpp
38+
Navio2/RCOutput_Navio2.cpp
39+
Navio2/RGBled.cpp
40+
Navio+/ADC_Navio.cpp
41+
Navio+/ADS1115.cpp
42+
Navio+/Led_Navio.cpp
43+
Navio+/MB85RC256.cpp
44+
Navio+/PCA9685.cpp
45+
Navio+/RCInput_Navio.cpp
46+
Navio+/RCOutput_Navio.cpp
47+
)
3748

3849
add_library(navio SHARED ${SOURCE_FILES})
39-
target_include_directories(navio PUBLIC .)
50+
target_include_directories(navio PUBLIC . Navio+ Navio2 Common pigpio)
51+
4052
# set_target_properties(navio PROPERTIES PUBLIC_HEADER ${HEADER_FILES})
41-
install(TARGETS navio
42-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
43-
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
44-
install(DIRECTORY "${CMAKE_SOURCE_DIR}/" # source directory
45-
DESTINATION "include" # target directory
46-
FILES_MATCHING # install only matched files
47-
PATTERN "*.h" # select header files
48-
)
53+
#install(TARGETS navio
54+
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
55+
# PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
56+
#install(DIRECTORY "${CMAKE_SOURCE_DIR}/" # source directory
57+
# DESTINATION "include" # target directory
58+
# FILES_MATCHING # install only matched files
59+
# PATTERN "*.h" # select header files
60+
#)

C++/Navio/Common/I2Cdev.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -375,34 +375,34 @@ bool I2Cdev::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_
375375

376376
if (length > 127) {
377377
fprintf(stderr, "Byte write count (%d) > 127\n", length);
378-
return(FALSE);
378+
return(false);
379379
}
380380

381381
fd = open(I2CDEV , O_RDWR);
382382
if (fd < 0) {
383383
fprintf(stderr, "Failed to open device: %s\n", strerror(errno));
384-
return(FALSE);
384+
return(false);
385385
}
386386
if (ioctl(fd, I2C_SLAVE, devAddr) < 0) {
387387
fprintf(stderr, "Failed to select device: %s\n", strerror(errno));
388388
close(fd);
389-
return(FALSE);
389+
return(false);
390390
}
391391
buf[0] = regAddr;
392392
memcpy(buf+1,data,length);
393393
count = write(fd, buf, length+1);
394394
if (count < 0) {
395395
fprintf(stderr, "Failed to write device(%d): %s\n", count, ::strerror(errno));
396396
close(fd);
397-
return(FALSE);
397+
return(false);
398398
} else if (count != length+1) {
399399
fprintf(stderr, "Short write to device, expected %d, got %d\n", length+1, count);
400400
close(fd);
401-
return(FALSE);
401+
return(false);
402402
}
403403
close(fd);
404404

405-
return TRUE;
405+
return true;
406406
}
407407

408408
/** 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
422422

423423
if (length > 63) {
424424
fprintf(stderr, "Word write count (%d) > 63\n", length);
425-
return(FALSE);
425+
return(false);
426426
}
427427

428428
fd = open(I2CDEV, O_RDWR);
429429
if (fd < 0) {
430430
fprintf(stderr, "Failed to open device: %s\n", strerror(errno));
431-
return(FALSE);
431+
return(false);
432432
}
433433
if (ioctl(fd, I2C_SLAVE, devAddr) < 0) {
434434
fprintf(stderr, "Failed to select device: %s\n", strerror(errno));
435435
close(fd);
436-
return(FALSE);
436+
return(false);
437437
}
438438
buf[0] = regAddr;
439439
for (i = 0; i < length; i++) {
@@ -444,14 +444,14 @@ bool I2Cdev::writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16
444444
if (count < 0) {
445445
fprintf(stderr, "Failed to write device(%d): %s\n", count, ::strerror(errno));
446446
close(fd);
447-
return(FALSE);
447+
return(false);
448448
} else if (count != length*2+1) {
449449
fprintf(stderr, "Short write to device, expected %d, got %d\n", length+1, count);
450450
close(fd);
451-
return(FALSE);
451+
return(false);
452452
}
453453
close(fd);
454-
return TRUE;
454+
return true;
455455
}
456456

457457
/** Default timeout value for read operations.

C++/Navio/Common/I2Cdev.h

-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ THE SOFTWARE.
4949

5050
#define I2CDEV RASPBERRY_PI_I2C
5151

52-
#ifndef TRUE
53-
#define TRUE (1==1)
54-
#define FALSE (0==1)
55-
#endif
56-
5752
#include <stdint.h>
5853

5954
class I2Cdev {

0 commit comments

Comments
 (0)