diff --git a/.travis.yml b/.travis.yml index 1ff6bce..e6be991 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,8 @@ branches: before_install: - sudo add-apt-repository -y ppa:voltvisionfrenchy/ola - sudo apt-get update - - sudo apt-get install -y libola-dev + - sudo apt-get install -y --no-install-recommends libola-dev + - sudo apt-get install -y --no-install-recommends libncurses5-dev before_script: @@ -16,4 +17,4 @@ before_script: - cd build - cmake .. -script: make && make olaclient && sudo make install && ctest -V +script: make && sudo make install && make PCA9685test && ctest -V && make examples diff --git a/CMakeLists.txt b/CMakeLists.txt index 95e0a62..ccd55fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,55 +1,30 @@ cmake_minimum_required(VERSION 3.0) -project(PCA9685) +project(libPCA9685) # set the lib version -set (libPCA9685_VERSION_MAJOR 0) -set (libPCA9685_VERSION_MINOR 7) +set(libPCA9685_VERSION_MAJOR 0) +set(libPCA9685_VERSION_MINOR 7) + +# save the lib version in config.h +configure_file(config.h.cmake ${PROJECT_BINARY_DIR}/config.h) + +# include for config.h +include_directories(${PROJECT_BINARY_DIR}) # add flags -set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -D_BSD_SOURCE -std=c11 -Wall -pedantic -Wextra") +set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -D_BSD_SOURCE -D_DEFAULT_SOURCE -std=c11 -Wall -pedantic -Wextra") + +# build the library +add_subdirectory(src) + +# build the test app +add_subdirectory(test EXCLUDE_FROM_ALL) + +# build the examples, but not by default +add_subdirectory(examples EXCLUDE_FROM_ALL) # add tests enable_testing() -add_test(run_test sh -xc "./PCA9685test -td 1 40 > PCA9685_actual_output" 2>&1) +add_test(run_test sh -xc "./test/PCA9685test -td 1 40 > PCA9685_actual_output" 2>&1) add_test(diff_output sh -xc "diff ../test/PCA9685_expected_output ./PCA9685_actual_output" 2>&1) - -# build the library -add_subdirectory (src) -include_directories ("${PROJECT_SOURCE_DIR}/src") - - -# build the quickstart example -configure_file ( - "${PROJECT_SOURCE_DIR}/examples/quickstart/quickstartConfig.h.in" - "${PROJECT_BINARY_DIR}/examples/quickstart/quickstartConfig.h" -) -include_directories("${PROJECT_BINARY_DIR}/examples/quickstart") -add_executable (quickstart examples/quickstart/quickstart.c) -target_link_libraries (quickstart PCA9685) - - -# build the PCA9685demo example -configure_file ( - "${PROJECT_SOURCE_DIR}/examples/PCA9685demo/PCA9685demoConfig.h.in" - "${PROJECT_BINARY_DIR}/examples/PCA9685demo/PCA9685demoConfig.h" -) -include_directories("${PROJECT_BINARY_DIR}/examples/PCA9685demo") -add_executable (PCA9685demo examples/PCA9685demo/PCA9685demo.c) -target_link_libraries (PCA9685demo PCA9685) -target_link_libraries (PCA9685demo ncurses) - - -# build the PCA9685test app -configure_file ( - "${PROJECT_SOURCE_DIR}/test/PCA9685testConfig.h.in" - "${PROJECT_BINARY_DIR}/test/PCA9685testConfig.h" -) -include_directories("${PROJECT_BINARY_DIR}/test") -add_executable (PCA9685test test/PCA9685test.c) -target_link_libraries (PCA9685test PCA9685) - - -# build the olaclient app -add_subdirectory(examples/olaclient) -include_directories("${PROJECT_BINARY_DIR}/examples/olaclient") diff --git a/examples/PCA9685demo/PCA9685demoConfig.h.in b/config.h.cmake similarity index 100% rename from examples/PCA9685demo/PCA9685demoConfig.h.in rename to config.h.cmake diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..3084d94 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,8 @@ +project (examples) +# build the examples +add_subdirectory (olaclient) +add_subdirectory (PCA9685demo) +add_subdirectory (quickstart) + +add_custom_target(examples) +add_dependencies(examples olaclient PCA9685demo quickstart) diff --git a/examples/PCA9685demo/CMakeLists.txt b/examples/PCA9685demo/CMakeLists.txt new file mode 100644 index 0000000..8582ea4 --- /dev/null +++ b/examples/PCA9685demo/CMakeLists.txt @@ -0,0 +1,4 @@ +project (PCA9685demo) +add_executable(PCA9685demo PCA9685demo.c) +target_link_libraries(PCA9685demo PCA9685) +target_link_libraries(PCA9685demo ncurses) diff --git a/examples/PCA9685demo/PCA9685demo.c b/examples/PCA9685demo/PCA9685demo.c index c484544..c8500d6 100644 --- a/examples/PCA9685demo/PCA9685demo.c +++ b/examples/PCA9685demo/PCA9685demo.c @@ -7,12 +7,12 @@ #include #include #include -#include +#include // sudo apt-get install libncurses5-dev #include #include #include -#include "PCA9685demoConfig.h" +#include "config.h" // globals diff --git a/examples/olaclient/CMakeLists.txt b/examples/olaclient/CMakeLists.txt index 5ca1a13..51ac40a 100644 --- a/examples/olaclient/CMakeLists.txt +++ b/examples/olaclient/CMakeLists.txt @@ -1,16 +1,7 @@ cmake_minimum_required(VERSION 3.0) project (olaclient) -set (libPCA9685_VERSION_MAJOR 0) -set (libPCA9685_VERSION_MINOR 7) -configure_file ( - "${PROJECT_SOURCE_DIR}/olaclientConfig.h.in" - "${PROJECT_BINARY_DIR}/olaclientConfig.h" -) -include_directories ("${PROJECT_BINARY_DIR}") -include_directories ("${PROJECT_SOURCE_DIR}") - -add_executable(olaclient EXCLUDE_FROM_ALL olaclient.cpp) +add_executable(olaclient olaclient.cpp) target_link_libraries(olaclient PCA9685) target_link_libraries(olaclient ola) diff --git a/examples/olaclient/olaclient.cpp b/examples/olaclient/olaclient.cpp index bde45c4..80a2898 100644 --- a/examples/olaclient/olaclient.cpp +++ b/examples/olaclient/olaclient.cpp @@ -1,13 +1,13 @@ -#include +#include // sudo apt-get install libola-dev #include -#include +#include #include #include #include using namespace std; #include -#include "olaclientConfig.h" +#include "config.h" #define PWM_FREQ 200 #define DMX_UNIVERSE 1 diff --git a/examples/olaclient/olaclientConfig.h.in b/examples/olaclient/olaclientConfig.h.in deleted file mode 100644 index 16f20ec..0000000 --- a/examples/olaclient/olaclientConfig.h.in +++ /dev/null @@ -1,2 +0,0 @@ -#define libPCA9685_VERSION_MAJOR @libPCA9685_VERSION_MAJOR@ -#define libPCA9685_VERSION_MINOR @libPCA9685_VERSION_MINOR@ diff --git a/examples/quickstart/CMakeLists.txt b/examples/quickstart/CMakeLists.txt new file mode 100644 index 0000000..d3ca7a1 --- /dev/null +++ b/examples/quickstart/CMakeLists.txt @@ -0,0 +1,3 @@ +project (quickstart) +add_executable(quickstart quickstart.c) +target_link_libraries(quickstart PCA9685) diff --git a/examples/quickstart/quickstart.c b/examples/quickstart/quickstart.c index d10dd7b..21635f7 100644 --- a/examples/quickstart/quickstart.c +++ b/examples/quickstart/quickstart.c @@ -7,7 +7,7 @@ #include #include -#include "quickstartConfig.h" +#include "config.h" int fd; int addr = 0x40; diff --git a/examples/quickstart/quickstartConfig.h.in b/examples/quickstart/quickstartConfig.h.in deleted file mode 100644 index 16f20ec..0000000 --- a/examples/quickstart/quickstartConfig.h.in +++ /dev/null @@ -1,2 +0,0 @@ -#define libPCA9685_VERSION_MAJOR @libPCA9685_VERSION_MAJOR@ -#define libPCA9685_VERSION_MINOR @libPCA9685_VERSION_MINOR@ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c057ce..7e860ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,14 +1,9 @@ cmake_minimum_required(VERSION 3.0) -project (libPCA9685) +project(libPCA9685) -set (libPCA9685_VERSION_MAJOR 0) -set (libPCA9685_VERSION_MINOR 7) -configure_file ( - "${PROJECT_SOURCE_DIR}/libPCA9685Config.h.in" - "${PROJECT_BINARY_DIR}/libPCA9685Config.h" -) -include_directories ("${PROJECT_BINARY_DIR}") +# build the lib add_library(PCA9685 SHARED PCA9685.c) -install (TARGETS PCA9685 DESTINATION lib) -install (FILES PCA9685.h DESTINATION include) +# install the lib +install(TARGETS PCA9685 DESTINATION lib) +install(FILES PCA9685.h DESTINATION include) diff --git a/src/PCA9685.c b/src/PCA9685.c index 03322c2..b38d5e4 100644 --- a/src/PCA9685.c +++ b/src/PCA9685.c @@ -14,7 +14,7 @@ // set the lib version from the Config header // sets libPCA9685_VERSION_MAJOR and libPCA9685_VERSION_MINOR -#include "libPCA9685Config.h" +#include "config.h" // debug flag bool _PCA9685_DEBUG = 0; diff --git a/src/libPCA9685Config.h.in b/src/libPCA9685Config.h.in deleted file mode 100644 index 16f20ec..0000000 --- a/src/libPCA9685Config.h.in +++ /dev/null @@ -1,2 +0,0 @@ -#define libPCA9685_VERSION_MAJOR @libPCA9685_VERSION_MAJOR@ -#define libPCA9685_VERSION_MINOR @libPCA9685_VERSION_MINOR@ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..8008c9e --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.0) +project(PCA9685test) + +# build the test app +add_executable(PCA9685test PCA9685test.c) + +# link with the lib +target_link_libraries(PCA9685test PCA9685) diff --git a/test/PCA9685test.c b/test/PCA9685test.c index 96e12c2..26eaed3 100644 --- a/test/PCA9685test.c +++ b/test/PCA9685test.c @@ -8,7 +8,7 @@ #include #include -#include "PCA9685testConfig.h" +#include "config.h" int adpt; int addr;