Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify the stack direction detection
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 9 Jun 2015 14:50:29 +0000 (16:50 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 9 Jun 2015 14:50:29 +0000 (16:50 +0200)
For some reason, it did not work on Windows.

buildtools/Cmake/CompleteInFiles.cmake
buildtools/Cmake/test_prog/prog_stackgrowth.c

index 7310817..ba8db2b 100644 (file)
@@ -634,20 +634,18 @@ if (NOT CMAKE_CROSSCOMPILING)
   try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
     ${CMAKE_BINARY_DIR}
     ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stackgrowth.c
   try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
     ${CMAKE_BINARY_DIR}
     ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stackgrowth.c
+    RUN_OUTPUT_VARIABLE stack
     )
     )
-  if (RUN_makecontext_VAR)
-    file(READ "${CMAKE_BINARY_DIR}/conftestval" stack)
-    if(stack MATCHES "down")
-      set(PTH_STACKGROWTH "-1")
-    endif()
-    if(stack MATCHES "up")
-      set(PTH_STACKGROWTH "1")
-    endif()
-  endif()
 endif()
 endif()
-if(NOT PTH_STACKGROWTH)
+if("${stack}" STREQUAL "down")
+  set(PTH_STACKGROWTH "-1")
+elseif("${stack}" STREQUAL "up")
+  set(PTH_STACKGROWTH "1")
+else()
   if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
     set(PTH_STACKGROWTH "-1")
   if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
     set(PTH_STACKGROWTH "-1")
+  elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
+    set(PTH_STACKGROWTH "-1")
   else()
     message(ERROR "Could not figure the stack direction.")
   endif()
   else()
     message(ERROR "Could not figure the stack direction.")
   endif()
index 81aff74..52a2363 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
+
 static int iterate = 10;
 static int growsdown(int *x)
 {
 static int iterate = 10;
 static int growsdown(int *x)
 {
@@ -20,12 +21,8 @@ static int growsdown(int *x)
 
 int main(int argc, char *argv[])
 {
 
 int main(int argc, char *argv[])
 {
-  FILE *f;
   auto int x;
   auto int x;
-  if ((f = fopen("conftestval", "w")) == NULL)
-    exit(1);
-  fprintf(f, "%s\n", growsdown(&x) ? "down" : "up");;
-  fclose(f);
+  printf("%s", growsdown(&x) ? "down" : "up");
   exit(0);
   return 1;
 }
   exit(0);
   return 1;
 }