Am Freitag, 4. Januar 2013 um 14:59:23, schrieb Mateusz Loskot 
<[email protected]>
> On 4 January 2013 14:46, Bill Hoffman <[email protected]> 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

Attachment: signature.asc
Description: This is a digitally signed message part.

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to