mirror of
https://github.com/eclipse/upm.git
synced 2025-03-14 20:47:30 +03:00
examples: C/C++ examples use transitive dependencies
Updated the examples to comprehend transitive dependencies. This means that each example target will no longer have a giant list of -I includes (the examples at the end of the list had includes for all previous examples, upwards of 200 -I's on the command line). * Created a CMakeLists.txt in the upm/examples directory, moved common functionality to this level. * C/C++ examples now look to the filename for their dependency target name, ie; gas-mq2.cxx adds a dependency to the 'gas' target * Updated a handful of C/C++ example names to reflect this * Example CMake flow - glob the list of files, add targets for any special case examples, then att targets for all the rest Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
parent
76a12af15f
commit
048f1ac08e
@ -419,18 +419,11 @@ set (UPM_COMMON_HEADER_DIRS
|
||||
${CMAKE_HOME_DIRECTORY}/include
|
||||
${CMAKE_HOME_DIRECTORY}/include/fti)
|
||||
|
||||
# UPM source
|
||||
add_subdirectory (src)
|
||||
if(BUILDEXAMPLES)
|
||||
add_subdirectory (examples/c)
|
||||
if(BUILDCPP)
|
||||
add_subdirectory (examples/c++)
|
||||
endif(BUILDCPP)
|
||||
endif()
|
||||
|
||||
# Build java examples
|
||||
if(BUILDSWIGJAVA AND BUILDEXAMPLES)
|
||||
add_subdirectory (examples/java)
|
||||
endif()
|
||||
# UPM examples
|
||||
add_subdirectory (examples)
|
||||
|
||||
# Python interp is previously found if BUILDTESTS=ON
|
||||
if (BUILDTESTS)
|
||||
|
@ -11,10 +11,10 @@ buzzer.cxx BuzzerSample.java buzzer.js buzzer.py
|
||||
cjq4435.cxx CJQ4435Sample.java cjq4435.js cjq4435.py
|
||||
ds1307.cxx DS1307Sample.java ds1307.js ds1307.py
|
||||
enc03r.cxx ENC03RSample.java enc03r.js enc03r.py
|
||||
es08a.cxx ES08ASample.java es08a.js es08a.py
|
||||
servo-es08a.cxx ES08ASample.java es08a.js es08a.py
|
||||
groveehr.cxx GroveEHRSample.java groveehr.js groveehr.py
|
||||
groveledbar.cxx GroveLEDBar.java groveledbar.js groveledbar.py
|
||||
groveled.cxx GroveLEDSample.java groveled.js groveled.py
|
||||
my9221-groveledbar.cxx GroveLEDBar.java groveledbar.js groveledbar.py
|
||||
grove-groveled.cxx GroveLEDSample.java groveled.js groveled.py
|
||||
grovelinefinder.cxx GroveLineFinderSample.java grovelinefinder.js grovelinefinder.py
|
||||
grovemoisture.cxx GroveMoistureSample.java grovemoisture.js grovemoisture.py
|
||||
grovescam.cxx GROVESCAMSample.java grovescam.js grovescam.py
|
||||
@ -42,9 +42,9 @@ mma7660.cxx MMA7660Sample.java mma7660.js mma7660.py
|
||||
mpl3115a2.cxx MPL3115A2Sample.java mpl3115a2.js mpl3115a2.py
|
||||
mpr121.cxx MPR121Sample.java mpr121.js mpr121.py
|
||||
mpu9150.cxx MPU9150Sample.java mpu9150.js mpu9150.py
|
||||
mq2.cxx MQ2Sample.java mq2.js mq2.py
|
||||
gas-mq2.cxx MQ2Sample.java mq2.js mq2.py
|
||||
mq303a.cxx MQ303ASample.java mq303a.js mq303a.py
|
||||
mq5.cxx MQ5Sample.java mq5.js mq5.py
|
||||
gas-mq5.cxx MQ5Sample.java mq5.js mq5.py
|
||||
nrf24l01-receiver.cxx NRF24L01_receiverSample.java nrf24l01-receiver.js nrf24l01-receiver.py
|
||||
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java nrf24l01-transmitter.js nrf24l01-transmitter.py
|
||||
nunchuck.cxx NUNCHUCKSample.java nunchuck.js nunchuck.py
|
||||
@ -59,12 +59,12 @@ rpr220.cxx RPR220Sample.java rpr220.js rpr220.py
|
||||
rpr220-intr.cxx RPR220_intrSample.java rpr220-intr.js rpr220-intr.py
|
||||
slide.cxx SlideSample.java slide.js slide.py
|
||||
speaker.cxx SpeakerSample.java speaker.js speaker.py
|
||||
ssd1308-oled.cxx SSD1308_oledSample.java ssd1308-oled.js ssd1308-oled.py
|
||||
ssd1327-oled.cxx SSD1327_oledSample.java ssd1327-oled.js ssd1327-oled.py
|
||||
i2clcd-ssd1308-oled.cxx SSD1308_oledSample.java ssd1308-oled.js ssd1308-oled.py
|
||||
i2clcd-ssd1327-oled.cxx SSD1327_oledSample.java ssd1327-oled.js ssd1327-oled.py
|
||||
st7735.cxx ST7735Sample.java st7735.js st7735.py
|
||||
stepmotor.cxx StepMotorSample.java stepmotor.js stepmotor.py
|
||||
tm1637.cxx TM1637Sample.java tm1637.js tm1637.py
|
||||
tp401.cxx TP401Sample.java tp401.js tp401.py
|
||||
gas-tp401.cxx TP401Sample.java tp401.js tp401.py
|
||||
tsl2561.cxx TSL2561Sample.java tsl2561.js tsl2561.py
|
||||
ttp223.cxx TTP223Sample.java ttp223.js ttp223.py
|
||||
uln200xa.cxx ULN200XASample.java uln200xa.js uln200xa.py
|
||||
|
118
examples/CMakeLists.txt
Normal file
118
examples/CMakeLists.txt
Normal file
@ -0,0 +1,118 @@
|
||||
# Add an example executable target for the provided source file which depends
|
||||
# on a UPM library target. Strings after the first '-' are ignored.
|
||||
#
|
||||
# Usage:
|
||||
# add_example(source_file TARGETS <target0> <target1> <targetn> SUFFIX <target_suffix>)
|
||||
#
|
||||
# Parameters:
|
||||
# source_file - C/C++ source file. Filename must follow a specific format:
|
||||
# <library>-[additional].c(xx)
|
||||
# library: Name of UPM library required by example
|
||||
# -additional: Any other string used to identify the example
|
||||
# TARGETS - If TARGETS is set, ignore the <library>-[additional] syntax and
|
||||
# use only the provided TARGETS as target name dependencies
|
||||
# SUFFIX - Provide a means to differentiate between C/C++ dependency targets and
|
||||
# example names. Leave empty for CXX examples. Use '-c' for c targets.
|
||||
# SUFFIX Example file Dependency target Example binary
|
||||
# ------ ------------ ----------------- --------------
|
||||
# "-c" foo.c foo-c foo-example-c
|
||||
# foo.cxx foo foo-example-cxx
|
||||
#
|
||||
# Parent scope variable:
|
||||
# example_src_list - Any example target which is successfully created by
|
||||
# add_example will be removed from the parent scope variable
|
||||
# example_src_list (if it exists). This provides a means to handle
|
||||
# special case examples BEFORE handling all files in example_src_list.
|
||||
#
|
||||
# Examples:
|
||||
# # Creates sensorfoo-example-cxx, depends on target: sensorfoo
|
||||
# add_example(sensorfoo.cxx)
|
||||
#
|
||||
# # Creates sensorfoo-example-c, depends on target: sensorfoo-c
|
||||
# add_example(sensorfoo.c SUFFIX "-c")
|
||||
#
|
||||
# # Creates sensorfoo-bar-example-c, depends on target: sensorfoo-c
|
||||
# add_example(sensorfoo-bar.c SUFFIX "-c")
|
||||
#
|
||||
# # Creates testfoobar-cxx, depends on targets: blib, blah
|
||||
# add_example(testfoobar.c TARGETS blib blah)
|
||||
#
|
||||
# Examples:
|
||||
# a110x.c Requires libupmc-a110x
|
||||
# lcm1602-i2c.c Requires libupmc-lcm1602
|
||||
# bmp280-bme280.c Requires libupmc-bmp280
|
||||
# i2clcd-eboled.cxx Requires libupm-i2clcd
|
||||
#
|
||||
#
|
||||
function (add_example example_src)
|
||||
set (oneValueArgs SUFFIX)
|
||||
set (multiValueArgs TARGETS)
|
||||
# Parse function parameters
|
||||
cmake_parse_arguments(add_example "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
||||
|
||||
# Get the base filename from the full filename
|
||||
# For file /some/path/to/sensorfoo-bar.c, example_name = sensorfoo-bar
|
||||
get_filename_component(example_name ${example_src} NAME_WE)
|
||||
|
||||
# Parse out <library>
|
||||
# Example: sensorfoo-bar.c, library = sensorfoo
|
||||
string (REPLACE "-" ";" split_name ${example_name})
|
||||
list (GET split_name 0 library_name)
|
||||
|
||||
# If TARGETS is not provided, parse dependency target name from example_src
|
||||
if (NOT add_example_TARGETS)
|
||||
# For sensorfoo, lib_target_names = sensorfoo-c
|
||||
set (lib_target_names "${library_name}${add_example_SUFFIX}")
|
||||
else ()
|
||||
set (lib_target_names "${add_example_TARGETS}")
|
||||
endif ()
|
||||
|
||||
# Unfortunately, c++ and c library targets are not named the same. If
|
||||
# no suffix is provided, assume C++ and add a suffix of -cxx to the
|
||||
# example target name
|
||||
# library example target
|
||||
# c: sensorfoo-c sensorfoo-bar-example-c
|
||||
# cxx: sensorfoo sensorfoo-bar-example-cxx
|
||||
if (NOT add_example_SUFFIX)
|
||||
set(add_example_SUFFIX "-cxx")
|
||||
endif ()
|
||||
|
||||
# Create the target name for this example: mylibrary-bar-example-c
|
||||
set (this_target_name "${example_name}-example${add_example_SUFFIX}")
|
||||
|
||||
# If a dependency target does NOT exist, print a warning and skip
|
||||
foreach(_dep_target ${lib_target_names})
|
||||
if (NOT TARGET ${_dep_target})
|
||||
message(STATUS "Missing CMake target (${_dep_target}), skipping example ${example_src}")
|
||||
return()
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
# Create an executable target for this example
|
||||
add_executable (${this_target_name} ${example_src})
|
||||
|
||||
# Add each dependency to the library target
|
||||
foreach(_dep_target ${lib_target_names})
|
||||
target_link_libraries(${this_target_name} ${_dep_target} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endforeach ()
|
||||
|
||||
# Special case...
|
||||
list (REMOVE_ITEM example_src_list ${example_src})
|
||||
set (example_src_list ${example_src_list} PARENT_SCOPE)
|
||||
endfunction (add_example example_src)
|
||||
|
||||
# Add subdirectories if BUILDEXAMPLES=on
|
||||
if(BUILDEXAMPLES)
|
||||
# Add C examples
|
||||
add_subdirectory (c)
|
||||
|
||||
# Add C++ examples?
|
||||
if (BUILDCPP)
|
||||
add_subdirectory (c++)
|
||||
endif ()
|
||||
|
||||
# Add java examples?
|
||||
if(BUILDSWIGJAVA)
|
||||
add_subdirectory (java)
|
||||
endif()
|
||||
endif()
|
@ -1,388 +1,20 @@
|
||||
# Selectively disable certain warnings for the examples
|
||||
# nrf examples flag -Wtautological-compare
|
||||
set (CXX_DISABLED_WARNINGS -Wno-tautological-compare)
|
||||
# Create an list of all C++ source files in this directory
|
||||
file (GLOB example_src_list RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cxx")
|
||||
|
||||
# Extract module name from non-standard example name
|
||||
macro(get_module_name example_name module_name)
|
||||
string(LENGTH ${example_name} length)
|
||||
string(FIND ${example_name} "-" index)
|
||||
if (${index} GREATER 1)
|
||||
string(SUBSTRING ${example_name} 0 ${index} substr)
|
||||
set(${module_name} ${substr})
|
||||
elseif (${example_name} MATCHES "^grove")
|
||||
set (${module_name} "grove")
|
||||
elseif ((${example_name} MATCHES "^mq" AND ${length} EQUAL 3) OR ${example_name} STREQUAL "tp401")
|
||||
set (${module_name} "gas")
|
||||
else()
|
||||
set(${module_name} ${example_name})
|
||||
endif()
|
||||
endmacro()
|
||||
# - Handle special cases here --------------------------------------------------
|
||||
|
||||
# Set source file, include and linker settings for an example
|
||||
# If example cannot be built, example_bin is cleared
|
||||
macro(add_custom_example example_bin example_src example_module_list)
|
||||
set(found_all_modules TRUE)
|
||||
foreach (module ${example_module_list})
|
||||
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/src/${module}")
|
||||
set(found_all_modules FALSE)
|
||||
endif()
|
||||
if (MODULE_LIST)
|
||||
list(FIND MODULE_LIST ${module} index)
|
||||
if (${index} EQUAL -1)
|
||||
set(found_all_modules FALSE)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
if (found_all_modules)
|
||||
add_executable (${example_bin} ${example_src})
|
||||
target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
|
||||
# Test humidity interface for 2 sensor libraries
|
||||
add_example(humidity-sensor.cxx TARGETS si7005 bmp280)
|
||||
# Test pressure interface for 2 sensor libraries
|
||||
add_example(pressure-sensor.cxx TARGETS bmp280 bmpx8x)
|
||||
# Test temperature interface for 3 sensor libraries
|
||||
add_example(temperature-sensor.cxx TARGETS bmp280 bmpx8x si7005)
|
||||
# Test light interface for 2 sensor libraries
|
||||
add_example(light-sensor.cxx TARGETS si1132 max44009)
|
||||
# Test light controller interface for 3 sensor libraries
|
||||
add_example(light-controller.cxx TARGETS lp8860 ds1808lc hlg150h)
|
||||
|
||||
# Disable warnings from CXX_DISABLED_WARNINGS
|
||||
foreach(flag ${CXX_DISABLED_WARNINGS})
|
||||
compiler_flag_supported(CXX is_supported ${flag})
|
||||
if (is_supported)
|
||||
target_compile_options(${example_bin} PRIVATE "${flag}")
|
||||
endif(is_supported)
|
||||
endforeach(flag ${CXX_DISABLED_WARNINGS})
|
||||
|
||||
foreach (module ${example_module_list})
|
||||
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}")
|
||||
include_directories (${module_dir})
|
||||
if (${module} STREQUAL "lcd")
|
||||
set(module "i2clcd")
|
||||
endif()
|
||||
target_link_libraries (${example_bin} ${module})
|
||||
endforeach()
|
||||
else()
|
||||
message (WARNING "Ignored ${example_bin}")
|
||||
set (example_bin "")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
# Add specified example by name
|
||||
# Note special case for grove based examples
|
||||
macro(add_example example_name)
|
||||
set(example_src "${example_name}.cxx")
|
||||
set(example_bin "${example_name}-example-cxx")
|
||||
get_module_name(${example_name} module_name)
|
||||
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}")
|
||||
|
||||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}"
|
||||
AND EXISTS ${module_dir}
|
||||
AND IS_DIRECTORY ${module_dir})
|
||||
add_custom_example(${example_bin} ${example_src} ${module_name})
|
||||
if ((NOT ${example_bin} STREQUAL "") AND (${module_name} STREQUAL "grove"))
|
||||
set(grove_module_path "${PROJECT_SOURCE_DIR}/src/${example_name}")
|
||||
if (EXISTS ${grove_module_path})
|
||||
include_directories(${grove_module_path})
|
||||
target_link_libraries (${example_bin} ${example_name})
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
message (WARNING "Ignored ${example_bin}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
|
||||
|
||||
# UPM c include directories
|
||||
include_directories (${PROJECT_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/src/utilities)
|
||||
|
||||
# Set the mraa include and link directories prior to adding examples
|
||||
include_directories (${MRAA_INCLUDE_DIRS})
|
||||
link_directories (${MRAA_LIBDIR})
|
||||
|
||||
# If your sample source file matches the name of the module it tests, add it here
|
||||
# Exceptions are as follows:
|
||||
# string after first '-' is ignored (e.g. nrf24l01-transmitter maps to nrf24l01)
|
||||
# mq? will use module gas
|
||||
# grove* will use module grove
|
||||
add_example (hmc5883l)
|
||||
add_example (led)
|
||||
add_example (groveled)
|
||||
add_example (relay)
|
||||
add_example (groverelay)
|
||||
add_example (light)
|
||||
add_example (grovelight)
|
||||
add_example (temperature)
|
||||
add_example (grovetemp)
|
||||
add_example (button)
|
||||
add_example (grovebutton)
|
||||
add_example (rotary)
|
||||
add_example (groverotary)
|
||||
add_example (slide)
|
||||
add_example (groveslide)
|
||||
add_example (buzzer)
|
||||
add_example (nrf24l01-transmitter)
|
||||
add_example (nrf24l01-receiver)
|
||||
add_example (nrf24l01-broadcast)
|
||||
add_example (hcsr04)
|
||||
add_example (max44000)
|
||||
add_example (mma7455)
|
||||
add_example (st7735)
|
||||
add_example (max31855)
|
||||
add_example (bmpx8x)
|
||||
add_example (stepmotor)
|
||||
add_example (pulsensor)
|
||||
add_example (mic)
|
||||
add_example (mpu9150)
|
||||
add_example (maxds3231m)
|
||||
add_example (max31723)
|
||||
add_example (max5487)
|
||||
add_example (nrf8001-broadcast)
|
||||
add_example (nrf8001-helloworld)
|
||||
add_example (lpd8806)
|
||||
add_example (mlx90614)
|
||||
add_example (ecs1030)
|
||||
add_example (mq2)
|
||||
add_example (mq3)
|
||||
add_example (mq4)
|
||||
add_example (mq5)
|
||||
add_example (mq6)
|
||||
add_example (mq7)
|
||||
add_example (mq8)
|
||||
add_example (mq9)
|
||||
add_example (tp401)
|
||||
add_example (tcs3414cs)
|
||||
add_example (th02)
|
||||
add_example (ttp223)
|
||||
add_example (lsm303)
|
||||
add_example (joystick12)
|
||||
add_example (lol)
|
||||
add_example (tsl2561)
|
||||
add_example (htu21d)
|
||||
add_example (mpl3115a2)
|
||||
add_example (ldt0028)
|
||||
add_example (am2315)
|
||||
add_example (itg3200)
|
||||
add_example (enc03r)
|
||||
add_example (adc121c021)
|
||||
add_example (ds1307)
|
||||
add_example (a110x)
|
||||
add_example (gp2y0a)
|
||||
add_example (moisture)
|
||||
add_example (grovemoisture)
|
||||
add_example (ehr)
|
||||
add_example (groveehr)
|
||||
add_example (ta12200)
|
||||
add_example (grovelinefinder)
|
||||
add_example (linefinder)
|
||||
add_example (vdiv)
|
||||
add_example (grovevdiv)
|
||||
add_example (water)
|
||||
add_example (grovewater)
|
||||
add_example (guvas12d)
|
||||
add_example (mpr121)
|
||||
add_example (yg1006)
|
||||
add_example (wt5001)
|
||||
add_example (ppd42ns)
|
||||
add_example (mq303a)
|
||||
add_example (speaker)
|
||||
add_example (grovespeaker)
|
||||
add_example (rfr359f)
|
||||
add_example (biss0001)
|
||||
add_example (rotaryencoder)
|
||||
add_example (adxl345)
|
||||
add_example (rpr220)
|
||||
add_example (rpr220-intr)
|
||||
add_example (mma7660)
|
||||
add_example (cjq4435)
|
||||
add_example (adxl335)
|
||||
add_example (hmtrp)
|
||||
add_example (nunchuck)
|
||||
add_example (otp538u)
|
||||
add_example (collision)
|
||||
add_example (grovecollision)
|
||||
add_example (electromagnet)
|
||||
add_example (groveelectromagnet)
|
||||
add_example (emg)
|
||||
add_example (groveemg)
|
||||
add_example (o2)
|
||||
add_example (groveo2)
|
||||
add_example (gsr)
|
||||
add_example (grovegsr)
|
||||
add_example (ina132)
|
||||
add_example (l298)
|
||||
add_example (l298-stepper)
|
||||
add_example (at42qt1070)
|
||||
add_example (grovemd)
|
||||
add_example (md)
|
||||
add_example (grovemd-stepper)
|
||||
add_example (md-stepper)
|
||||
add_example (pca9685)
|
||||
add_example (eldriver)
|
||||
add_example (groveeldriver)
|
||||
add_example (adafruitss)
|
||||
add_example (adafruitms1438)
|
||||
add_example (adafruitms1438-stepper)
|
||||
add_example (hx711)
|
||||
add_example (flex)
|
||||
add_example (a110x-intr)
|
||||
add_example (mhz16)
|
||||
add_example (apds9002)
|
||||
add_example (waterlevel)
|
||||
add_example (tm1637)
|
||||
add_example (zfm20)
|
||||
add_example (zfm20-register)
|
||||
add_example (uln200xa)
|
||||
add_example (grovewfs)
|
||||
add_example (wfs)
|
||||
add_example (isd1820)
|
||||
add_example (sx6119)
|
||||
add_example (si114x)
|
||||
add_example (maxsonarez)
|
||||
add_example (hm11)
|
||||
add_example (ht9170)
|
||||
add_example (h3lis331dl)
|
||||
add_example (ad8232)
|
||||
add_example (grovescam)
|
||||
add_example (scam)
|
||||
add_example (m24lr64e)
|
||||
add_example (rgbringcoder)
|
||||
add_example (hp20x)
|
||||
add_example (pn532)
|
||||
add_example (pn532-writeurl)
|
||||
add_example (lsm9ds0)
|
||||
add_example (loudness)
|
||||
add_example (mg811)
|
||||
add_example (wheelencoder)
|
||||
add_example (sm130)
|
||||
add_example (gprs)
|
||||
add_example (grovegprs)
|
||||
add_example (lm35)
|
||||
add_example (micsv89)
|
||||
add_example (xbee)
|
||||
add_example (urm37)
|
||||
add_example (urm37-uart)
|
||||
add_example (adxrs610)
|
||||
add_example (bma220)
|
||||
add_example (dfrph)
|
||||
add_example (mcp9808)
|
||||
add_example (groveultrasonic)
|
||||
add_example (ultrasonic)
|
||||
add_example (sx1276-lora)
|
||||
add_example (sx1276-fsk)
|
||||
add_example (ili9341)
|
||||
add_example (nlgpio16)
|
||||
add_example (ads1x15)
|
||||
if (MODBUS_FOUND)
|
||||
include_directories(${MODBUS_INCLUDE_DIRS})
|
||||
add_example (t3311)
|
||||
add_example (hwxpxx)
|
||||
add_example (h803x)
|
||||
endif()
|
||||
add_example (hdxxvxta)
|
||||
add_example (rhusb)
|
||||
add_example (apds9930)
|
||||
add_example (kxcjk1013)
|
||||
add_example (ssd1351)
|
||||
add_example (ds1808lc)
|
||||
add_example (hlg150h)
|
||||
add_example (lp8860)
|
||||
add_example (max44009)
|
||||
add_example (si1132)
|
||||
add_example (si7005)
|
||||
add_example (t6713)
|
||||
add_example (cwlsxxa)
|
||||
add_example (teams)
|
||||
add_example (apa102)
|
||||
add_example (tex00)
|
||||
add_example (bmi160)
|
||||
add_example (smartdrive)
|
||||
if (HAVE_FIRMATA)
|
||||
add_example (curieimu)
|
||||
endif ()
|
||||
if (BACNET_FOUND)
|
||||
include_directories(${BACNET_INCLUDE_DIRS})
|
||||
# we need access to bacnetmstp headers too
|
||||
include_directories(${PROJECT_SOURCE_DIR}/src/bacnetmstp)
|
||||
add_example (e50hx)
|
||||
add_example (t8100)
|
||||
add_example (tb7300)
|
||||
endif()
|
||||
if (JPEG_FOUND)
|
||||
add_example (vcap)
|
||||
endif (JPEG_FOUND)
|
||||
add_example (ds2413)
|
||||
add_example (ds18b20)
|
||||
add_example (bmp280)
|
||||
add_example (bno055)
|
||||
add_example (l3gd20)
|
||||
add_example (l3gd20-i2c)
|
||||
add_example (bmx055)
|
||||
add_example (ms5611)
|
||||
add_example (nmea_gps)
|
||||
add_example (mma7361)
|
||||
add_example (bh1750)
|
||||
add_example (hka5)
|
||||
add_example (dfrorp)
|
||||
add_example (dfrec)
|
||||
add_example (sht1x)
|
||||
add_example (ms5803)
|
||||
add_example (ims)
|
||||
add_example (ecezo)
|
||||
add_example (mb704x)
|
||||
add_example (rf22-server)
|
||||
add_example (rf22-client)
|
||||
add_example (mcp2515)
|
||||
add_example (max30100)
|
||||
add_example (sensortemplate)
|
||||
add_example (p9813)
|
||||
add_example (abp)
|
||||
add_example (lcdks)
|
||||
add_example (mmc35240)
|
||||
add_example (tcs37727)
|
||||
add_example (tmp006)
|
||||
add_example (mma8x5x)
|
||||
add_example (mag3110)
|
||||
add_example (hdc1000)
|
||||
add_example (bmg160)
|
||||
add_example (bma250e)
|
||||
add_example (bmm150)
|
||||
add_example (rsc)
|
||||
|
||||
# These are special cases where you specify example binary, source file and module(s)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||
add_custom_example (groveled-multi-example-cxx groveled-multi.cxx grove)
|
||||
add_custom_example (lcm1602-i2c-example-cxx lcm1602-i2c.cxx lcm1602)
|
||||
add_custom_example (lcm1602-parallel-example-cxx lcm1602-parallel.cxx lcm1602)
|
||||
add_custom_example (jhd1313m1-lcd-example-cxx jhd1313m1-lcd.cxx jhd1313m1)
|
||||
add_custom_example (es08a-example-cxx es08a.cxx servo)
|
||||
add_custom_example (ssd1306-oled-example-cxx ssd1306-oled.cxx lcd)
|
||||
add_custom_example (ssd1308-oled-example-cxx ssd1308-oled.cxx lcd)
|
||||
add_custom_example (ssd1327-oled-example-cxx ssd1327-oled.cxx lcd)
|
||||
add_custom_example (eboled-example-cxx eboled.cxx lcd)
|
||||
add_custom_example (mpu60x0-example-cxx mpu60x0.cxx mpu9150)
|
||||
add_custom_example (ak8975-example-cxx ak8975.cxx mpu9150)
|
||||
add_custom_example (mpu9250-example-cxx mpu9250.cxx mpu9150)
|
||||
add_custom_example (groveledbar-example-cxx groveledbar.cxx my9221)
|
||||
add_custom_example (grovecircularled-example-cxx grovecircularled.cxx my9221)
|
||||
add_custom_example (temperature-sensor-example-cxx temperature-sensor.cxx "si7005;bmpx8x;bmp280")
|
||||
add_custom_example (humidity-sensor-example-cxx humidity-sensor.cxx "si7005;bmp280")
|
||||
add_custom_example (pressure-sensor-example-cxx pressure-sensor.cxx "bmpx8x;bmp280")
|
||||
add_custom_example (co2-sensor-example-cxx co2-sensor.cxx "t6713")
|
||||
add_custom_example (adc-example-cxx adc-sensor.cxx "ads1x15")
|
||||
add_custom_example (light-sensor-example-cxx light-sensor.cxx "si1132;max44009")
|
||||
add_custom_example (light-controller-example-cxx light-controller.cxx "lp8860;ds1808lc;hlg150h")
|
||||
add_custom_example (bme280-example-cxx bme280.cxx bmp280)
|
||||
add_custom_example (bmc150-example-cxx bmc150.cxx bmx055)
|
||||
add_custom_example (bmi055-example-cxx bmi055.cxx bmx055)
|
||||
if (OPENZWAVE_FOUND)
|
||||
include_directories(${OPENZWAVE_INCLUDE_DIRS})
|
||||
|
||||
add_custom_example (ozwdump-example-cxx ozwdump.cxx ozw)
|
||||
add_custom_example (aeotecss6-example-cxx aeotecss6.cxx ozw)
|
||||
add_custom_example (aeotecsdg2-example-cxx aeotecsdg2.cxx ozw)
|
||||
add_custom_example (aeotecdw2e-example-cxx aeotecdw2e.cxx ozw)
|
||||
add_custom_example (aeotecdsb09104-example-cxx aeotecdsb09104.cxx ozw)
|
||||
add_custom_example (tzemt400-example-cxx tzemt400.cxx ozw)
|
||||
endif()
|
||||
add_custom_example (nmea_gps_i2c_example-cxx nmea_gps_i2c.cxx nmea_gps)
|
||||
add_custom_example (mcp2515-txrx-example-cxx mcp2515-txrx.cxx mcp2515)
|
||||
add_custom_example (ads1015-example-cxx ads1015.cxx ads1x15)
|
||||
add_custom_example (le910-example-cxx le910.cxx uartat)
|
||||
add_custom_example (speaker_pwm-example-cxx speaker_pwm.cxx speaker)
|
||||
add_custom_example (ads1115-example-cxx ads1015.cxx ads1x15)
|
||||
# - Create an executable for all other src files in this directory -------------
|
||||
foreach (_example_src ${example_src_list})
|
||||
add_example(${_example_src})
|
||||
endforeach ()
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "adis16448.h"
|
||||
#include "adis16448.hpp"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
|
@ -1,172 +1,11 @@
|
||||
# Extract module name from non-standard example name
|
||||
macro(get_module_name example_name module_name)
|
||||
string(LENGTH ${example_name} length)
|
||||
string(FIND ${example_name} "-" index)
|
||||
if (${index} GREATER 1)
|
||||
string(SUBSTRING ${example_name} 0 ${index} substr)
|
||||
set(${module_name} ${substr})
|
||||
elseif (${example_name} MATCHES "^grove")
|
||||
set (${module_name} "grove")
|
||||
elseif ((${example_name} MATCHES "^mq" AND ${length} EQUAL 3) OR ${example_name} STREQUAL "tp401")
|
||||
set (${module_name} "gas")
|
||||
else()
|
||||
set(${module_name} ${example_name})
|
||||
endif()
|
||||
endmacro()
|
||||
# Create an list of all C source files in this directory
|
||||
file (GLOB example_src_list RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.c")
|
||||
|
||||
# Set source file, include and linker settings for an example
|
||||
# If example cannot be built, example_bin is cleared
|
||||
macro(add_custom_example example_bin example_src example_module_list)
|
||||
set(found_all_modules TRUE)
|
||||
foreach (module ${example_module_list})
|
||||
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/src/${module}")
|
||||
set(found_all_modules FALSE)
|
||||
endif()
|
||||
if (MODULE_LIST)
|
||||
list(FIND MODULE_LIST ${module} index)
|
||||
if (${index} EQUAL -1)
|
||||
set(found_all_modules FALSE)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
if (found_all_modules)
|
||||
add_executable (${example_bin} ${example_src})
|
||||
target_link_libraries (${example_bin} ${CMAKE_THREAD_LIBS_INIT})
|
||||
foreach (module ${example_module_list})
|
||||
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module}")
|
||||
include_directories (${module_dir})
|
||||
if (${module} STREQUAL "lcd")
|
||||
set(module "i2clcd")
|
||||
endif()
|
||||
target_link_libraries (${example_bin} ${module}-c)
|
||||
endforeach()
|
||||
else()
|
||||
message (WARNING "Ignored ${example_bin}")
|
||||
set (example_bin "")
|
||||
endif()
|
||||
endmacro()
|
||||
# - Handle special cases here --------------------------------------------------
|
||||
|
||||
#add_example(humidity-sensor.c TARGETS si7005-c bmp280-c)
|
||||
|
||||
# Add specified example by name
|
||||
# Note special case for grove based examples
|
||||
macro(add_example example_name)
|
||||
set(example_src "${example_name}.c")
|
||||
set(example_bin "${example_name}-example-c")
|
||||
get_module_name(${example_name} module_name)
|
||||
set(module_dir "${PROJECT_SOURCE_DIR}/src/${module_name}")
|
||||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${example_src}"
|
||||
AND EXISTS ${module_dir}
|
||||
AND IS_DIRECTORY ${module_dir})
|
||||
add_custom_example(${example_bin} ${example_src} ${module_name})
|
||||
if ((NOT ${example_bin} STREQUAL "") AND (${module_name} STREQUAL "grove"))
|
||||
set(grove_module_path "${PROJECT_SOURCE_DIR}/src/${example_name}")
|
||||
if (EXISTS ${grove_module_path})
|
||||
include_directories(${grove_module_path})
|
||||
target_link_libraries (${example_bin} ${example_name})
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
message (WARNING "Ignored ${example_bin}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
|
||||
|
||||
# UPM c include directories
|
||||
include_directories (${PROJECT_SOURCE_DIR}/include
|
||||
${CMAKE_SOURCE_DIR}/src/utilities)
|
||||
|
||||
# Set the mraa include and link directories prior to adding examples
|
||||
include_directories (${MRAA_INCLUDE_DIRS})
|
||||
link_directories (${MRAA_LIBDIR})
|
||||
|
||||
# If your sample source file matches the name of the module it tests, add it here
|
||||
# Exceptions are as follows:
|
||||
# string after first '-' is ignored (e.g. nrf24l01-transmitter maps to nrf24l01)
|
||||
# mq? will use module gas
|
||||
# grove* will use module grove
|
||||
add_example (dfrph)
|
||||
add_example (nmea_gps)
|
||||
add_example (mma7361)
|
||||
add_example (bh1750)
|
||||
add_example (urm37)
|
||||
add_example (urm37-uart)
|
||||
add_example (hka5)
|
||||
add_example (dfrorp)
|
||||
add_example (vdiv)
|
||||
add_example (mqx)
|
||||
add_example (o2)
|
||||
add_example (emg)
|
||||
add_example (gsr)
|
||||
add_example (light)
|
||||
add_example (ldt0028)
|
||||
add_example (joystick12)
|
||||
add_example (flex)
|
||||
add_example (slide)
|
||||
add_example (mq303a)
|
||||
add_example (m24lr64e)
|
||||
add_example (mpr121)
|
||||
add_example (servo)
|
||||
add_example (a110x)
|
||||
add_example (gp2y0a)
|
||||
add_example (ttp223)
|
||||
add_example (loudness)
|
||||
add_example (tsl2561)
|
||||
add_example (collision)
|
||||
add_example (moisture)
|
||||
add_example (led)
|
||||
add_example (ds18b20)
|
||||
add_example (dfrec)
|
||||
add_example (sht1x)
|
||||
add_example (water)
|
||||
add_example (yg1006)
|
||||
add_example (biss0001)
|
||||
add_example (bmi160)
|
||||
add_example (jhd1313m1)
|
||||
add_example (lm35)
|
||||
add_example (rotaryencoder)
|
||||
add_example (rpr220)
|
||||
add_example (md)
|
||||
add_example (linefinder)
|
||||
add_example (uln200xa)
|
||||
add_example (mma7660)
|
||||
add_example (buzzer)
|
||||
add_example (ppd42ns)
|
||||
add_example (guvas12d)
|
||||
add_example (otp538u)
|
||||
add_example (button)
|
||||
add_example (my9221)
|
||||
add_example (ms5803)
|
||||
add_example (ims)
|
||||
add_example (ecezo)
|
||||
add_example (mb704x)
|
||||
add_example (mcp2515)
|
||||
add_example (max30100)
|
||||
add_example (speaker)
|
||||
add_example (cjq4435)
|
||||
add_example (hmc5883l)
|
||||
add_example (wfs)
|
||||
add_example (enc03r)
|
||||
add_example (nunchuck)
|
||||
add_example (bno055)
|
||||
add_example (bmp280)
|
||||
add_example (abp)
|
||||
add_example (lcdks)
|
||||
add_example (bmg160)
|
||||
add_example (bma250e)
|
||||
add_example (bmm150)
|
||||
add_example (rsc)
|
||||
add_example (bmpx8x)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
add_custom_example (lcm1602-i2c-example-c lcm1602-i2c.c lcm1602)
|
||||
add_custom_example (lcm1602-parallel-example-c lcm1602-parallel.c lcm1602)
|
||||
add_custom_example (rpr220-intr-example-c rpr220-intr.c rpr220)
|
||||
add_custom_example (md-stepper-example-c md-stepper.c md)
|
||||
add_custom_example (button_intr-example-c button_intr.c button)
|
||||
add_custom_example (mcp2515-txrx-example-c mcp2515-txrx.c mcp2515)
|
||||
add_custom_example (le910-example-c le910.c uartat)
|
||||
add_custom_example (speaker_pwm-example-c speaker_pwm.c speaker)
|
||||
add_custom_example (bme280-example-c bme280.c bmp280)
|
||||
# - Create an executable for all other src files in this directory -------------
|
||||
foreach (_example_src ${example_src_list})
|
||||
add_example(${_example_src} SUFFIX "-c")
|
||||
endforeach ()
|
||||
|
@ -1,27 +0,0 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "grovemoisture.h"
|
||||
|
||||
#include "upm_utilities.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
grovemoisture_context dev = grovemoisture_init(14);
|
||||
int val;
|
||||
while(1){
|
||||
if(grovemoisture_get_moisture(dev, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Moisture Value: %d\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
grovemoisture_close(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -510,6 +510,11 @@ function (UPM_MIXED_MODULE_INIT)
|
||||
target_link_libraries (${libname} utilities-c)
|
||||
endif()
|
||||
|
||||
# Add include directories for C
|
||||
target_include_directories (${libname} PUBLIC
|
||||
${UPM_COMMON_HEADER_DIRS}
|
||||
${CMAKE_SOURCE_DIR}/src/utilities)
|
||||
|
||||
## "export" the logical C lib target for the calling module's
|
||||
## CMakeLists.txt
|
||||
set (libnamec ${libname} PARENT_SCOPE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user