nuttx-apps/crypto/tinycrypt/CMakeLists.txt
Alan Carvalho de Assis cc8a6c8b85 cmake: Use NUTTX(_DIR/_BINARY_DIR) instead of CMAKE(_SOURCE_DIR/BINARY_DIR)
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>
2026-08-09 10:43:01 -03:00

312 lines
8.3 KiB
CMake

# ##############################################################################
# apps/crypto/tinycrypt/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_TINYCRYPT)
# ############################################################################
# Config and Fetch tinycrypt
# ############################################################################
set(TINYCRYPT_DIR ${CMAKE_CURRENT_LIST_DIR}/tinycrypt)
if(NOT EXISTS ${TINYCRYPT_DIR})
set(TINYCRYPT_VERSION ${CONFIG_TINYCRYPT_VERSION})
set(TINYCRYPT_URL
https://github.com/intel/tinycrypt/archive/refs/tags/v${TINYCRYPT_VERSION}.zip
)
FetchContent_Declare(
tinycrypt_fetch
URL ${TINYCRYPT_URL} SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/tinycrypt
BINARY_DIR ${NUTTX_BINARY_DIR}/apps/crypto/tinycrypt/tinycrypt
PATCH_COMMAND
patch -p0 -d ${CMAKE_CURRENT_LIST_DIR}/tinycrypt <
${CMAKE_CURRENT_LIST_DIR}/0001-TinyCrypt-test-resolve-compile-error.patch
DOWNLOAD_NO_PROGRESS true
TIMEOUT 30)
FetchContent_GetProperties(tinycrypt_fetch)
if(NOT tinycrypt_fetch_POPULATED)
FetchContent_Populate(tinycrypt_fetch)
endif()
endif()
nuttx_add_library(tinycrypt STATIC)
# ############################################################################
# Include Directory
# ############################################################################
set(INCDIR ${TINYCRYPT_DIR}/lib/include)
nuttx_export_header(TARGET tinycrypt INCLUDE_DIRECTORIES ${INCDIR})
# ############################################################################
# Sources
# ############################################################################
list(APPEND CFLAGS -Dunix)
set(CSRCS
${TINYCRYPT_DIR}/lib/source/utils.c ${TINYCRYPT_DIR}/lib/source/ecc.c
${TINYCRYPT_DIR}/lib/source/ecc_platform_specific.c)
if(CONFIG_TINYCRYPT_ECC_DH)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ecc_dh.c)
endif()
if(CONFIG_TINYCRYPT_ECC_DSA)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ecc_dsa.c)
endif()
if(CONFIG_TINYCRYPT_AES)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/aes_encrypt.c
${TINYCRYPT_DIR}/lib/source/aes_decrypt.c)
endif()
if(CONFIG_TINYCRYPT_AES_CBC)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/cbc_mode.c)
endif()
if(CONFIG_TINYCRYPT_AES_CTR)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ctr_mode.c)
endif()
if(CONFIG_TINYCRYPT_AES_CCM)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ccm_mode.c)
endif()
if(CONFIG_TINYCRYPT_AES_CMAC)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/cmac_mode.c)
endif()
if(CONFIG_TINYCRYPT_SHA256)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/sha256.c)
endif()
if(CONFIG_TINYCRYPT_SHA256_HMAC)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/hmac.c)
endif()
if(CONFIG_TINYCRYPT_SHA256_HMAC_PRNG)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/hmac_prng.c)
endif()
if(CONFIG_TINYCRYPT_CTR_PRNG)
list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ctr_prng.c)
endif()
# ############################################################################
# Applications Configuration
# ############################################################################
if(CONFIG_TINYCRYPT_TEST)
list(APPEND CSRCS ${TINYCRYPT_DIR}/tests/test_ecc_utils.c)
list(APPEND INCDIR ${TINYCRYPT_DIR}/tests/include)
list(APPEND CFLAGS -DENABLE_TESTS)
nuttx_add_application(
NAME
tinycrypt_test_aes
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_aes.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
nuttx_add_application(
NAME
tinycrypt_test_cbc_mode
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_cbc_mode.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
nuttx_add_application(
NAME
tinycrypt_test_ccm_mode
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_ccm_mode.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
nuttx_add_application(
NAME
tinycrypt_test_cmac_mode
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_cmac_mode.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
nuttx_add_application(
NAME
tinycrypt_test_ctr_mode
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_ctr_mode.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
nuttx_add_application(
NAME
tinycrypt_test_ctr_prng
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_ctr_prng.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
nuttx_add_application(
NAME
tinycrypt_test_ecc_dh
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_ecc_dh.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
nuttx_add_application(
NAME
tinycrypt_test_ecc_dsa
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_ecc_dsa.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
nuttx_add_application(
NAME
tinycrypt_test_hmac
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_hmac.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
nuttx_add_application(
NAME
tinycrypt_test_hmac_prng
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_hmac_prng.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
nuttx_add_application(
NAME
tinycrypt_test_sha256
STACKSIZE
${CONFIG_TINYCRYPT_TEST_STACKSIZE}
PRIORITY
${CONFIG_TINYCRYPT_TEST_PRIORITY}
SRCS
${TINYCRYPT_DIR}/tests/test_sha256.c
INCLUDE_DIRECTORIES
${INCDIR}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
tinycrypt)
endif()
# ############################################################################
# Library Configuration
# ############################################################################
target_sources(tinycrypt PRIVATE ${CSRCS})
target_include_directories(tinycrypt PRIVATE ${INCDIR})
if(CFLAGS)
target_compile_options(tinycrypt PRIVATE ${CFLAGS})
endif()
endif()