[CMake] AC_C_RESTRICT

Kornel Benko kornel at lyx.org
Fri Jan 4 10:42:59 EST 2013


Am Freitag, 4. Januar 2013 um 14:59:23, schrieb Mateusz Loskot <mateusz at loskot.net>
> On 4 January 2013 14:46, Bill Hoffman <bill.hoffman at kitware.com> wrote:
> > On 1/4/2013 9:24 AM, Mateusz Loskot wrote:
> >>
> >> It tests if C compiler supports C99 restrict keyword,
> >> perhaps also implementation-specific form, e.g. __restrict, etc.
> >>
> >> [1]http://en.wikipedia.org/wiki/Restrict
> >
> > Should be able to do it with a CheckCSourceCompiles:
> >
> >
> > http://www.cmake.org/cmake/help/v2.8.10/cmake.html#module:CheckCSourceCompiles
> 
> Yup:
> 
> CHECK_C_SOURCE_COMPILES (
>   "int test (void *restrict x); int main (void) {return 0;}"
>   HAVE_RESTRICT)

I implemented it now this way (used the autoconf macro as guide :

# Check for restrict keyword
# Builds the macro A_C_RESTRICT form automake
foreach(ac_kw __restrict __restrict__ _Restrict restrict)
  check_cxx_source_compiles(
  "
  typedef int * int_ptr;
  int foo (int_ptr ${ac_kw} ip) {
    return ip[0];
  }
  int main(){
    int s[1];
    int * ${ac_kw} t = s;
    t[0] = 0;
    return foo(t);
  }
  "
  RESTRICT)
  if(RESTRICT)
    set(ac_cv_c_restrict ${ac_kw})
    break()
  endif()
endforeach()
if(RESTRICT)
  add_definitions("-Drestrict=${ac_cv_c_restrict}")
else()
  add_definitions("-Drestrict=")
endif()

Thanks to all replies.

	Kornel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130104/4f287752/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130104/4f287752/attachment.pgp>


More information about the CMake mailing list