programs: Link to tests common code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
diff --git a/programs/Makefile b/programs/Makefile
index 31e431b..f9c2608 100644
--- a/programs/Makefile
+++ b/programs/Makefile
@@ -7,9 +7,13 @@
WARNING_CXXFLAGS ?= -Wall -Wextra
LDFLAGS ?=
-LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -D_FILE_OFFSET_BITS=64
+MBEDTLS_TEST_PATH:=../tests/src
+MBEDTLS_TEST_OBJS:=$(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/*.c))
+
+LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../tests/include -I../include -D_FILE_OFFSET_BITS=64
LOCAL_CXXFLAGS = $(WARNING_CXXFLAGS) -I../include -D_FILE_OFFSET_BITS=64
-LOCAL_LDFLAGS = -L../library \
+LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
+ -L../library \
-lmbedtls$(SHARED_SUFFIX) \
-lmbedx509$(SHARED_SUFFIX) \
-lmbedcrypto$(SHARED_SUFFIX)
@@ -18,10 +22,11 @@
LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
ifndef SHARED
-DEP=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
+MBEDLIBS=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
else
-DEP=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
+MBEDLIBS=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
endif
+DEP=${MBEDLIBS} ${MBEDTLS_TEST_OBJS}
ifdef DEBUG
LOCAL_CFLAGS += -g3
@@ -127,12 +132,15 @@
all: fuzz
endif
-fuzz:
+fuzz: ${MBEDTLS_TEST_OBJS}
$(MAKE) -C fuzz THIRDPARTY_INCLUDES=$(THIRDPARTY_INCLUDES)
-$(DEP):
+$(MBEDLIBS):
$(MAKE) -C ../library
+${MBEDTLS_TEST_OBJS}:
+ $(MAKE) -C ../tests mbedtls_test
+
ifdef WINDOWS
EXTRA_GENERATED += psa\psa_constant_names_generated.c
else
diff --git a/programs/aes/CMakeLists.txt b/programs/aes/CMakeLists.txt
index 761531d..2309789 100644
--- a/programs/aes/CMakeLists.txt
+++ b/programs/aes/CMakeLists.txt
@@ -4,7 +4,7 @@
)
foreach(exe IN LISTS executables)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
target_link_libraries(${exe} mbedcrypto)
endforeach()
diff --git a/programs/fuzz/CMakeLists.txt b/programs/fuzz/CMakeLists.txt
index 9d4043a..e2b0eac 100644
--- a/programs/fuzz/CMakeLists.txt
+++ b/programs/fuzz/CMakeLists.txt
@@ -32,7 +32,7 @@
foreach(exe IN LISTS executables_no_common_c executables_with_common_c)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
if (NOT FUZZINGENGINE_LIB)
target_link_libraries(${exe} ${libs})
diff --git a/programs/fuzz/Makefile b/programs/fuzz/Makefile
index 24dc7ba..8196f39 100644
--- a/programs/fuzz/Makefile
+++ b/programs/fuzz/Makefile
@@ -1,6 +1,9 @@
+MBEDTLS_TEST_PATH:=../../tests/src
+MBEDTLS_TEST_OBJS:=$(patsubst %.c,%.o,$(wildcard ${MBEDTLS_TEST_PATH}/*.c))
-LOCAL_CFLAGS = -I../../include -D_FILE_OFFSET_BITS=64
-LOCAL_LDFLAGS = -L../../library \
+LOCAL_CFLAGS = -I../../tests/include -I../../include -D_FILE_OFFSET_BITS=64
+LOCAL_LDFLAGS = ${MBEDTLS_TEST_OBJS} \
+ -L../../library \
-lmbedtls$(SHARED_SUFFIX) \
-lmbedx509$(SHARED_SUFFIX) \
-lmbedcrypto$(SHARED_SUFFIX)
diff --git a/programs/hash/CMakeLists.txt b/programs/hash/CMakeLists.txt
index 0b4a1c5..ae29479 100644
--- a/programs/hash/CMakeLists.txt
+++ b/programs/hash/CMakeLists.txt
@@ -4,7 +4,7 @@
)
foreach(exe IN LISTS executables)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
target_link_libraries(${exe} mbedcrypto)
endforeach()
diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt
index 17a252d..b4b3d30 100644
--- a/programs/pkey/CMakeLists.txt
+++ b/programs/pkey/CMakeLists.txt
@@ -4,7 +4,7 @@
)
foreach(exe IN LISTS executables_mbedtls)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
target_link_libraries(${exe} mbedtls)
endforeach()
@@ -30,7 +30,7 @@
)
foreach(exe IN LISTS executables_mbedcrypto)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
target_link_libraries(${exe} mbedcrypto)
endforeach()
diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt
index 4fe7952..6ad6dad 100644
--- a/programs/psa/CMakeLists.txt
+++ b/programs/psa/CMakeLists.txt
@@ -5,8 +5,9 @@
)
foreach(exe IN LISTS executables)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
target_link_libraries(${exe} mbedtls)
+ target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
endforeach()
target_include_directories(psa_constant_names PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt
index 6ef212c..95acb7e 100644
--- a/programs/random/CMakeLists.txt
+++ b/programs/random/CMakeLists.txt
@@ -5,7 +5,7 @@
)
foreach(exe IN LISTS executables)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
target_link_libraries(${exe} mbedcrypto)
endforeach()
diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt
index edd8b35..28fbfc5 100644
--- a/programs/ssl/CMakeLists.txt
+++ b/programs/ssl/CMakeLists.txt
@@ -27,15 +27,16 @@
)
foreach(exe IN LISTS executables)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
target_link_libraries(${exe} ${libs})
+ target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include)
endforeach()
target_sources(ssl_client2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../test/query_config.c)
target_sources(ssl_server2 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../test/query_config.c)
if(THREADS_FOUND)
- add_executable(ssl_pthread_server ssl_pthread_server.c)
+ add_executable(ssl_pthread_server ssl_pthread_server.c $<TARGET_OBJECTS:mbedtls_test>)
target_link_libraries(ssl_pthread_server ${libs} ${CMAKE_THREAD_LIBS_INIT})
list(APPEND executables ssl_pthread_server)
endif(THREADS_FOUND)
diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt
index 33a4ee2..0df0bec 100644
--- a/programs/test/CMakeLists.txt
+++ b/programs/test/CMakeLists.txt
@@ -26,7 +26,7 @@
endif()
foreach(exe IN LISTS executables_libs executables_mbedcrypto)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
# This emulates "if ( ... IN_LIST ... )" which becomes available in CMake 3.3
list(FIND executables_libs ${exe} exe_index)
diff --git a/programs/util/CMakeLists.txt b/programs/util/CMakeLists.txt
index 0fd6ada..cb14a3e 100644
--- a/programs/util/CMakeLists.txt
+++ b/programs/util/CMakeLists.txt
@@ -8,7 +8,7 @@
)
foreach(exe IN LISTS executables)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
target_link_libraries(${exe} ${libs})
endforeach()
diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt
index 02d783c..f7b5fe1 100644
--- a/programs/x509/CMakeLists.txt
+++ b/programs/x509/CMakeLists.txt
@@ -19,7 +19,7 @@
)
foreach(exe IN LISTS executables)
- add_executable(${exe} ${exe}.c)
+ add_executable(${exe} ${exe}.c $<TARGET_OBJECTS:mbedtls_test>)
target_link_libraries(${exe} ${libs})
endforeach()