mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
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:
@@ -26,30 +26,47 @@ define_property(
|
|||||||
BRIEF_DOCS "NuttX application libs"
|
BRIEF_DOCS "NuttX application libs"
|
||||||
FULL_DOCS "List of all NuttX application libraries")
|
FULL_DOCS "List of all NuttX application libraries")
|
||||||
|
|
||||||
|
# ~~~
|
||||||
# nuttx_add_application
|
# nuttx_add_application
|
||||||
#
|
#
|
||||||
# Description: Declares a NuttX application as a static library. The
|
# Description:
|
||||||
# corresponding target will be named apps_<NAME>. The first entry into the
|
# Declares a NuttX application as a static library. The corresponding target
|
||||||
# source list is assumed to be the one containing main() and will thus receive a
|
# will be named apps_<NAME>. The first entry into the source list is assumed
|
||||||
# -Dmain=app_main definition during build.
|
# 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
|
# Usage:
|
||||||
# <string> ] [ COMPILE_FLAGS <list> ] [ INCLUDE_DIRECTORIES <list> ] [ DEPENDS
|
# nuttx_add_application( NAME <string> [ PRIORITY <string> ]
|
||||||
# <string> ] [ MODULE <string> ] [ SRCS <list> ] )
|
# [ STACKSIZE <string> ] [ COMPILE_FLAGS <list> ]
|
||||||
|
# [ INCLUDE_DIRECTORIES <list> ] [ DEPENDS <string> ]
|
||||||
|
# [ DEFINITIONS <string> ] [ MODULE <string> ] [ SRCS <list> ] )
|
||||||
#
|
#
|
||||||
# Parameters: NAME : unique name of application PRIORITY :
|
# Parameters:
|
||||||
# priority STACKSIZE : stack size COMPILE_FLAGS : compile flags SRCS :
|
# NAME : unique name of application
|
||||||
# source files MODULE : if "m", build module (designed to received
|
# PRIORITY : priority
|
||||||
# CONFIG_<app> value) DEPENDS : targets which this module depends on
|
# STACKSIZE : stack size
|
||||||
# NO_MAIN_ALIAS : do not add a main=<app>_main alias(*)
|
# 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
|
# (*) This is only really needed in convoluted cases where a single .c file
|
||||||
# contains differently named <app>_main() entries for different <app>. This
|
# contains differently named <app>_main() entries for different <app>. This
|
||||||
# situation should really be changed into a separate main file per actual app
|
# situation should really be changed into a separate main file per actual app
|
||||||
# using a shared user library.
|
# using a shared user library.
|
||||||
#
|
#
|
||||||
# Example: nuttx_add_application( NAME test SRCS file.cpp STACKSIZE 1024 DEPENDS
|
# Example:
|
||||||
# nshlib MODULE ${CONFIG_EXAMPLES_TEST} )
|
# nuttx_add_application(
|
||||||
|
# NAME test
|
||||||
|
# SRCS file.cpp
|
||||||
|
# STACKSIZE 1024
|
||||||
|
# DEPENDS nshlib
|
||||||
|
# MODULE ${CONFIG_EXAMPLES_TEST})
|
||||||
|
# ~~~
|
||||||
|
|
||||||
function(nuttx_add_application)
|
function(nuttx_add_application)
|
||||||
|
|
||||||
@@ -68,6 +85,7 @@ function(nuttx_add_application)
|
|||||||
INCLUDE_DIRECTORIES
|
INCLUDE_DIRECTORIES
|
||||||
SRCS
|
SRCS
|
||||||
DEPENDS
|
DEPENDS
|
||||||
|
DEFINITIONS
|
||||||
OPTIONS
|
OPTIONS
|
||||||
NO_MAIN_ALIAS
|
NO_MAIN_ALIAS
|
||||||
REQUIRED
|
REQUIRED
|
||||||
@@ -170,6 +188,12 @@ function(nuttx_add_application)
|
|||||||
target_compile_options(${TARGET} PRIVATE ${COMPILE_FLAGS})
|
target_compile_options(${TARGET} PRIVATE ${COMPILE_FLAGS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# compile definitions
|
||||||
|
|
||||||
|
if(DEFINITIONS)
|
||||||
|
target_compile_definitions(${TARGET} PRIVATE ${DEFINITIONS})
|
||||||
|
endif()
|
||||||
|
|
||||||
if(INCLUDE_DIRECTORIES)
|
if(INCLUDE_DIRECTORIES)
|
||||||
foreach(inc ${INCLUDE_DIRECTORIES})
|
foreach(inc ${INCLUDE_DIRECTORIES})
|
||||||
target_include_directories(${TARGET} PRIVATE ${inc})
|
target_include_directories(${TARGET} PRIVATE ${inc})
|
||||||
@@ -183,7 +207,7 @@ function(nuttx_add_application)
|
|||||||
# interface include and libraries
|
# interface include and libraries
|
||||||
foreach(dep ${DEPENDS})
|
foreach(dep ${DEPENDS})
|
||||||
get_target_property(dep_type ${dep} TYPE)
|
get_target_property(dep_type ${dep} TYPE)
|
||||||
if (${dep_type} STREQUAL "STATIC_LIBRARY")
|
if(${dep_type} STREQUAL "STATIC_LIBRARY")
|
||||||
target_link_libraries(${TARGET} PRIVATE ${dep})
|
target_link_libraries(${TARGET} PRIVATE ${dep})
|
||||||
else()
|
else()
|
||||||
add_dependencies(${TARGET} ${dep})
|
add_dependencies(${TARGET} ${dep})
|
||||||
|
|||||||
Reference in New Issue
Block a user