Fix build errors in CMake
tests/src/ssl_helpers.c depends on functions defined
in library/*.c. If it's complied as an OBJECT with other c files,
cmake complains undefined reference in link stage under programs/.
Therefore, tests/src/test_helpers/ is created to hold c files with
dependency of library/*.c. Besides, tests/src/test_helper/*.c is
separated into another OBJECT, mbedtls_test_helpers, as sources
to build all test suite executables.
In addition, everest header directory is included in case
MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED is enabled.
Signed-off-by: Yanray Wang <yanray.wang@arm.com>
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index ca477ac..10de8c7 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -50,7 +50,9 @@
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_test_code.py ${mbedtls_target} ${CMAKE_CURRENT_SOURCE_DIR}/suites/helpers.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/main_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/host_test.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${suite_name}.function ${CMAKE_CURRENT_SOURCE_DIR}/suites/test_suite_${data_name}.data
)
- add_executable(test_suite_${data_name} test_suite_${data_name}.c $<TARGET_OBJECTS:mbedtls_test>)
+ add_executable(test_suite_${data_name} test_suite_${data_name}.c
+ $<TARGET_OBJECTS:mbedtls_test>
+ $<TARGET_OBJECTS:mbedtls_test_helpers>)
target_link_libraries(test_suite_${data_name} ${libs})
# Include test-specific header files from ./include and private header
# files (used by some invasive tests) from ../library. Public header
diff --git a/tests/Makefile b/tests/Makefile
index 44ff43c..27dcacb 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -86,7 +86,7 @@
$(MBEDLIBS):
$(MAKE) -C ../library
-MBEDTLS_TEST_OBJS=$(patsubst %.c,%.o,$(wildcard src/*.c src/drivers/*.c))
+MBEDTLS_TEST_OBJS=$(patsubst %.c,%.o,$(wildcard src/*.c src/drivers/*.c src/test_helpers/*.c))
mbedtls_test: $(MBEDTLS_TEST_OBJS)
@@ -107,6 +107,10 @@
echo " CC $<"
$(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
+src/test_helpers/%.o : src/test_helpers/%.c
+ echo " CC $<"
+ $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
+
C_FILES := $(addsuffix .c,$(APPS))
c: $(C_FILES)
@@ -143,7 +147,7 @@
clean:
ifndef WINDOWS
rm -rf $(BINARIES) *.c *.datax
- rm -f src/*.o src/drivers/*.o src/libmbed*
+ rm -f src/*.o src/drivers/*.o src/test_helpers/*.o src/libmbed*
rm -f include/test/instrument_record_status.h
rm -rf libtestdriver1
else
@@ -152,6 +156,7 @@
if exist *.datax del /Q /F *.datax
if exist src/*.o del /Q /F src/*.o
if exist src/drivers/*.o del /Q /F src/drivers/*.o
+ if exist src/test_helpers/*.o del /Q /F src/test_helpers/*.o
if exist src/libmbed* del /Q /F src/libmed*
if exist include/test/instrument_record_status.h del /Q /F include/test/instrument_record_status.h
endif
diff --git a/tests/src/ssl_helpers.c b/tests/src/test_helpers/ssl_helpers.c
similarity index 100%
rename from tests/src/ssl_helpers.c
rename to tests/src/test_helpers/ssl_helpers.c