diff --git a/tf-psa-crypto/programs/test/cmake_subproject/.gitignore b/tf-psa-crypto/programs/test/cmake_subproject/.gitignore new file mode 100644 index 0000000000..464833b932 --- /dev/null +++ b/tf-psa-crypto/programs/test/cmake_subproject/.gitignore @@ -0,0 +1,3 @@ +build +Makefile +cmake_subproject diff --git a/tf-psa-crypto/programs/test/cmake_subproject/CMakeLists.txt b/tf-psa-crypto/programs/test/cmake_subproject/CMakeLists.txt new file mode 100644 index 0000000000..29195a9e2d --- /dev/null +++ b/tf-psa-crypto/programs/test/cmake_subproject/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.5.1) + +# Test the target renaming support by adding a prefix to the targets built +set(TF_PSA_CRYPTO_TARGET_PREFIX subproject_test_) + +# We use the parent TF-PSA-Crypto directory as the TF_PSA_CRYPTO_DIR for this +# test. Other projects that use TF-PSA-Crypto as a subproject are likely to +# add by their own relative paths. +set(TF_PSA_CRYPTO_DIR ../../../) + +# Add TF-PSA-Crypto as a subdirectory. +add_subdirectory(${TF_PSA_CRYPTO_DIR} build) + +# Link against all the TF-PSA-Crypto library. Verifies that the target has been +# created using the specified prefix + +add_executable(cmake_subproject cmake_subproject.c) +target_link_libraries(cmake_subproject subproject_test_mbedcrypto ${CMAKE_THREAD_LIBS_INIT}) diff --git a/tf-psa-crypto/programs/test/cmake_subproject/cmake_subproject.c b/tf-psa-crypto/programs/test/cmake_subproject/cmake_subproject.c new file mode 100644 index 0000000000..d82f0acd84 --- /dev/null +++ b/tf-psa-crypto/programs/test/cmake_subproject/cmake_subproject.c @@ -0,0 +1,19 @@ +/* + * Simple program to test that CMake builds with TF-PSA-Crypto as a + * subdirectory work correctly. + * + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + */ + +#include + +/* The main reason to build this is for testing the CMake build, so the program + * doesn't need to do very much. It calls a PSA cryptography API to ensure + * linkage works, but that is all. */ +int main() +{ + psa_crypto_init(); + + return 0; +} diff --git a/tf-psa-crypto/programs/test/cmake_subproject/framework/.gitignore b/tf-psa-crypto/programs/test/cmake_subproject/framework/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tf-psa-crypto/tests/scripts/components-build-system.sh b/tf-psa-crypto/tests/scripts/components-build-system.sh index af8e7fa227..5de9dc7876 100644 --- a/tf-psa-crypto/tests/scripts/components-build-system.sh +++ b/tf-psa-crypto/tests/scripts/components-build-system.sh @@ -22,3 +22,12 @@ component_test_tf_psa_crypto_cmake_out_of_source () { cd "$TF_PSA_CRYPTO_ROOT_DIR" rm -rf "$OUT_OF_SOURCE_DIR" } + +component_test_tf_psa_crypto_cmake_as_subdirectory () { + msg "build: cmake 'as-subdirectory' build" + cd programs/test/cmake_subproject + # Note: Explicitly generate files as these are turned off in releases + cmake -D GEN_FILES=ON . + make + ./cmake_subproject +}