-if(GIT_VERSION)
- set(SIMGRID_VERSION_BANNER "${SIMGRID_VERSION_BANNER} at commit ${GIT_VERSION}")
-endif()
-if(GIT_DATE)
- set(SIMGRID_VERSION_BANNER "${SIMGRID_VERSION_BANNER} (${GIT_DATE})")
-endif()
-#--------------------------------------------------------------------------------------------------
-
-set(makecontext_CPPFLAGS_2 "")
-if(HAVE_UCONTEXT_H)
- set(makecontext_CPPFLAGS "-DTEST_makecontext")
- if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
- set(makecontext_CPPFLAGS_2 "-D_XOPEN_SOURCE=700")
- endif()
-
- if(WIN32)
- if(ARCH_32_BITS)
- set(makecontext_CPPFLAGS "-DTEST_makecontext -D_I_X86_")
- else()
- set(makecontext_CPPFLAGS "-DTEST_makecontext -D_AMD64_")
- endif()
- set(makecontext_CPPFLAGS_2 "-D_XBT_WIN32 -I${CMAKE_HOME_DIRECTORY}/src/include -I${CMAKE_HOME_DIRECTORY}/src/xbt")
- endif()
-
- file(REMOVE ${CMAKE_BINARY_DIR}/conftestval)
-
- if(CMAKE_CROSSCOMPILING)
- set(RUN_makecontext_VAR "cross")
- set(COMPILE_makecontext_VAR "cross")
- else()
- try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
- ${CMAKE_BINARY_DIR}
- ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stacksetup.c
- COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}"
- )
- endif()
-
- if(EXISTS ${CMAKE_BINARY_DIR}/conftestval)
- file(READ ${CMAKE_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE)
- string(REPLACE "\n" "" MAKECONTEXT_ADDR_SIZE "${MAKECONTEXT_ADDR_SIZE}")
- string(REGEX MATCH ;^.*,;MAKECONTEXT_ADDR "${MAKECONTEXT_ADDR_SIZE}")
- string(REGEX MATCH ;,.*$; MAKECONTEXT_SIZE "${MAKECONTEXT_ADDR_SIZE}")
- string(REPLACE "," "" makecontext_addr "${MAKECONTEXT_ADDR}")
- string(REPLACE "," "" makecontext_size "${MAKECONTEXT_SIZE}")
- set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
- set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
- else()
- # message(FATAL_ERROR "makecontext is not compilable")
- endif()
-endif()
-
-#--------------------------------------------------------------------------------------------------
-
-### check for stackgrowth
-if (NOT CMAKE_CROSSCOMPILING)
- try_run(RUN_stackgrowth_VAR COMPILE_stackgrowth_VAR
- ${CMAKE_BINARY_DIR}
- ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stackgrowth.c
- RUN_OUTPUT_VARIABLE stack
- COPY_FILE test_stackgrowth
- )
-endif()
-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")
- elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
- set(PTH_STACKGROWTH "-1")
+### Generate the required headers and scripts
+#############################################
+
+# gcc makes no difference between "#define HAVE_FOOBAR" and "#define HAVE_FOOBAR 0" by default,
+# but this too error prone. If you forget to include the config.h, you get weird segfaults.
+# If you include it everywhere, everything gets recompiled everytime.
+# So we include only where needed, and compile with -Wundef to notice the missing includes.
+# But cmake sometimes defines to the empty definition (#define HAVE_VALGRIND_H).
+# So we have to make sure that everything got a decent value before generating the files.
+foreach(var HAVE_BACKTRACE HAVE_EXECINFO_H HAVE_FUTEX_H HAVE_GETDTABLESIZE HAVE_GETTIMEOFDAY HAVE_MMAP HAVE_NANOSLEEP HAVE_POPEN
+ HAVE_POSIX_GETTIME HAVE_PROCESS_VM_READV HAVE_SIGNAL_H HAVE_SYS_PARAM_H HAVE_SYS_SYSCTL_H HAVE_SYSCONF
+ HAVE_UCONTEXT_H HAVE_UNISTD_H HAVE_VALGRIND_H HAVE_VASPRINTF)
+ if(${var})
+ set(${var} 1)