[PATCH] D21478: [build] Link main executable with libpthread

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 10:51:51 PDT 2016


beanz added inline comments.

================
Comment at: cmake/config-ix.cmake:115
@@ +114,3 @@
+  find_package(Threads REQUIRED)
+  # Strip -l prefix, because we expect unprefixed name in PTHREAD_LIB
+  string(REGEX REPLACE "^-l" "" PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT})
----------------
Rather than this, try setting `THREADS_PREFER_PTHREAD_FLAG`. That will prefer the -pthreds flag if the compiler supports it.

Even with that you can't actually assume that the flag returned here will be `-pthread` instead of `-lpthread` because I'm pretty sure we support using pthreads library with compilers that don't support `-pthread`.

================
Comment at: cmake/modules/AddLLVM.cmake:677
@@ +676,3 @@
+    # API for all shared libaries loaded by this executable.
+    target_link_libraries(${name} ${PTHREAD_LIB})
+  endif()
----------------
Since this would be a flag rather than a library, maybe you should change your calls to target_link_libraries to something more like this:


```
set_property(TARGET ${name} APPEND_STRING PROPERTY
             LINK_FLAGS "${PTHREAD_LIB}")
```

I'd also suggest changing `PTHREAD_LIB` to `PTHREAD_FLAG` because that is more representative of what you're actually using here.


http://reviews.llvm.org/D21478





More information about the llvm-commits mailing list