Ver Fonte

CMakeLists.txt: Fix Android pthread linkage (#3591)

https://developer.android.com/ndk/guides/stable_apis#core_cc

> Note that on Android, unlike Linux, there are no separate libpthread or librt libraries.
That functionality is included directly in libc, which does not need to be explicitly linked against.

Set `THREADS_PREFER_PTHREAD_FLAG` ON and find package `Threads`, then link
`${CMAKE_THREAD_LIBS_INIT}` instead of `-lpthread`.

ps.
https://cmake.org/cmake/help/latest/module/FindThreads.html
Benbuck Nason há 1 ano atrás
pai
commit
777121217e
1 ficheiros alterados com 5 adições e 2 exclusões
  1. 5 2
      CMakeLists.txt

+ 5 - 2
CMakeLists.txt

@@ -142,12 +142,15 @@ endif ()
 
 
 include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
 include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
 
 
+set (THREADS_PREFER_PTHREAD_FLAG ON)
+find_package(Threads REQUIRED)
+
 # STATIC LIBRARY
 # STATIC LIBRARY
 if (WAMR_BUILD_STATIC)
 if (WAMR_BUILD_STATIC)
     add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
     add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
     set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
     set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
     target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
     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 ${CMAKE_THREAD_LIBS_INIT})
     if (WAMR_BUILD_WASM_CACHE EQUAL 1)
     if (WAMR_BUILD_WASM_CACHE EQUAL 1)
       target_link_libraries(iwasm_static INTERFACE boringssl_crypto)
       target_link_libraries(iwasm_static INTERFACE boringssl_crypto)
     endif ()
     endif ()
@@ -160,7 +163,7 @@ if (WAMR_BUILD_SHARED)
     add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
     add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
     set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
     set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
     target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
     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 ${CMAKE_THREAD_LIBS_INIT})
     if (WAMR_BUILD_WASM_CACHE EQUAL 1)
     if (WAMR_BUILD_WASM_CACHE EQUAL 1)
       target_link_libraries(iwasm_shared INTERFACE boringssl_crypto)
       target_link_libraries(iwasm_shared INTERFACE boringssl_crypto)
     endif ()
     endif ()