From 4068c7e47cf7180550c7a52e3c5f6513392c7720 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 15 Dec 2023 17:14:34 +0000 Subject: [PATCH] Link programs with pthread via cmake All programs are now linked directly with all test code, thus adding a pthread abstraction into the test code means having to link the programs with pthread (if the library is found under cmake). Signed-off-by: Paul Elliott --- programs/aes/CMakeLists.txt | 4 +++- programs/cipher/CMakeLists.txt | 4 +++- programs/fuzz/CMakeLists.txt | 3 +++ programs/fuzz/Makefile | 4 ++++ programs/hash/CMakeLists.txt | 4 +++- programs/pkey/CMakeLists.txt | 6 ++++-- programs/psa/CMakeLists.txt | 4 +++- programs/random/CMakeLists.txt | 4 +++- programs/ssl/CMakeLists.txt | 2 +- programs/test/CMakeLists.txt | 8 +++++--- programs/test/cmake_subproject/CMakeLists.txt | 4 +++- programs/util/CMakeLists.txt | 4 +++- programs/x509/CMakeLists.txt | 4 +++- 13 files changed, 41 insertions(+), 14 deletions(-) diff --git a/programs/aes/CMakeLists.txt b/programs/aes/CMakeLists.txt index 85bcd5fcad..457a0fc26f 100644 --- a/programs/aes/CMakeLists.txt +++ b/programs/aes/CMakeLists.txt @@ -1,10 +1,12 @@ +find_package(Threads) + set(executables crypt_and_hash ) foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/cipher/CMakeLists.txt b/programs/cipher/CMakeLists.txt index 93e5f31ee8..c047dd69e8 100644 --- a/programs/cipher/CMakeLists.txt +++ b/programs/cipher/CMakeLists.txt @@ -1,10 +1,12 @@ +find_package(Threads) + set(executables cipher_aead_demo ) foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/fuzz/CMakeLists.txt b/programs/fuzz/CMakeLists.txt index 7747744cd1..a0eba0fd0f 100644 --- a/programs/fuzz/CMakeLists.txt +++ b/programs/fuzz/CMakeLists.txt @@ -1,5 +1,8 @@ +find_package(Threads) + set(libs ${mbedtls_target} + ${CMAKE_THREAD_LIBS_INIT} ) find_library(FUZZINGENGINE_LIB FuzzingEngine) diff --git a/programs/fuzz/Makefile b/programs/fuzz/Makefile index b4fc76ae11..3b9b50df83 100644 --- a/programs/fuzz/Makefile +++ b/programs/fuzz/Makefile @@ -29,6 +29,10 @@ endif ifdef WINDOWS_BUILD LOCAL_LDFLAGS += -lbcrypt +else +ifeq ($(THREADING),pthread) +LOCAL_LDFLAGS += -lpthread +endif endif # A test application is built for each suites/test_suite_*.data file. diff --git a/programs/hash/CMakeLists.txt b/programs/hash/CMakeLists.txt index da98188443..3d6989cca5 100644 --- a/programs/hash/CMakeLists.txt +++ b/programs/hash/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(executables generic_sum hello @@ -6,7 +8,7 @@ set(executables foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/pkey/CMakeLists.txt b/programs/pkey/CMakeLists.txt index 3ad56436e6..e2fb404029 100644 --- a/programs/pkey/CMakeLists.txt +++ b/programs/pkey/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(executables_mbedtls dh_client dh_server @@ -5,7 +7,7 @@ set(executables_mbedtls foreach(exe IN LISTS executables_mbedtls) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedtls_target}) + target_link_libraries(${exe} ${mbedtls_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() @@ -32,7 +34,7 @@ set(executables_mbedcrypto foreach(exe IN LISTS executables_mbedcrypto) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt index c8ee626d81..d86f29e2c2 100644 --- a/programs/psa/CMakeLists.txt +++ b/programs/psa/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(executables aead_demo crypto_examples @@ -28,7 +30,7 @@ endif() foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/random/CMakeLists.txt b/programs/random/CMakeLists.txt index e5edf7b58c..a4c99f5613 100644 --- a/programs/random/CMakeLists.txt +++ b/programs/random/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(executables gen_entropy gen_random_ctr_drbg @@ -5,7 +7,7 @@ set(executables foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/ssl/CMakeLists.txt b/programs/ssl/CMakeLists.txt index 280bbcf3d2..8ffa854647 100644 --- a/programs/ssl/CMakeLists.txt +++ b/programs/ssl/CMakeLists.txt @@ -39,7 +39,7 @@ foreach(exe IN LISTS executables) endif() add_executable(${exe} ${exe}.c $ ${extra_sources}) - target_link_libraries(${exe} ${libs}) + target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) if(exe STREQUAL "ssl_client2" OR exe STREQUAL "ssl_server2") if(GEN_FILES) diff --git a/programs/test/CMakeLists.txt b/programs/test/CMakeLists.txt index 0778731125..a7260452fc 100644 --- a/programs/test/CMakeLists.txt +++ b/programs/test/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(libs ${mbedtls_target} ) @@ -26,7 +28,7 @@ if(TEST_CPP) ) add_executable(cpp_dummy_build "${cpp_dummy_build_cpp}") target_include_directories(cpp_dummy_build PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include) - target_link_libraries(cpp_dummy_build ${mbedcrypto_target}) + target_link_libraries(cpp_dummy_build ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) endif() if(USE_SHARED_MBEDTLS_LIBRARY AND @@ -81,9 +83,9 @@ foreach(exe IN LISTS executables_libs executables_mbedcrypto) # This emulates "if ( ... IN_LIST ... )" which becomes available in CMake 3.3 list(FIND executables_libs ${exe} exe_index) if (${exe_index} GREATER -1) - target_link_libraries(${exe} ${libs}) + target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT}) else() - target_link_libraries(${exe} ${mbedcrypto_target}) + target_link_libraries(${exe} ${mbedcrypto_target} ${CMAKE_THREAD_LIBS_INIT}) endif() endforeach() diff --git a/programs/test/cmake_subproject/CMakeLists.txt b/programs/test/cmake_subproject/CMakeLists.txt index 3c3cba3c2d..dd23d6165f 100644 --- a/programs/test/cmake_subproject/CMakeLists.txt +++ b/programs/test/cmake_subproject/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.5.1) +find_package(Threads) + # Test the target renaming support by adding a prefix to the targets built set(MBEDTLS_TARGET_PREFIX subproject_test_) @@ -20,4 +22,4 @@ set(libs ) add_executable(cmake_subproject cmake_subproject.c) -target_link_libraries(cmake_subproject ${libs}) +target_link_libraries(cmake_subproject ${libs} ${CMAKE_THREAD_LIBS_INIT}) diff --git a/programs/util/CMakeLists.txt b/programs/util/CMakeLists.txt index 7fc58cbcf4..920f69e880 100644 --- a/programs/util/CMakeLists.txt +++ b/programs/util/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(libs ${mbedcrypto_target} ) @@ -9,7 +11,7 @@ set(executables foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${libs}) + target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach() diff --git a/programs/x509/CMakeLists.txt b/programs/x509/CMakeLists.txt index 5876b8d21d..c507de2a74 100644 --- a/programs/x509/CMakeLists.txt +++ b/programs/x509/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Threads) + set(libs ${mbedx509_target} ) @@ -13,7 +15,7 @@ set(executables foreach(exe IN LISTS executables) add_executable(${exe} ${exe}.c $) - target_link_libraries(${exe} ${libs}) + target_link_libraries(${exe} ${libs} ${CMAKE_THREAD_LIBS_INIT}) target_include_directories(${exe} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../tests/include) endforeach()