[Piglit] [PATCH 12/13] cmake: Check for pthreads

Jose Fonseca jfonseca at vmware.com
Thu Mar 27 08:08:50 PDT 2014


I think it would be more portable to use FindThreads module that comes with cmake. e.g.:

  find_package (Threads)

  target_link_libraries (my_program
    ${CMAKE_THREAD_LIBS_INIT}
  )

  if (CMAKE_USE_PTHREADS_INIT)
    add_definitions(-DPIGLIT_HAS_PTHREADS)
  endif ()

etc.

Jose


----- Original Message -----
> Set PIGLIT_HAS_PTHREADS as a CMake variable and cpp feature macro if
> CMake succeeds in compiling a small test file that uses pthread_self(),
> 
> Future EGL_KHR_fence_sync tests will be multi-threaded.
> 
> Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
> ---
>  CMakeLists.txt | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index bef9c35..88a1483 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -318,6 +318,24 @@ if(PIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
>  	add_definitions(-DPIGLIT_HAS_POSIX_CLOCK_MONOTONIC)
>  endif()
>  
> +# Set PIGLIT_HAS_PTHREADS.
> +FIND_LIBRARY(HAVE_PTHREADS pthread)
> +if(HAVE_PTHREADS)
> +	set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} pthread)
> +endif()
> +check_c_source_compiles(
> +	"
> +	#include <pthread.h>
> +	int main() { return (int) pthread_self(); }
> +	"
> +	PIGLIT_HAS_PTHREADS
> +)
> +set(CMAKE_REQUIRED_LIBRARIES)
> +
> +if(PIGLIT_HAS_PTHREADS)
> +	add_definitions(-DPIGLIT_HAS_PTHREADS)
> +endif()
> +
>  if(PIGLIT_USE_WAFFLE AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
>  	pkg_check_modules(EGL egl)
>  endif()
> --
> 1.8.5.3
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/piglit&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=NMr9uy2iTjWVixC0wOcYCWEIYhfo80qKwRgdodpoDzA%3D%0A&m=dqhwi8i3TQOA%2BYc%2B9Lt8Hr8qdD1Pq5IHEOQftTgLs6k%3D%0A&s=19d978fcff39feed5c593c08e824288d85559e42ff17cd46c94303301d4c2271
> 


More information about the Piglit mailing list