cmake: add support for compile definitions for apps

With this we can pass build options to compiled app which is useful for integrating external projects
This commit is contained in:
raiden00pl 2023-07-25 21:06:12 +02:00 committed by Xiang Xiao
parent 9d7f349664
commit 5769952471

View File

@ -26,21 +26,32 @@ define_property(
BRIEF_DOCS "NuttX application libs"
FULL_DOCS "List of all NuttX application libraries")
# ~~~
# nuttx_add_application
#
# Description: Declares a NuttX application as a static library. The
# corresponding target will be named apps_<NAME>. The first entry into the
# source list is assumed to be the one containing main() and will thus receive a
# -Dmain=app_main definition during build.
# Description:
# Declares a NuttX application as a static library. The corresponding target
# will be named apps_<NAME>. The first entry into the source list is assumed
# to be the one containing main() and will thus receive a -Dmain=app_main
# definition during build.
#
# Usage: nuttx_add_application( NAME <string> [ PRIORITY <string> ] [ STACKSIZE
# <string> ] [ COMPILE_FLAGS <list> ] [ INCLUDE_DIRECTORIES <list> ] [ DEPENDS
# <string> ] [ MODULE <string> ] [ SRCS <list> ] )
# Usage:
# nuttx_add_application( NAME <string> [ PRIORITY <string> ]
# [ STACKSIZE <string> ] [ COMPILE_FLAGS <list> ]
# [ INCLUDE_DIRECTORIES <list> ] [ DEPENDS <string> ]
# [ DEFINITIONS <string> ] [ MODULE <string> ] [ SRCS <list> ] )
#
# Parameters: NAME : unique name of application PRIORITY :
# priority STACKSIZE : stack size COMPILE_FLAGS : compile flags SRCS :
# source files MODULE : if "m", build module (designed to received
# CONFIG_<app> value) DEPENDS : targets which this module depends on
# Parameters:
# NAME : unique name of application
# PRIORITY : priority
# STACKSIZE : stack size
# COMPILE_FLAGS : compile flags
# INCLUDE_DIRECTORIES : include directories
# DEPENDS : targets which this module depends on
# DEFINITIONS : optional compile definitions
# MODULE : if "m", build module (designed to received
# CONFIG_<app> value)
# SRCS : source files
# NO_MAIN_ALIAS : do not add a main=<app>_main alias(*)
#
# (*) This is only really needed in convoluted cases where a single .c file
@ -48,8 +59,14 @@ define_property(
# situation should really be changed into a separate main file per actual app
# using a shared user library.
#
# Example: nuttx_add_application( NAME test SRCS file.cpp STACKSIZE 1024 DEPENDS
# nshlib MODULE ${CONFIG_EXAMPLES_TEST} )
# Example:
# nuttx_add_application(
# NAME test
# SRCS file.cpp
# STACKSIZE 1024
# DEPENDS nshlib
# MODULE ${CONFIG_EXAMPLES_TEST})
# ~~~
function(nuttx_add_application)
@ -68,6 +85,7 @@ function(nuttx_add_application)
INCLUDE_DIRECTORIES
SRCS
DEPENDS
DEFINITIONS
OPTIONS
NO_MAIN_ALIAS
REQUIRED
@ -170,6 +188,12 @@ function(nuttx_add_application)
target_compile_options(${TARGET} PRIVATE ${COMPILE_FLAGS})
endif()
# compile definitions
if(DEFINITIONS)
target_compile_definitions(${TARGET} PRIVATE ${DEFINITIONS})
endif()
if(INCLUDE_DIRECTORIES)
foreach(inc ${INCLUDE_DIRECTORIES})
target_include_directories(${TARGET} PRIVATE ${inc})