build: add initial cmake build system

1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an
2023-02-07 14:15:30 +08:00
committed by Xiang Xiao
parent 558fa503d0
commit 6ee9ec7656
317 changed files with 17032 additions and 1 deletions
+115
View File
@@ -0,0 +1,115 @@
# ##############################################################################
# cmake/menuconfig.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
# menuconfig target this triggers a reconfiguration (TODO: do only if config
# changes)
set(KCONFIG_ENV
"KCONFIG_CONFIG=${CMAKE_BINARY_DIR}/.config"
"EXTERNALDIR=dummy"
"APPSDIR=${NUTTX_APPS_DIR}"
"DRIVERS_PLATFORM_DIR=dummy"
"APPSBINDIR=${NUTTX_APPS_BINDIR}"
"BINDIR=${CMAKE_BINARY_DIR}"
"HOST_LINUX=$<IF:$<BOOL:{LINUX}>,y,n>"
"HOST_MACOS=$<IF:$<BOOL:${APPLE}>,y,n>"
"HOST_WINDOWS=$<IF:$<BOOL:${WIN32}>,y,n>"
"HOST_OTHER=$<IF:$<BOOL:${OTHER_OS}>,y,n>")
# Use qconfig instead of menuconfig since PowerShell not support curses
# redirection
if(WIN32)
set(MENUCONFIG guiconfig)
else()
set(MENUCONFIG menuconfig)
endif()
add_custom_target(
menuconfig
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} ${MENUCONFIG}
COMMAND ${CMAKE_COMMAND} -E remove -f
${CMAKE_BINARY_DIR}/include/nuttx/config.h # invalidate existing
# config
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_PARENT_LIST_FILE}
WORKING_DIRECTORY ${NUTTX_DIR}
USES_TERMINAL)
# qconfig target
add_custom_target(
qconfig
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} guiconfig
COMMAND ${CMAKE_COMMAND} -E remove -f
${CMAKE_BINARY_DIR}/include/nuttx/config.h # invalidate existing
# config
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_PARENT_LIST_FILE}
WORKING_DIRECTORY ${NUTTX_DIR}
USES_TERMINAL)
add_custom_target(
savedefconfig
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} savedefconfig --out
${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND grep "CONFIG_ARCH=" ${CMAKE_BINARY_DIR}/.config >>
${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND grep "^CONFIG_ARCH_CHIP_" ${CMAKE_BINARY_DIR}/.config >>
${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND grep "CONFIG_ARCH_CHIP=" ${CMAKE_BINARY_DIR}/.config >>
${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND grep "CONFIG_ARCH_BOARD=" ${CMAKE_BINARY_DIR}/.config >>
${CMAKE_BINARY_DIR}/defconfig.tmp || true
COMMAND grep "^CONFIG_ARCH_CUSTOM" ${CMAKE_BINARY_DIR}/.config >>
${CMAKE_BINARY_DIR}/defconfig.tmp || true
COMMAND grep "^CONFIG_ARCH_BOARD_CUSTOM" ${CMAKE_BINARY_DIR}/.config >>
${CMAKE_BINARY_DIR}/defconfig.tmp || true
COMMAND export LC_ALL=C && cat ${CMAKE_BINARY_DIR}/defconfig.tmp | sort | uniq
> ${CMAKE_BINARY_DIR}/sortedconfig.tmp || true
COMMAND echo "\\#" > ${CMAKE_BINARY_DIR}/warning.tmp || true
COMMAND echo "\\# This file is autogenerated: PLEASE DO NOT EDIT IT." >>
${CMAKE_BINARY_DIR}/warning.tmp
COMMAND echo "\\#" >> ${CMAKE_BINARY_DIR}/warning.tmp
COMMAND
echo
"\\# You can use make menuconfig to make any modifications to the installed .config file."
>> ${CMAKE_BINARY_DIR}/warning.tmp
COMMAND
echo
"\\# You can then do make savedefconfig or cmake -t savedefconfig to generate a new defconfig file that includes your"
>> ${CMAKE_BINARY_DIR}/warning.tmp
COMMAND echo "\\# modifications." >> ${CMAKE_BINARY_DIR}/warning.tmp
COMMAND echo "\\#" >> ${CMAKE_BINARY_DIR}/warning.tmp
COMMAND cat ${CMAKE_BINARY_DIR}/warning.tmp
${CMAKE_BINARY_DIR}/sortedconfig.tmp > ${CMAKE_BINARY_DIR}/defconfig
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/warning.tmp
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/defconfig.tmp
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_BINARY_DIR}/sortedconfig.tmp
WORKING_DIRECTORY ${NUTTX_DIR})
# utility target to restore .config from board's defconfig
add_custom_target(
resetconfig
COMMAND ${CMAKE_COMMAND} -E copy ${NUTTX_DEFCONFIG}
${CMAKE_BINARY_DIR}/.config
COMMAND ${CMAKE_COMMAND} -E env ${KCONFIG_ENV} olddefconfig
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/.config
${CMAKE_BINARY_DIR}/.config.orig
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_PARENT_LIST_FILE}
WORKING_DIRECTORY ${NUTTX_DIR})
+192
View File
@@ -0,0 +1,192 @@
# ##############################################################################
# cmake/nuttx_add_application.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
include(nuttx_parse_function_args)
define_property(
GLOBAL
PROPERTY NUTTX_APPS_LIBRARIES
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.
#
# Usage: nuttx_add_application( NAME <string> [ PRIORITY <string> ] [ STACKSIZE
# <string> ] [ COMPILE_FLAGS <list> ] [ INCLUDE_DIRECTORIES <list> ] [ DEPENDS
# <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
# NO_MAIN_ALIAS : do not add a main=<app>_main alias(*)
#
# (*) This is only really needed in convoluted cases where a single .c file
# contains differently named <app>_main() entries for different <app>. This
# 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} )
function(nuttx_add_application)
# parse arguments into variables
nuttx_parse_function_args(
FUNC
nuttx_add_application
ONE_VALUE
NAME
PRIORITY
STACKSIZE
MODULE
MULTI_VALUE
COMPILE_FLAGS
INCLUDE_DIRECTORIES
SRCS
DEPENDS
OPTIONS
NO_MAIN_ALIAS
REQUIRED
NAME
ARGN
${ARGN})
# create target
if(SRCS)
if(MODULE
AND ("${MODULE}" STREQUAL "m")
OR CONFIG_BUILD_KERNEL)
# create as standalone executable (loadable application or "module")
set(TARGET "${NAME}")
# Use ELF capable toolchain, by building manually and overwriting the
# non-elf output
if(NOT CMAKE_C_ELF_COMPILER)
add_library(${TARGET} ${SRCS})
add_custom_command(
TARGET ${TARGET}
POST_BUILD
COMMAND
${CMAKE_C_COMPILER}
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_APP_LINK_OPTIONS>>
$<TARGET_FILE:${TARGET}> -o ${TARGET}
COMMAND_EXPAND_LISTS)
else()
add_executable(${TARGET} ${SRCS})
target_link_options(
${TARGET} PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_APP_LINK_OPTIONS>>)
endif()
# easy access to final ELF, regardless of how it was created
set_property(TARGET ${TARGET}
PROPERTY ELF_BINARY ${CMAKE_CURRENT_BINARY_DIR}/${TARGET})
nuttx_add_library_internal(${TARGET})
install(TARGETS ${TARGET})
set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_LOADABLE_APPS ${TARGET})
else()
# create as library to be archived into libapps.a
set(TARGET "apps_${NAME}")
add_library(${TARGET} ${SRCS})
nuttx_add_library_internal(${TARGET})
# add to list of application libraries
set_property(GLOBAL APPEND PROPERTY NUTTX_APPS_LIBRARIES ${TARGET})
if(NOT NO_MAIN_ALIAS)
# provide main() alias
list(GET SRCS 0 MAIN_SRC)
set_property(
SOURCE ${MAIN_SRC}
APPEND
PROPERTY COMPILE_DEFINITIONS main=${NAME}_main)
endif()
endif()
# loadable build requires applying ELF flags to all applications
if(CONFIG_BUILD_LOADABLE)
target_compile_options(
${TARGET}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_APP_COMPILE_OPTIONS>>)
endif()
endif()
# store parameters into properties (used during builtin list generation)
set_target_properties(${TARGET} PROPERTIES APP_MAIN ${NAME}_main)
set_target_properties(${TARGET} PROPERTIES APP_NAME ${NAME})
if(PRIORITY)
set_target_properties(${TARGET} PROPERTIES APP_PRIORITY ${PRIORITY})
else()
set_target_properties(${TARGET} PROPERTIES APP_PRIORITY
SCHED_PRIORITY_DEFAULT)
endif()
if(STACKSIZE)
set_target_properties(${TARGET} PROPERTIES APP_STACK ${STACKSIZE})
else()
set_target_properties(${TARGET} PROPERTIES APP_STACK
${CONFIG_DEFAULT_TASK_STACKSIZE})
endif()
# compile options
if(COMPILE_FLAGS)
target_compile_options(${TARGET} PRIVATE ${COMPILE_FLAGS})
endif()
if(INCLUDE_DIRECTORIES)
foreach(inc ${INCLUDE_DIRECTORIES})
target_include_directories(${TARGET} PRIVATE ${inc})
endforeach()
endif()
# add supplied dependencies
if(DEPENDS)
# using target_link_libraries for dependencies provides linking as well as
# interface include and libraries
foreach(dep ${DEPENDS})
get_target_property(dep_type ${dep} TYPE)
# if (${dep_type} STREQUAL "STATIC_LIBRARY")
# target_link_libraries(${TARGET} PRIVATE ${dep}) else()
add_dependencies(${TARGET} ${dep})
# endif()
endforeach()
endif()
endfunction()
+177
View File
@@ -0,0 +1,177 @@
# ##############################################################################
# cmake/nuttx_add_library.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
# Internal utility function
#
# Used by functions below, not to be used directly
function(nuttx_add_library_internal target)
# ensure nuttx_context is created before this
add_dependencies(${target} nuttx_context)
# add main include directories
target_include_directories(
${target} SYSTEM
PUBLIC ${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/include
${CMAKE_BINARY_DIR}/include_arch)
# Set global compile options & definitions We use the "nuttx" target to hold
# these properties so that libraries added after this property is set can read
# the final value at build time. The GENEX_EVAL allows the property to hold
# generator expression itself
target_compile_options(
${target}
PRIVATE $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_COMPILE_OPTIONS>>)
target_compile_definitions(
${target} PRIVATE $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_DEFINITIONS>>)
target_include_directories(
${target}
PRIVATE $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_INCLUDE_DIRECTORIES>>)
endfunction()
# Auxiliary libraries
#
# The whole purpose of this is to overcome the limitation of CMake 3.16 to set
# source file properties from directories different from the one defining the
# target where the source file is used. This auxiliary library acts as an
# intermediate target that is usually linked to the system/kernel library
# defined at a higher level.
function(nuttx_add_aux_library target)
# declare target
add_library(${target} OBJECT ${ARGN})
nuttx_add_library_internal(${target} ${ARGN})
endfunction()
# User (application) libraries
#
# An user library is a target which is defined as a collection of object files
# which is ultimately archived into the apps library
function(nuttx_add_user_library target)
# declare target
add_library(${target} OBJECT ${ARGN})
nuttx_add_library_internal(${target} ${ARGN})
# link to final libapps
target_link_libraries(apps INTERFACE ${target})
# add apps/include to include path
target_include_directories(${target} INTERFACE ${NUTTX_APPS_DIR}/include)
endfunction()
# System Libraries
#
# A system library is a library which is built into the OS but does not receive
# kernel-level flags (such as __KERNEL__). This is will be part of the userspace
# blob in kernel builds
function(nuttx_add_system_library target)
# declare target
add_library(${target} ${ARGN})
# add library to build
nuttx_add_library_internal(${target} ${ARGN})
# add to list of libraries to link to final nuttx binary
set_property(GLOBAL APPEND PROPERTY NUTTX_SYSTEM_LIBRARIES ${target})
# install to library dir
install(TARGETS ${target} DESTINATION lib)
endfunction()
# Kernel Libraries
#
# nuttx_add_kernel_library(target [SPLIT] [SAME_SOURCES] [sources ...])
#
# For non-kernel builds, this defines an OS library which will receive
# kernel-level flags (such as __KERNEL__) and will be linked into nuttx binary
# For kernel builds, the same happens unless SPLIT is specified. In this case
# both a <target> and a k<target> library will be defined, but only the latter
# having the kernel-level flags. In this case, both libraries will receive the
# same set of sources (the original <target> should be used by the user to add
# sources).
function(nuttx_add_kernel_library target)
cmake_parse_arguments(ARGS SPLIT "" "" ${ARGN})
set(SRCS ${ARGS_UNPARSED_ARGUMENTS})
if(ARGS_SPLIT AND NOT CONFIG_BUILD_FLAT)
set(kernel_target k${target})
# add non-kernel (system) library
nuttx_add_system_library(${target} ${SRCS})
else()
set(kernel_target ${target})
endif()
# add kernel library
add_library(${kernel_target} ${SRCS})
nuttx_add_library_internal(${kernel_target} ${SRCS})
set_property(GLOBAL APPEND PROPERTY NUTTX_KERNEL_LIBRARIES ${kernel_target})
# Add kernel options & definitions See note above in
# nuttx_add_library_internal() on syntax and nuttx target use
target_compile_options(
${kernel_target}
PRIVATE $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_KERNEL_COMPILE_OPTIONS>>)
target_compile_definitions(
${kernel_target}
PRIVATE $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_KERNEL_DEFINITIONS>>)
target_include_directories(
${kernel_target}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_KERNEL_INCLUDE_DIRECTORIES>>)
if(NOT "${target}" STREQUAL "${kernel_target}")
# The k${target} lib will have the same sources added to that ${target} lib.
# This allows to do target_sources(${target} ..) easily
target_sources(${kernel_target}
PRIVATE $<TARGET_PROPERTY:${target},SOURCES>)
# same for include directories
target_include_directories(
${kernel_target} PRIVATE $<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>)
endif()
endfunction()
include(nuttx_parse_function_args)
define_property(
GLOBAL
PROPERTY NUTTX_LIBRARIES
BRIEF_DOCS "NuttX libs"
FULL_DOCS "List of all NuttX libraries")
# =============================================================================
#
# nuttx_add_library
#
# Wrapper of cmake add_library but with nuttx platform dependencies
#
function(nuttx_add_library target)
add_library(${target} ${ARGN})
set_property(GLOBAL APPEND PROPERTY NUTTX_EXTRA_LIBRARIES ${target})
nuttx_add_library_internal(${target})
endfunction()
+57
View File
@@ -0,0 +1,57 @@
# ##############################################################################
# cmake/nuttx_add_module.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
function(nuttx_add_module target)
# Use ELF capable toolchain, by building manually and overwriting the non-elf
# output
if(CMAKE_C_ELF_COMPILER)
add_library(${target} ${ARGN})
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND
${CMAKE_C_ELF_COMPILER}
$<TARGET_PROPERTY:nuttx,NUTTX_ELF_MODULE_LINK_OPTIONS>
$<TARGET_FILE:${target}> -o ${target}
COMMAND_EXPAND_LISTS)
else()
add_executable(${target} ${ARGN})
target_link_options(
${target} PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_MODULE_LINK_OPTIONS>>)
endif()
set_property(TARGET ${target} PROPERTY ELF_BINARY
${CMAKE_CURRENT_BINARY_DIR}/${target})
nuttx_add_library_internal(${target})
target_compile_options(
${target}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_MODULE_COMPILE_OPTIONS>>)
target_compile_definitions(
${target}
PRIVATE $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_MODULE_DEFINITIONS>>
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_KERNEL_DEFINITIONS>>)
install(TARGETS ${target})
endfunction()
+158
View File
@@ -0,0 +1,158 @@
# ##############################################################################
# cmake/nuttx_add_romfs.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
# nuttx_add_romfs Generates a ROMFS image in a C array, which is built to an
# OBJECT library.
#
# Parameters: - NAME: determines the romfs label and name of target
# (romfs_${NAME}) - HEADER: option to indicate that a .h file is to be generated
# instead of a .c - PREFIX: optional prefix to add to image name (as
# romfs_${PREFIX}.img) - NONCONST: option to indicate the array should be
# non-const - DEPENDS: list of targets that should be depended on
function(nuttx_add_romfs)
nuttx_parse_function_args(
FUNC
nuttx_add_romfs
ONE_VALUE
NAME
MOUNTPOINT
PATH
PREFIX
OPTIONS
HEADER
NONCONST
MULTI_VALUE
DEPENDS
RCSRCS
RCRAWS
REQUIRED
NAME
ARGN
${ARGN})
if(NOT PATH AND NOT FILES)
message(FATAL_ERROR "Either PATH or FILES must be specified")
endif()
foreach(rcsrc ${RCSRCS})
get_filename_component(rcpath ${rcsrc} DIRECTORY)
add_custom_command(
OUTPUT ${rcsrc}
COMMAND ${CMAKE_COMMAND} -E make_directory ${rcpath}
COMMAND
${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -E -P -x c
-I${CMAKE_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/${rcsrc} >
${rcsrc}
DEPENDS nuttx_context ${CMAKE_CURRENT_SOURCE_DIR}/${rcsrc})
list(APPEND DEPENDS ${rcsrc})
endforeach()
foreach(rcraw ${RCRAWS})
get_filename_component(absrcraw ${rcraw} ABSOLUTE)
if(IS_DIRECTORY ${absrcraw})
file(
GLOB subdir
LIST_DIRECTORIES false
${rcraws} ${rcraw})
foreach(rcraw ${rcraws})
list(APPEND DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${rcraw})
configure_file(${rcraw} ${CMAKE_CURRENT_BINARY_DIR}/${rcraw} COPYONLY)
endforeach()
else()
list(APPEND DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${rcraw})
configure_file(${rcraw} ${CMAKE_CURRENT_BINARY_DIR}/${rcraw} COPYONLY)
endif()
endforeach()
if(HEADER)
set(EXTENSION h)
else()
set(EXTENSION c)
endif()
if(PREFIX)
set(IMGNAME ${PREFIX}.img)
else()
set(IMGNAME romfs.img)
endif()
add_custom_command(
OUTPUT romfs_${NAME}.${EXTENSION}
COMMAND ${CMAKE_COMMAND} -E make_directory romfs_${NAME}
COMMAND if \[ \"${PATH}\" != \"\" \]; then ${CMAKE_COMMAND} -E
copy_directory ${PATH} romfs_${NAME} \; fi
COMMAND genromfs -f ${IMGNAME} -d romfs_${NAME} -V ${NAME}
COMMAND xxd -i ${IMGNAME} romfs_${NAME}.${EXTENSION}
COMMAND ${CMAKE_COMMAND} -E remove ${IMGNAME}
COMMAND ${CMAKE_COMMAND} -E remove_directory romfs_${NAME}
COMMAND if ! [ -z "${NONCONST}" ]\; then sed -E -i'' -e
"s/^unsigned/const unsigned/g" romfs_${NAME}.${EXTENSION} \; fi
DEPENDS ${DEPENDS})
if(NOT HEADER)
add_custom_target(target-romfs DEPENDS ${DEPENDS})
nuttx_add_aux_library(romfs_${NAME})
target_sources(romfs_${NAME} PRIVATE romfs_${NAME}.${EXTENSION})
add_dependencies(romfs_${NAME} target-romfs)
endif()
endfunction()
# nuttx_add_cromfs Generates a CROMFS image in a C array, which is built to an
# OBJECT library.
#
# Parameters: - NAME: determines the name of target (cromfs_${NAME}) - PATH: the
# directory that will be used to create the CROMFS - FILES: paths to files to
# copy into CROMFS - DEPENDS: list of targets that should be depended on
function(nuttx_add_cromfs)
nuttx_parse_function_args(
FUNC
nuttx_add_cromfs
ONE_VALUE
NAME
MOUNTPOINT
PATH
MULTI_VALUE
DEPENDS
FILES
OPTIONS
REQUIRED
NAME
ARGN
${ARGN})
if(NOT PATH AND NOT FILES)
message(FATAL_ERROR "Either PATH or FILES must be specified")
endif()
add_custom_command(
OUTPUT cromfs_${NAME}.c
COMMAND ${CMAKE_COMMAND} -E make_directory cromfs_${NAME}
COMMAND if \[ \"${PATH}\" != \"\" \]; then ${CMAKE_COMMAND} -E
copy_directory ${PATH} cromfs_${NAME} \; fi
COMMAND if \[ \"${FILES}\" != \"\" \]; then ${CMAKE_COMMAND} -E copy
${FILES} cromfs_${NAME} \; fi
COMMAND ${CMAKE_BINARY_DIR}/bin/gencromfs cromfs_${NAME} cromfs_${NAME}.c
DEPENDS ${DEPENDS})
add_library(cromfs_${NAME} OBJECT cromfs_${NAME}.c)
nuttx_add_library_internal(cromfs_${NAME})
endfunction()
+32
View File
@@ -0,0 +1,32 @@
# ##############################################################################
# cmake/nuttx_add_subdirectory.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
function(nuttx_add_subdirectory)
file(
GLOB subdir
LIST_DIRECTORIES false
RELATIVE ${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/*/CMakeLists.txt)
foreach(dir ${subdir})
get_filename_component(dir ${dir} DIRECTORY)
add_subdirectory(${dir})
endforeach()
endfunction()
+103
View File
@@ -0,0 +1,103 @@
# ##############################################################################
# cmake/nuttx_add_symtab.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
# nuttx_add_symtab Generates a symbol table of undefined symbols from a set of
# binaries
#
# Parameters: - NAME: name of symtab (output will be symtab_${NAME}.c) -
# BINARIES: list of binary target names to process (dependencies will be added
# to these targets) - PREFIX: optional prefix to add to symtab variable name -
# EXCLUDE: optional list of symbols to exclude (ie: assume they are defined)
function(nuttx_add_symtab)
nuttx_parse_function_args(
FUNC
nuttx_add_symtab
ONE_VALUE
NAME
PREFIX
OPTIONS
HEADER
MULTI_VALUE
EXCLUDE
BINARIES
REQUIRED
NAME
BINARIES
ARGN
${ARGN})
# get path to binaries
set(BINARY_PATHS)
foreach(binary ${BINARIES})
# this way of getting the path will select the actual ELF binary, even when
# this was built by means of an intermediate library on non-ELF platforms
list(APPEND BINARY_PATHS $<TARGET_PROPERTY:${binary},ELF_BINARY>)
endforeach()
if(EXCLUDE)
string(REPLACE ";" " " EXCLUDE_STRING ${EXCLUDE})
endif()
# generate list of undefined symbols
add_custom_command(
OUTPUT symtab_${NAME}.dat
COMMAND ${CMAKE_NM} ${BINARY_PATHS} | fgrep ' U ' | sed -e "s/^[ ]*//g" |
cut -d' ' -f2 | sort | uniq > symtab_${NAME}.dat
COMMAND
if [ \"${EXCLUDE}\" != \"\" ]\; then fgrep -v -x ${EXCLUDE_STRING}
symtab_${NAME}.dat > symtab_${NAME}.dat2\; mv symtab_${NAME}.dat2
symtab_${NAME}.dat\; fi
DEPENDS ${BINARIES})
add_custom_target(symtab_${NAME}_dat DEPENDS symtab_${NAME}.dat)
# generate declarations for symbols and symtab entries as headers
add_custom_command(
OUTPUT symtab_${NAME}_declarations.h symtab_${NAME}_entries.h
COMMAND sed -E 's|\(.+\)|extern void *\\1\;|g' symtab_${NAME}.dat >
symtab_${NAME}_declarations.h
COMMAND sed -E 's|\(.+\)|{ \"\\1\", \\&\\1 },|g' symtab_${NAME}.dat >
symtab_${NAME}_entries.h
DEPENDS symtab_${NAME}_dat)
# generate code which instantiates the symbol table
configure_file(${CMAKE_SOURCE_DIR}/cmake/symtab.c.in symtab_${NAME}.c @ONLY)
# define an internal library to build the symtab file on its own
add_library(symtab_${NAME} OBJECT
${CMAKE_CURRENT_BINARY_DIR}/symtab_${NAME}.c)
# Make the dependance between .c and .h explicit. This is necessary since
# using configure_file() does not seem to allow this to be automatically
# guessed by CMake
set_property(
SOURCE ${CMAKE_CURRENT_BINARY_DIR}/symtab_${NAME}.c
APPEND
PROPERTY OBJECT_DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/symtab_${NAME}_declarations.h
${CMAKE_CURRENT_BINARY_DIR}/symtab_${NAME}_entries.h)
nuttx_add_library_internal(symtab_${NAME})
if(PREFIX)
target_compile_definitions(symtab_${NAME} PRIVATE -DSYMTAB_PREFIX=${PREFIX})
endif()
endfunction()
+27
View File
@@ -0,0 +1,27 @@
# ##############################################################################
# cmake/nuttx_create_symlink.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
function(nuttx_create_symlink old new)
if(IS_DIRECTORY ${old} AND WIN32)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${old} ${new})
else()
file(CREATE_LINK ${old} ${new} COPY_ON_ERROR SYMBOLIC)
endif()
endfunction()
+149
View File
@@ -0,0 +1,149 @@
# ##############################################################################
# cmake/nuttx_generate_headers.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
# setup target to generate config.h and version.h from mkconfig and mkversion
if(NOT EXISTS ${CMAKE_BINARY_DIR}/include)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include)
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/include/nuttx)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/nuttx)
endif()
include(nuttx_mkconfig)
include(nuttx_mkversion)
# Setup symbolic link generation
if(NOT EXISTS ${CMAKE_BINARY_DIR}/include_arch/arch)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
${CMAKE_BINARY_DIR}/include_arch/arch)
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/include_apps)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
${CMAKE_BINARY_DIR}/include_apps)
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/include/arch)
nuttx_create_symlink(${NUTTX_DIR}/arch/${CONFIG_ARCH}/include
${CMAKE_BINARY_DIR}/include/arch)
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/include_arch/arch/board)
nuttx_create_symlink(${NUTTX_BOARD_DIR}/include
${CMAKE_BINARY_DIR}/include_arch/arch/board)
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/include_arch/arch/chip)
if(CONFIG_ARCH_CHIP_CUSTOM)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_directory ${NUTTX_CHIP_ABS_DIR}/include
${CMAKE_BINARY_DIR}/include_arch/arch/chip)
else()
execute_process(
COMMAND
${CMAKE_COMMAND} -E copy_directory
${NUTTX_DIR}/arch/${CONFIG_ARCH}/include/${CONFIG_ARCH_CHIP}
${CMAKE_BINARY_DIR}/include_arch/arch/chip)
endif()
endif()
# Optional symbolic links
# Target used to copy include/nuttx/lib/stdarg.h. If CONFIG_ARCH_STDARG_H is
# defined, then there is an architecture specific stdarg.h header file that will
# be included indirectly from include/lib/stdarg.h. But first, we have to copy
# stdarg.h from include/nuttx/. to include/.
if(CONFIG_ARCH_STDARG_H)
nuttx_create_symlink(${NUTTX_DIR}/include/nuttx/lib/stdarg.h
${CMAKE_BINARY_DIR}/include/stdarg.h)
else()
file(REMOVE ${CMAKE_BINARY_DIR}/include/stdarg.h)
endif()
# Target used to copy include/nuttx/lib/math.h. If CONFIG_ARCH_MATH_H is
# defined, then there is an architecture specific math.h header file that will
# be included indirectly from include/math.h. But first, we have to copy math.h
# from include/nuttx/. to include/. Logic within include/nuttx/lib/math.h will
# hand the redirection to the architecture- specific math.h header file.
#
# If the CONFIG_LIBM is defined, the Rhombus libm will be built at libc/math.
# Definitions and prototypes for the Rhombus libm are also contained in
# include/nuttx/lib/math.h and so the file must also be copied in that case.
#
# If neither CONFIG_ARCH_MATH_H nor CONFIG_LIBM is defined, then no math.h
# header file will be provided. You would want that behavior if (1) you don't
# use libm, or (2) you want to use the math.h and libm provided within your
# toolchain.
if(CONFIG_ARCH_MATH_H OR CONFIG_LIBM)
set(NEED_MATH_H true)
endif()
if(NEED_MATH_H)
nuttx_create_symlink(${NUTTX_DIR}/include/nuttx/lib/math.h
${CMAKE_BINARY_DIR}/include/math.h)
else()
file(REMOVE ${CMAKE_BINARY_DIR}/include/math.h)
endif()
# The float.h header file defines the properties of your floating point
# implementation. It would always be best to use your toolchain's float.h
# header file but if none is available, a default float.h header file will
# provided if this option is selected. However there is no assurance that the
# settings in this float.h are actually correct for your platform!
if(CONFIG_ARCH_FLOAT_H)
nuttx_create_symlink(${NUTTX_DIR}/include/nuttx/lib/float.h
${CMAKE_BINARY_DIR}/include/float.h)
else()
file(REMOVE ${CMAKE_BINARY_DIR}/include/float.h)
endif()
# Target used to copy include/nuttx/lib/setjmp.h. If CONFIG_ARCH_SETJMP_H is
# defined, then there is an architecture specific setjmp.h header file that will
# be included indirectly from include/lib/setjmp.h. But first, we have to copy
# setjmp.h from include/nuttx/. to include/.
if(CONFIG_ARCH_SETJMP_H)
nuttx_create_symlink(${NUTTX_DIR}/include/nuttx/lib/setjmp.h
${CMAKE_BINARY_DIR}/include/setjmp.h)
else()
file(REMOVE ${CMAKE_BINARY_DIR}/include/setjmp.h)
endif()
# Add final context target that ties together all of the above The context
# target is invoked on each target build to assure that NuttX is properly
# configured. The basic configuration steps include creation of the the
# config.h and version.h header files in the include/nuttx directory and the
# establishment of symbolic links to configured directories.
add_custom_target(
nuttx_context
DEPENDS
${CMAKE_BINARY_DIR}/include/nuttx/config.h
${CMAKE_BINARY_DIR}/include/nuttx/version.h
$<$<BOOL:${CONFIG_ARCH_STDARG_H}>:${CMAKE_BINARY_DIR}/include/stdarg.h>
$<$<BOOL:${NEED_MATH_H}>:${CMAKE_BINARY_DIR}/include/math.h>
$<$<BOOL:${CONFIG_ARCH_FLOAT_H}>:${CMAKE_BINARY_DIR}/include/float.h>
$<$<BOOL:${CONFIG_ARCH_SETJMP_H}>:${CMAKE_BINARY_DIR}/include/setjmp.h>)
+48
View File
@@ -0,0 +1,48 @@
# ##############################################################################
# cmake/nuttx_generate_outputs.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
function(nuttx_generate_outputs target)
if(CONFIG_INTELHEX_BINARY)
add_custom_command(
OUTPUT ${target}.hex
COMMAND ${CMAKE_OBJCOPY} -O ihex ${target} ${target}.hex
DEPENDS ${target})
add_custom_target(${target}-hex ALL DEPENDS ${target}.hex)
file(APPEND ${CMAKE_BINARY_DIR}/nuttx.manifest "${target}.hex\n")
endif()
if(CONFIG_MOTOROLA_SREC)
add_custom_command(
OUTPUT ${target}.srec
COMMAND ${CMAKE_OBJCOPY} -O srec ${target} ${target}.srec
DEPENDS ${target})
add_custom_target(${target}-srec ALL DEPENDS ${target}.srec)
file(APPEND ${CMAKE_BINARY_DIR}/nuttx.manifest "${target}.srec\n")
endif()
if(CONFIG_RAW_BINARY)
add_custom_command(
OUTPUT ${target}.bin
COMMAND ${CMAKE_OBJCOPY} -O binary ${target} ${target}.bin
DEPENDS ${target})
add_custom_target(${target}-bin ALL DEPENDS ${target}.bin)
file(APPEND ${CMAKE_BINARY_DIR}/nuttx.manifest "${target}.bin\n")
endif()
endfunction(nuttx_generate_outputs)
+127
View File
@@ -0,0 +1,127 @@
# ##############################################################################
# cmake/nuttx_kconfig.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
function(nuttx_export_kconfig_by_value kconfigfile config)
file(STRINGS ${kconfigfile} ConfigContents)
foreach(NameAndValue ${ConfigContents})
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
string(REGEX MATCH "^CONFIG[^=]+" Name ${NameAndValue})
if(Name STREQUAL ${config})
string(REPLACE "${Name}=" "" Value ${NameAndValue})
string(REPLACE "\"" "" Value ${Value})
set(${Name}
${Value}
PARENT_SCOPE)
break()
endif()
endforeach()
endfunction()
function(nuttx_export_kconfig kconfigfile)
file(STRINGS ${kconfigfile} ConfigContents)
foreach(NameAndValue ${ConfigContents})
# Strip leading spaces
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
# Find variable name
string(REGEX MATCH "^CONFIG[^=]+" Name ${NameAndValue})
if(Name)
# Find the value
string(REPLACE "${Name}=" "" Value ${NameAndValue})
# remove extra quotes
string(REPLACE "\"" "" Value ${Value})
# Set the variable
set(${Name}
${Value}
PARENT_SCOPE)
endif()
endforeach()
# Compatibility for symbols usually user-settable (now, set via env vars)
# TODO: change usage of these symbols into the corresponding cmake variables
if(LINUX)
set(CONFIG_HOST_LINUX
true
PARENT_SCOPE)
elseif(APPLE)
set(CONFIG_HOST_MACOS
true
PARENT_SCOPE)
elseif(WIN32)
set(CONFIG_HOST_WINDOWS
true
PARENT_SCOPE)
else()
set(CONFIG_HOST_OTHER
true
PARENT_SCOPE)
endif()
endfunction()
function(nuttx_generate_kconfig)
nuttx_parse_function_args(
FUNC
nuttx_generate_kconfig
ONE_VALUE
MENUDESC
REQUIRED
ARGN
${ARGN})
if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt"
OR EXISTS "${NUTTX_APPS_BINDIR}/Kconfig")
return()
endif()
set(KCONFIG_OUTPUT_FILE)
if(MENUDESC)
string(REPLACE "/" "_" KCONFIG_PREFIX ${CMAKE_CURRENT_LIST_DIR})
if(WIN32)
string(REPLACE ":" "_" KCONFIG_PREFIX ${KCONFIG_PREFIX})
endif()
string(APPEND KCONFIG_OUTPUT_FILE ${NUTTX_APPS_BINDIR} "/"
${KCONFIG_PREFIX} "_Kconfig")
file(WRITE ${KCONFIG_OUTPUT_FILE} "menu \"${MENUDESC}\"\n")
else()
set(KCONFIG_OUTPUT_FILE ${NUTTX_APPS_BINDIR}/Kconfig)
file(
GLOB subdir
LIST_DIRECTORIES false
${NUTTX_APPS_BINDIR} ${NUTTX_APPS_BINDIR}/*_Kconfig)
foreach(dir ${subdir})
file(APPEND ${KCONFIG_OUTPUT_FILE} "source \"${dir}\"\n")
endforeach()
endif()
file(
GLOB subdir
LIST_DIRECTORIES false
${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/*/Kconfig)
foreach(dir ${subdir})
file(APPEND ${KCONFIG_OUTPUT_FILE} "source \"${dir}\"\n")
endforeach()
if(MENUDESC)
file(APPEND ${KCONFIG_OUTPUT_FILE} "endmenu # ${MENUDESC}\n")
endif()
endfunction()
+139
View File
@@ -0,0 +1,139 @@
# ##############################################################################
# cmake/nuttx_mkconfig.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
if(NOT EXISTS ${CMAKE_BINARY_DIR}/.config)
return()
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/.config.prev)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/.config
${CMAKE_BINARY_DIR}/.config.prev
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
execute_process(
COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_BINARY_DIR}/.config
${CMAKE_BINARY_DIR}/.config.prev
RESULT_VARIABLE COMPARE_RESULT
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set(CONFIG_H ${CMAKE_BINARY_DIR}/include/nuttx/config.h)
if(COMPARE_RESULT EQUAL 0 AND EXISTS ${CONFIG_H})
return()
endif()
set(DEQUOTELIST
# NuttX
"CONFIG_DEBUG_OPTLEVEL" # Custom debug level
"CONFIG_EXECFUNCS_NSYMBOLS_VAR" # Variable holding number of symbols in the
# table
"CONFIG_EXECFUNCS_SYMTAB_ARRAY" # Symbol table array used by exec[l|v]
"CONFIG_INIT_ARGS" # Argument list of entry point
"CONFIG_INIT_SYMTAB" # Global symbol table
"CONFIG_INIT_NEXPORTS" # Global symbol table size
"CONFIG_INIT_ENTRYPOINT" # Name of entry point function
"CONFIG_MODLIB_SYMTAB_ARRAY" # Symbol table array used by modlib functions
"CONFIG_MODLIB_NSYMBOLS_VAR" # Variable holding number of symbols in the
# table
"CONFIG_PASS1_BUILDIR" # Pass1 build directory
"CONFIG_PASS1_TARGET" # Pass1 build target
"CONFIG_PASS1_OBJECT" # Pass1 build object
"CONFIG_TTY_LAUNCH_ENTRYPOINT" # Name of entry point from tty launch
"CONFIG_TTY_LAUNCH_ARGS" # Argument list of entry point from tty launch
# NxWidgets/NxWM
"CONFIG_NXWM_BACKGROUND_IMAGE" # Name of bitmap image class
"CONFIG_NXWM_CALIBRATION_ICON" # Name of bitmap image class
"CONFIG_NXWM_HEXCALCULATOR_ICON" # Name of bitmap image class
"CONFIG_NXWM_MINIMIZE_BITMAP" # Name of bitmap image class
"CONFIG_NXWM_NXTERM_ICON" # Name of bitmap image class
"CONFIG_NXWM_STARTWINDOW_ICON" # Name of bitmap image class
"CONFIG_NXWM_STOP_BITMAP" # Name of bitmap image class
# apps/ definitions
"CONFIG_NSH_SYMTAB_ARRAYNAME" # Symbol table array name
"CONFIG_NSH_SYMTAB_COUNTNAME" # Name of the variable holding the
# number of symbols
)
file(WRITE ${CONFIG_H} "/* config.h -- Autogenerated! Do not edit. */\n\n")
file(APPEND ${CONFIG_H} "#ifndef __INCLUDE_NUTTX_CONFIG_H\n")
file(APPEND ${CONFIG_H} "#define __INCLUDE_NUTTX_CONFIG_H\n\n")
file(APPEND ${CONFIG_H}
"/* Used to represent the values of tristate options */\n\n")
file(APPEND ${CONFIG_H} "#define CONFIG_y 1\n")
file(APPEND ${CONFIG_H} "#define CONFIG_m 2\n\n")
file(APPEND ${CONFIG_H}
"/* General Definitions ***********************************/\n")
file(STRINGS ${CMAKE_BINARY_DIR}/.config ConfigContents)
foreach(NameAndValue ${ConfigContents})
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
string(REGEX MATCH "^CONFIG[^=]+" NAME ${NameAndValue})
string(REPLACE "${NAME}=" "" VALUE ${NameAndValue})
if(NAME AND NOT "${VALUE}" STREQUAL "")
if(${VALUE} STREQUAL "y")
file(APPEND ${CONFIG_H} "#define ${NAME} 1\n")
elseif(${VALUE} STREQUAL "m")
file(APPEND ${CONFIG_H} "#define ${NAME} 2\n")
elseif(${VALUE} STREQUAL "n")
file(APPEND ${CONFIG_H} "#undef ${NAME}\n")
else()
foreach(dequote ${DEQUOTELIST})
if("${NAME}" STREQUAL "${dequote}")
if(NOT "${VALUE}" STREQUAL "\"\"")
string(REGEX REPLACE "\"" "" VALUE ${VALUE})
else()
set(VALUE)
file(APPEND ${CONFIG_H} "#undef ${NAME}\n")
endif()
break()
endif()
endforeach()
if(NOT "${VALUE}" STREQUAL "")
file(APPEND ${CONFIG_H} "#define ${NAME} ${VALUE}\n")
endif()
endif()
endif()
endforeach()
file(APPEND ${CONFIG_H}
"\n/* Sanity Checks *****************************************/\n\n")
file(APPEND ${CONFIG_H}
"/* If the end of RAM is not specified then it is assumed to be\n")
file(APPEND ${CONFIG_H} " * the beginning of RAM plus the RAM size.\n")
file(APPEND ${CONFIG_H} " */\n\n")
file(APPEND ${CONFIG_H} "#ifndef CONFIG_RAM_END\n")
file(APPEND ${CONFIG_H}
"# define CONFIG_RAM_END (CONFIG_RAM_START+CONFIG_RAM_SIZE)\n")
file(APPEND ${CONFIG_H} "#endif\n\n")
file(APPEND ${CONFIG_H} "#ifndef CONFIG_RAM_VEND\n")
file(APPEND ${CONFIG_H}
"# define CONFIG_RAM_VEND (CONFIG_RAM_VSTART+CONFIG_RAM_SIZE)\n")
file(APPEND ${CONFIG_H} "#endif\n\n")
file(APPEND ${CONFIG_H}
"/* If the end of FLASH is not specified then it is assumed to be\n")
file(APPEND ${CONFIG_H} " * the beginning of FLASH plus the FLASH size.\n")
file(APPEND ${CONFIG_H} " */\n\n")
file(APPEND ${CONFIG_H} "#ifndef CONFIG_FLASH_END\n")
file(APPEND ${CONFIG_H}
"# define CONFIG_FLASH_END (CONFIG_FLASH_START+CONFIG_FLASH_SIZE)\n")
file(APPEND ${CONFIG_H} "#endif\n\n")
file(APPEND ${CONFIG_H} "#endif /* __INCLUDE_NUTTX_CONFIG_H */\n")
+110
View File
@@ -0,0 +1,110 @@
# ##############################################################################
# cmake/nuttx_mkversion.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
set(VERSION_H ${CMAKE_BINARY_DIR}/include/nuttx/version.h)
if(EXISTS ${VERSION_H})
return()
endif()
execute_process(
COMMAND git -C ${NUTTX_DIR} describe --match "nuttx-*"
WORKING_DIRECTORY ${NUTTX_DIR}
OUTPUT_VARIABLE NUTTX_VERSION
RESULT_VARIABLE VERSION_STATUS)
if(${VERSION_STATUS} AND NOT ${VERSION_STATUS} EQUAL 0)
set(NUTTX_VERSION "0.0.0")
else()
string(REPLACE "-" ";" NUTTX_VERSION ${NUTTX_VERSION})
list(GET NUTTX_VERSION 1 NUTTX_VERSION)
endif()
string(REPLACE "." ";" NUTTX_CHECK_VERSION ${NUTTX_VERSION})
list(LENGTH NUTTX_CHECK_VERSION NUTTX_VERSION_LENGTH)
if(${NUTTX_VERSION_LENGTH} LESS 3)
execute_process(
COMMAND git -C ${NUTTX_DIR} -c "versionsort.suffix=-" tag --sort=v:refname
WORKING_DIRECTORY ${NUTTX_DIR}
OUTPUT_VARIABLE NUTTX_VERSION_LIST
RESULT_VARIABLE VERSION_STATUS)
if(${VERSION_STATUS} EQUAL 0)
string(REPLACE "\n" ";" NUTTX_VERSION_LIST ${NUTTX_VERSION_LIST})
foreach(version ${NUTTX_VERSION_LIST})
string(REGEX MATCH "nuttx-[0-9]+\.[0-9]+\.[0-9]+" NUTTX_CHECK_VERSION
${version})
if(NUTTX_CHECK_VERSION)
string(REPLACE "-" ";" NUTTX_VERSION ${NUTTX_CHECK_VERSION})
list(GET NUTTX_VERSION 1 NUTTX_VERSION)
endif()
endforeach()
endif()
endif()
execute_process(
COMMAND git -C ${NUTTX_DIR} log --oneline -1
WORKING_DIRECTORY ${NUTTX_DIR}
OUTPUT_VARIABLE NUTTX_VERSION_BUILD
RESULT_VARIABLE VERSION_STATUS)
if(${VERSION_STATUS} AND NOT ${VERSION_STATUS} EQUAL 0)
set(NUTTX_VERSION_BUILD)
else()
string(REPLACE " " ";" NUTTX_VERSION_BUILD ${NUTTX_VERSION_BUILD})
list(GET NUTTX_VERSION_BUILD 0 NUTTX_VERSION_BUILD)
execute_process(
COMMAND git -C ${NUTTX_DIR} diff-index --name-only HEAD
WORKING_DIRECTORY ${NUTTX_DIR}
OUTPUT_VARIABLE NUTTX_VERSION_BUILD_DIRTY)
if(NUTTX_VERSION_BUILD_DIRTY)
set(NUTTX_VERSION_BUILD ${NUTTX_VERSION_BUILD}-dirty)
endif()
endif()
file(WRITE ${VERSION_H} "/* version.h -- Autogenerated! Do not edit. */\n\n")
file(APPEND ${VERSION_H} "#ifndef __INCLUDE_NUTTX_VERSION_H\n")
file(APPEND ${VERSION_H} "#define __INCLUDE_NUTTX_VERSION_H\n\n")
file(APPEND ${VERSION_H} "#define CONFIG_VERSION_STRING \"${NUTTX_VERSION}\"\n")
string(REPLACE "." ";" NUTTX_VERSION ${NUTTX_VERSION})
list(GET NUTTX_VERSION 0 NUTTX_VERSION_MAJOR)
list(GET NUTTX_VERSION 1 NUTTX_VERSION_MINOR)
list(GET NUTTX_VERSION 2 NUTTX_VERSION_PATCH)
file(APPEND ${VERSION_H}
"#define CONFIG_VERSION_MAJOR ${NUTTX_VERSION_MAJOR}\n")
file(APPEND ${VERSION_H}
"#define CONFIG_VERSION_MINOR ${NUTTX_VERSION_MINOR}\n")
file(APPEND ${VERSION_H}
"#define CONFIG_VERSION_PATCH ${NUTTX_VERSION_PATCH}\n")
file(APPEND ${VERSION_H}
"#define CONFIG_VERSION_BUILD \"${NUTTX_VERSION_BUILD}\"\n\n")
file(
APPEND ${VERSION_H}
"#define CONFIG_VERSION ((CONFIG_VERSION_MAJOR << 16) | \\
(CONFIG_VERSION_MINOR << 8) | \\
(CONFIG_VERSION_PATCH))\n")
file(APPEND ${VERSION_H} "\n#endif /* __INCLUDE_NUTTX_VERSION_H */\n")
+84
View File
@@ -0,0 +1,84 @@
# ##############################################################################
# cmake/nuttx_parse_function_args.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
# =============================================================================
#
# Defined functions in this file
#
# utility functions
#
# * nuttx_parse_function_args
#
include(CMakeParseArguments)
# =============================================================================
#
# nuttx_parse_function_args
#
# This function simplifies usage of the cmake_parse_arguments module. It is
# intended to be called by other functions.
#
# Usage: nuttx_parse_function_args( FUNC <name> [ OPTIONS <list> ] [ ONE_VALUE
# <list> ] [ MULTI_VALUE <list> ] REQUIRED <list> ARGN <ARGN>)
#
# Input: FUNC : the name of the calling function OPTIONS : boolean flags
# ONE_VALUE : single value variables MULTI_VALUE : multi value variables
# REQUIRED : required arguments ARGN : the function input arguments,
# typically ${ARGN}
#
# Output: The function arguments corresponding to the following are set:
# ${OPTIONS}, ${ONE_VALUE}, ${MULTI_VALUE}
#
# Example: function test() nuttx_parse_function_args( FUNC TEST ONE_VALUE NAME
# MULTI_VALUE LIST REQUIRED NAME LIST ARGN ${ARGN}) message(STATUS "name:
# ${NAME}") message(STATUS "list: ${LIST}") endfunction()
#
# test(NAME "hello" LIST a b c)
#
# OUTPUT: name: hello list: a b c
#
function(nuttx_parse_function_args)
cmake_parse_arguments(IN "" "FUNC"
"OPTIONS;ONE_VALUE;MULTI_VALUE;REQUIRED;ARGN" "${ARGN}")
cmake_parse_arguments(OUT "${IN_OPTIONS}" "${IN_ONE_VALUE}"
"${IN_MULTI_VALUE}" "${IN_ARGN}")
if(OUT_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "${IN_NAME}: unparsed ${OUT_UNPARSED_ARGUMENTS}")
endif()
foreach(arg ${IN_REQUIRED})
if(NOT OUT_${arg})
if(NOT "${OUT_${arg}}" STREQUAL "0")
message(
FATAL_ERROR "${IN_NAME} requires argument ${arg}\nARGN: ${IN_ARGN}")
endif()
endif()
endforeach()
foreach(arg ${IN_OPTIONS} ${IN_ONE_VALUE} ${IN_MULTI_VALUE})
set(${arg}
${OUT_${arg}}
PARENT_SCOPE)
endforeach()
endfunction()
+146
View File
@@ -0,0 +1,146 @@
# ##############################################################################
# cmake/nuttx_redefine_symbols.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
set(NXSYMBOLS
__cxa_atexit
abort
accept
access
atexit
backtrace
bind
calloc
chmod
chown
clock_gettime
close
closedir
connect
dlsym
dup
exit
fchmod
fchown
fclose
fcntl
fdopen
fopen
fprintf
fread
free
fseek
fstat
fsync
ftell
ftruncate
futimens
fwrite
getpeername
getsockname
getenv
getpid
getsockopt
if_nametoindex
ioctl
listen
longjmp
lseek
malloc
malloc_size
malloc_usable_size
memcpy
mkdir
mmap
mprotect
munmap
open
opendir
perror
poll
posix_memalign
pthread_attr_init
pthread_attr_setstack
pthread_attr_destroy
pthread_cond_destroy
pthread_cond_init
pthread_cond_signal
pthread_cond_wait
pthread_create
pthread_getspecific
pthread_key_create
pthread_kill
pthread_mutex_destroy
pthread_mutex_init
pthread_mutex_lock
pthread_mutex_unlock
pthread_setspecific
pthread_sigmask
puts
read
readdir
readv
realloc
recvfrom
rename
rewinddir
rmdir
sched_yield
select
sendmsg
sendto
setitimer
setbuf
setjmp
setsockopt
shutdown
sigaction
sigaddset
sigemptyset
sigfillset
sleep
socket
stat
statvfs
stderr
strcat
strchr
strerror
strlen
strtol
sysconf
syslog
tcgetattr
tcsetattr
unlink
usleep
utimensat
write
writev)
set(NXSYMBOL_RENAMES)
foreach(NXSYMBOL ${NXSYMBOLS})
if(APPLE OR (CYGWIN AND CONFIG_SIM_CYGWIN_DECORATED))
list(APPEND NXSYMBOL_RENAMES "_${NXSYMBOL} NX${NXSYMBOL}")
else()
list(APPEND NXSYMBOL_RENAMES "${NXSYMBOL} NX${NXSYMBOL}")
endif()
endforeach()
string(REPLACE ";" "\n" NXSYMBOL_RENAMES "${NXSYMBOL_RENAMES}")
file(WRITE ${CMAKE_BINARY_DIR}/nuttx-names.dat "${NXSYMBOL_RENAMES}\n")
+54
View File
@@ -0,0 +1,54 @@
/****************************************************************************
* cmake/symtab.c.in
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#include <nuttx/compiler.h>
#include <nuttx/symtab.h>
#define _CONCAT(x,y) x ## y
#define CONCAT(x,y) _CONCAT(x,y)
#include "symtab_@NAME@_declarations.h"
#ifndef SYMTAB_PREFIX
# if defined(CONFIG_EXECFUNCS_HAVE_SYMTAB)
const struct symtab_s CONFIG_EXECFUNCS_SYMTAB_ARRAY[] =
# elif defined(CONFIG_SYSTEM_NSH_SYMTAB)
const struct symtab_s CONFIG_NSH_SYMTAB_ARRAYNAME[] =
# else
const struct symtab_s dummy_symtab[] =
# endif
#else
const struct symtab_s CONCAT(SYMTAB_PREFIX,_exports)[] =
#endif
{
#include "symtab_@NAME@_entries.h"
};
#ifndef SYMTAB_PREFIX
# if defined(CONFIG_EXECFUNCS_HAVE_SYMTAB)
const int CONFIG_EXECFUNCS_NSYMBOLS_VAR = sizeof(CONFIG_EXECFUNCS_SYMTAB_ARRAY) / sizeof(struct symtab_s);
# elif defined(CONFIG_SYSTEM_NSH_SYMTAB)
const int CONFIG_NSH_SYMTAB_COUNTNAME = sizeof(CONFIG_NSH_SYMTAB_ARRAYNAME) / sizeof(struct symtab_s);
# else
const int dummy_nsymtabs = sizeof(dummy_symtab) / sizeof(struct symtab_s);
# endif
#else
const int CONCAT(SYMTAB_PREFIX,_nexports) = sizeof(CONCAT(SYMTAB_PREFIX,_exports)) / sizeof(struct symtab_s);
#endif