2016-08-17 17:58:21 -07:00
|
|
|
# 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()
|
|
|
|
|
|
|
|
# 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)
|
2016-11-17 16:20:29 -08:00
|
|
|
list(FIND MODULE_LIST ${module} index)
|
2016-08-17 17:58:21 -07:00
|
|
|
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()
|
2016-09-01 16:32:49 -07:00
|
|
|
target_link_libraries (${example_bin} ${module}-c)
|
2016-08-17 17:58:21 -07:00
|
|
|
endforeach()
|
|
|
|
else()
|
2016-09-05 21:57:41 -07:00
|
|
|
message (WARNING "Ignored ${example_bin}")
|
|
|
|
set (example_bin "")
|
2016-08-17 17:58:21 -07:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
|
|
|
# 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()
|
2016-09-05 21:57:41 -07:00
|
|
|
message (WARNING "Ignored ${example_bin}")
|
2016-08-17 17:58:21 -07:00
|
|
|
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)
|
2016-08-25 13:54:49 -06:00
|
|
|
add_example (nmea_gps)
|
2016-08-24 15:43:11 -06:00
|
|
|
add_example (mma7361)
|
2016-08-24 15:53:46 -06:00
|
|
|
add_example (bh1750)
|
2016-08-24 16:04:56 -06:00
|
|
|
add_example (urm37)
|
|
|
|
add_example (urm37-uart)
|
2016-08-29 17:42:54 -06:00
|
|
|
add_example (hka5)
|
2016-08-31 18:22:24 -06:00
|
|
|
add_example (dfrorp)
|
2016-09-01 16:32:49 -07:00
|
|
|
add_example (vdiv)
|
2016-09-06 08:40:37 -07:00
|
|
|
add_example (mqx)
|
2016-09-07 10:18:06 -07:00
|
|
|
add_example (o2)
|
2016-09-08 12:35:41 -07:00
|
|
|
add_example (emg)
|
2016-09-08 13:55:23 -07:00
|
|
|
add_example (gsr)
|
2016-09-09 14:10:30 -07:00
|
|
|
add_example (light)
|
2016-09-09 14:57:33 -07:00
|
|
|
add_example (ldt0028)
|
2016-09-09 16:17:48 -07:00
|
|
|
add_example (joystick12)
|
2016-09-09 16:24:35 -07:00
|
|
|
add_example (flex)
|
2016-09-09 17:21:03 -07:00
|
|
|
add_example (slide)
|
2016-09-09 19:19:35 -07:00
|
|
|
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)
|
2016-09-12 14:37:53 -07:00
|
|
|
add_example (collision)
|
2016-09-12 15:25:45 -07:00
|
|
|
add_example (moisture)
|
2016-09-12 16:16:30 -07:00
|
|
|
add_example (led)
|
2016-09-13 11:27:27 -06:00
|
|
|
add_example (ds18b20)
|
2016-09-13 11:31:33 -06:00
|
|
|
add_example (dfrec)
|
2016-09-16 16:50:09 -06:00
|
|
|
add_example (sht1x)
|
2016-09-22 16:42:16 -06:00
|
|
|
add_example (water)
|
2016-09-23 12:19:27 -06:00
|
|
|
add_example (yg1006)
|
2016-09-23 14:17:42 -06:00
|
|
|
add_example (biss0001)
|
2016-09-27 16:39:09 -06:00
|
|
|
add_example (bmi160)
|
2016-10-07 15:39:39 -06:00
|
|
|
add_example (jhd1313m1)
|
2016-10-12 16:36:08 -06:00
|
|
|
add_example (lm35)
|
2016-10-13 15:58:44 -06:00
|
|
|
add_example (rotaryencoder)
|
2016-10-14 13:53:00 -06:00
|
|
|
add_example (rpr220)
|
2016-10-18 17:02:33 -06:00
|
|
|
add_example (md)
|
2016-10-21 13:43:36 -06:00
|
|
|
add_example (linefinder)
|
2016-10-24 16:04:51 -06:00
|
|
|
add_example (uln200xa)
|
2016-10-27 15:12:26 -06:00
|
|
|
add_example (mma7660)
|
2016-10-28 16:47:01 -06:00
|
|
|
add_example (buzzer)
|
2016-11-02 17:38:44 -06:00
|
|
|
add_example (ppd42ns)
|
2016-11-04 12:51:42 -06:00
|
|
|
add_example (guvas12d)
|
2016-11-07 13:53:11 -07:00
|
|
|
add_example (otp538u)
|
2016-11-08 12:14:32 -08:00
|
|
|
add_example (button)
|
2016-11-08 17:11:25 -07:00
|
|
|
add_example (my9221)
|
2016-11-11 17:41:28 -07:00
|
|
|
add_example (ms5803)
|
2016-11-17 16:20:29 -08:00
|
|
|
add_example (ims)
|
2016-11-18 17:32:34 -07:00
|
|
|
add_example (ecezo)
|
2016-12-02 16:42:33 -07:00
|
|
|
add_example (mb704x)
|
2016-11-10 11:55:48 -07:00
|
|
|
add_example (mcp2515)
|
2016-12-08 15:24:36 -08:00
|
|
|
add_example (max30100)
|
2017-01-19 13:54:21 -07:00
|
|
|
add_example (speaker)
|
2017-01-20 12:01:31 -07:00
|
|
|
add_example (cjq4435)
|
2017-01-25 17:37:29 -07:00
|
|
|
add_example (hmc5883l)
|
2017-01-26 15:06:05 -07:00
|
|
|
add_example (wfs)
|
2017-01-27 17:58:35 -07:00
|
|
|
add_example (enc03r)
|
2017-01-31 13:06:26 -07:00
|
|
|
add_example (nunchuck)
|
2016-08-26 16:34:13 -06:00
|
|
|
|
|
|
|
# Custom examples
|
|
|
|
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
2016-10-06 13:28:05 -06:00
|
|
|
add_custom_example (lcm1602-i2c-example-c lcm1602-i2c.c lcm1602)
|
|
|
|
add_custom_example (lcm1602-parallel-example-c lcm1602-parallel.c lcm1602)
|
2016-10-14 13:53:00 -06:00
|
|
|
add_custom_example (rpr220-intr-example-c rpr220-intr.c rpr220)
|
2016-10-18 17:02:33 -06:00
|
|
|
add_custom_example (md-stepper-example-c md-stepper.c md)
|
2016-11-29 11:57:40 -07:00
|
|
|
add_custom_example (button_intr-example-c button_intr.c button)
|
2016-11-10 11:55:48 -07:00
|
|
|
add_custom_example (mcp2515-txrx-example-c mcp2515-txrx.c mcp2515)
|
2017-01-17 11:37:14 -07:00
|
|
|
add_custom_example (le910-example-c le910.c uartat)
|
2017-02-01 17:03:10 -07:00
|
|
|
add_custom_example (speaker_pwm-example-c speaker_pwm.c speaker)
|