upm/examples/c/CMakeLists.txt
Jon Trulson c57a0d2c30 bmpx8x: rewrite in C; FTI; C++ wraps C
This driver has been rewritten from scratch.

See docs/apichanges.md for a list of API compatibility changes
compared to the original driver.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
2017-04-05 11:29:08 -06:00

173 lines
5.2 KiB
CMake

# 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)
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()
# 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)