[Piglit] [PATCH] cmake: Check for asprintf.

Brian Paul brianp at vmware.com
Sun Dec 22 06:27:52 PST 2013


On 12/21/2013 02:32 PM, Vinson Lee wrote:
> Newer versions of MinGW provide asprintf in stdio.h. Do not define
> asprintf if it already exists.
>
> This patch fixes the Fedora 20 MinGW build.
>
> Signed-off-by: Vinson Lee <vlee at freedesktop.org>
> ---
>   CMakeLists.txt           | 1 +
>   tests/util/config.h.in   | 1 +
>   tests/util/piglit-util.c | 4 ++--
>   tests/util/piglit-util.h | 4 ++--
>   4 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> index e952e24..6092f99 100644
> --- a/CMakeLists.txt
> +++ b/CMakeLists.txt
> @@ -324,6 +324,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${piglit_BINARY_DIR}/bin)
>   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${piglit_BINARY_DIR}/bin)
>   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${piglit_BINARY_DIR}/bin)
>
> +check_function_exists(asprintf  HAVE_ASPRINTF)
>   check_function_exists(strchrnul HAVE_STRCHRNUL)
>   check_function_exists(strndup   HAVE_STRNDUP)
>   check_function_exists(fopen_s   HAVE_FOPEN_S)
> diff --git a/tests/util/config.h.in b/tests/util/config.h.in
> index 2e8262a..691a249 100644
> --- a/tests/util/config.h.in
> +++ b/tests/util/config.h.in
> @@ -1,3 +1,4 @@
> +#cmakedefine HAVE_ASPRINTF
>   #cmakedefine HAVE_STRCHRNUL
>   #cmakedefine HAVE_FOPEN_S
>   #cmakedefine HAVE_SETRLIMIT
> diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
> index 1c7f118..fe49fed 100644
> --- a/tests/util/piglit-util.c
> +++ b/tests/util/piglit-util.c
> @@ -56,7 +56,7 @@
>   #include "piglit-util.h"
>
>
> -#if defined(_WIN32)
> +#ifndef HAVE_ASPRINTF
>
>   /* Some versions of MinGW are missing _vscprintf's declaration, although they
>    * still provide the symbol in the import library.
> @@ -103,7 +103,7 @@ int asprintf(char **strp, const char *fmt, ...)
>   	return length;
>   }
>
> -#endif /* _WIN32 */
> +#endif /* HAVE_ASPRINTF */
>
>   /**
>    * \brief Split \a string into an array of strings.
> diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
> index 4535fad..db880c7 100644
> --- a/tests/util/piglit-util.h
> +++ b/tests/util/piglit-util.h
> @@ -84,9 +84,9 @@ lround(double x) {
>   #define PRINTFLIKE(f, a)
>   #endif
>
> -#ifdef _WIN32
> +#ifndef HAVE_ASPRINTF
>   int asprintf(char **strp, const char *fmt, ...) PRINTFLIKE(2, 3);
> -#endif /* _WIN32 */
> +#endif /* HAVE_ASPRINTF */
>
>   // Trick from https://urldefense.proofpoint.com/v1/url?u=http://tdistler.com/2011/03/24/how-to-define-nan-not-a-number-on-windows&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=lGQMzzTgII0I7jefp2FHq7WtZ%2BTLs8wadB%2BiIj9xpBY%3D%0A&m=B9FQT9xPZisThoztsRIIsb2v4JD4DAjsVwrD7xgTBvg%3D%0A&s=4d821799162f254b69415e626d846674a60f45ae0fc42617cc5a630985b94365
>   #ifndef INFINITY
>

That seems to work on my system.  Thanks.

Tested-by: Brian Paul <brianp at vmware.com>



More information about the Piglit mailing list