mirror of
				https://github.com/Mbed-TLS/mbedtls.git
				synced 2025-10-30 10:45:34 +03:00 
			
		
		
		
	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>
This commit is contained in:
		| @@ -287,12 +287,23 @@ add_subdirectory(library) | ||||
| # to define the test executables. | ||||
| # | ||||
| if(ENABLE_TESTING OR ENABLE_PROGRAMS) | ||||
|     file(GLOB MBEDTLS_TEST_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/*.c ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/drivers/*.c) | ||||
|     file(GLOB MBEDTLS_TEST_FILES | ||||
|          ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/*.c | ||||
|          ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/drivers/*.c) | ||||
|     add_library(mbedtls_test OBJECT ${MBEDTLS_TEST_FILES}) | ||||
|     target_include_directories(mbedtls_test | ||||
|         PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests/include | ||||
|         PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include | ||||
|         PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/library) | ||||
|  | ||||
|     file(GLOB MBEDTLS_TEST_HELPER_FILES | ||||
|          ${CMAKE_CURRENT_SOURCE_DIR}/tests/src/test_helpers/*.c) | ||||
|     add_library(mbedtls_test_helpers OBJECT ${MBEDTLS_TEST_HELPER_FILES}) | ||||
|     target_include_directories(mbedtls_test_helpers | ||||
|         PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests/include | ||||
|         PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include | ||||
|         PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/library | ||||
|         PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/everest/include) | ||||
| endif() | ||||
|  | ||||
| if(ENABLE_PROGRAMS) | ||||
|   | ||||
| @@ -50,7 +50,9 @@ function(add_test_suite suite_name) | ||||
|         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 | ||||
|   | ||||
| @@ -86,7 +86,7 @@ all: $(BINARIES) | ||||
| $(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 @@ src/drivers/%.o : src/drivers/%.c | ||||
| 	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 @@ $(BINARIES): %$(EXEXT): %.c $(MBEDLIBS) $(TEST_OBJS_DEPS) $(MBEDTLS_TEST_OBJS) | ||||
| 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 @@ else | ||||
| 	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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user