From c88cf32b9f502dc7beda25a8cd97e6e075619afd Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Tue, 2 Jul 2024 14:26:38 -0700 Subject: [PATCH 1/2] Only link pthread lib for WAMR_BUILD_LIB_PTHREAD --- CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 761ac574ae..cabfaaf49c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,7 +147,10 @@ if (WAMR_BUILD_STATIC) add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE}) set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib) target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include) - target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread) + target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl) + if (WAMR_BUILD_LIB_PTHREAD EQUAL 1) + target_link_libraries (iwasm_static INTERFACE -lpthread) + endif() if (WAMR_BUILD_WASM_CACHE EQUAL 1) target_link_libraries(iwasm_static INTERFACE boringssl_crypto) endif () @@ -160,7 +163,10 @@ if (WAMR_BUILD_SHARED) add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE}) set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm) target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include) - target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread) + target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl) + if (WAMR_BUILD_LIB_PTHREAD EQUAL 1) + target_link_libraries (iwasm_shared INTERFACE -lpthread) + endif() if (WAMR_BUILD_WASM_CACHE EQUAL 1) target_link_libraries(iwasm_shared INTERFACE boringssl_crypto) endif () From a1b655d7ab4671de0c9fe3a5873736c372583869 Mon Sep 17 00:00:00 2001 From: Benbuck Nason Date: Wed, 3 Jul 2024 11:26:36 -0700 Subject: [PATCH 2/2] Better fix to pthread link dependency --- CMakeLists.txt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cabfaaf49c..bedf0af6c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,15 +142,15 @@ endif () include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) +set (THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) + # STATIC LIBRARY if (WAMR_BUILD_STATIC) add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE}) set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib) target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include) - target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl) - if (WAMR_BUILD_LIB_PTHREAD EQUAL 1) - target_link_libraries (iwasm_static INTERFACE -lpthread) - endif() + target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT}) if (WAMR_BUILD_WASM_CACHE EQUAL 1) target_link_libraries(iwasm_static INTERFACE boringssl_crypto) endif () @@ -163,10 +163,7 @@ if (WAMR_BUILD_SHARED) add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE}) set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm) target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include) - target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl) - if (WAMR_BUILD_LIB_PTHREAD EQUAL 1) - target_link_libraries (iwasm_shared INTERFACE -lpthread) - endif() + target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl ${CMAKE_THREAD_LIBS_INIT}) if (WAMR_BUILD_WASM_CACHE EQUAL 1) target_link_libraries(iwasm_shared INTERFACE boringssl_crypto) endif ()