mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-11 07:25:19 +00:00
This companion change updates the nuttx-apps CMake build to use NuttX’s NUTTX_DIR and NUTTX_BINARY_DIR instead of CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR, which incorrectly refer to the outermost project when NuttX is embedded via add_subdirectory(). Since apps/ is itself included from NuttX’s top-level CMakeLists.txt, these variables were effectively being used as references to NuttX’s root and inherited the same bug fixed in the matching NuttX change for #19697. All self-referencing uses are replaced while intentionally preserving standalone projects and unrelated custom variables or hardcoded paths. The change affects only the CMake build system, preserves normal standalone behavior, and was tested with sim:nsh both standalone and embedded, with apps such as hello and ostest successfully built and available in NSH. Fixes #19697. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Alan Carvalho de Assis <acassis@gmail.com>
149 lines
5 KiB
CMake
149 lines
5 KiB
CMake
# ##############################################################################
|
|
# apps/interpreters/lua/CMakeLists.txt
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# 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(CONFIG_INTERPRETERS_LUA)
|
|
|
|
# ############################################################################
|
|
# Config and Fetch lua
|
|
# ############################################################################
|
|
|
|
set(LUA_DIR ${CMAKE_CURRENT_LIST_DIR}/lua)
|
|
|
|
if(NOT EXISTS ${LUA_DIR})
|
|
set(LUA_URL https://github.com/lua/lua/archive/refs/tags/)
|
|
FetchContent_Declare(
|
|
lua_fetch
|
|
URL ${LUA_URL}/v${CONFIG_INTERPRETERS_LUA_VERSION}.tar.gz SOURCE_DIR
|
|
${CMAKE_CURRENT_LIST_DIR}/lua BINARY_DIR
|
|
${NUTTX_BINARY_DIR}/apps/interpreters/lua/lua
|
|
DOWNLOAD_NO_PROGRESS true
|
|
TIMEOUT 30)
|
|
|
|
FetchContent_GetProperties(lua_fetch)
|
|
|
|
if(NOT lua_fetch_POPULATED)
|
|
FetchContent_Populate(lua_fetch)
|
|
endif()
|
|
endif()
|
|
|
|
# ############################################################################
|
|
# Flags
|
|
# ############################################################################
|
|
|
|
set(CFLAGS -DLUA_MAXINPUT=${CONFIG_INTERPRETERS_LUA_IOBUFSIZE}
|
|
-DLUA_PROGNAME=\"lua\")
|
|
if(CONFIG_INTERPRETERS_LUA_32BITS)
|
|
list(APPEND CFLAGS -DLUA_32BITS)
|
|
endif()
|
|
if(NOT "${CONFIG_INTERPRETERS_LUA_PATH}" STREQUAL "")
|
|
list(APPEND CFLAGS -DLUA_PATH_DEFAULT=\"${CONFIG_INTERPRETERS_LUA_PATH}\")
|
|
endif()
|
|
|
|
if(NOT "${CONFIG_INTERPRETERS_LUA_CPATH}" STREQUAL "")
|
|
list(APPEND CFLAGS -DLUA_CPATH_DEFAULT=\"${CONFIG_INTERPRETERS_LUA_CPATH}\")
|
|
endif()
|
|
|
|
if(CONFIG_SYSTEM_READLINE)
|
|
set(LUA_SYSTEM_READLINE_DEF
|
|
[=[
|
|
#define lua_initreadline(L) ((void)L)
|
|
#define lua_readline(L,b,p) ((void)L,fputs(p,stdout),fflush(stdout),readline_stream(b,LUA_MAXINPUT,stdin,stdout))
|
|
#define lua_saveline(L,line) {(void)L;(void)line;}
|
|
#define lua_freeline(L,line) {(void)L;(void)b;}
|
|
]=])
|
|
|
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/def_lua_readline.h
|
|
"${LUA_SYSTEM_READLINE_DEF}")
|
|
list(APPEND CFLAGS "SHELL:-include \"system/readline.h\"")
|
|
list(APPEND CFLAGS
|
|
"SHELL:-include ${CMAKE_CURRENT_BINARY_DIR}/def_lua_readline.h")
|
|
|
|
endif()
|
|
|
|
# ############################################################################
|
|
# Sources
|
|
# ############################################################################
|
|
|
|
file(GLOB CORELIBS_SRCS ${LUA_DIR}/*lib.c)
|
|
list(REMOVE_ITEM CORELIBS_SRCS ${LUA_DIR}/lauxlib.c)
|
|
file(GLOB CSRCS ${LUA_DIR}/*.c)
|
|
list(
|
|
REMOVE_ITEM
|
|
CSRCS
|
|
${LUA_DIR}/onelua.c
|
|
${LUA_DIR}/luac.c
|
|
${LUA_DIR}/linit.c
|
|
${LUA_DIR}/lua.c
|
|
${CORELIBS_SRCS})
|
|
list(APPEND CSRCS nuttx_linit.c)
|
|
|
|
if(CONFIG_INTERPRETERS_LUA_CORELIBS)
|
|
list(APPEND CSRCS ${CORELIBS_SRCS})
|
|
|
|
set(LUA_LIB_H_PATH ${LUA_DIR}/lualib.h)
|
|
file(READ "${LUA_LIB_H_PATH}" FILE_CONTENTS)
|
|
string(REGEX MATCHALL "#define[ \t]+LUA_[A-Z]+LIBNAME[ \t]+\"[^\"]+\""
|
|
LIB_DEFINITIONS "${FILE_CONTENTS}")
|
|
foreach(DEFINITION IN LISTS LIB_DEFINITIONS)
|
|
string(REGEX REPLACE ".*\"([^\"]+)\"" "\\1" LIB_NAME "${DEFINITION}")
|
|
# register lua core mod
|
|
nuttx_add_luamod(MODS ${LIB_NAME})
|
|
endforeach()
|
|
endif()
|
|
|
|
# ############################################################################
|
|
# Include Directory
|
|
# ############################################################################
|
|
|
|
set(INCDIR ${LUAMOD_DIR})
|
|
|
|
# ############################################################################
|
|
# Library Configuration
|
|
# ############################################################################
|
|
|
|
set_property(
|
|
TARGET nuttx
|
|
APPEND
|
|
PROPERTY NUTTX_INCLUDE_DIRECTORIES ${LUA_DIR})
|
|
|
|
# ############################################################################
|
|
# Applications Configuration
|
|
# ############################################################################
|
|
|
|
nuttx_add_application(
|
|
MODULE
|
|
${CONFIG_INTERPRETERS_LUA}
|
|
NAME
|
|
lua
|
|
STACKSIZE
|
|
${CONFIG_INTERPRETERS_LUA_STACKSIZE}
|
|
PRIORITY
|
|
${CONFIG_INTERPRETERS_LUA_PRIORITY}
|
|
SRCS
|
|
${LUA_DIR}/lua.c
|
|
${CSRCS}
|
|
INCLUDE_DIRECTORIES
|
|
${INCDIR}
|
|
COMPILE_FLAGS
|
|
${CFLAGS})
|
|
|
|
endif()
|