Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use the CMake macro #cmakedefine01 in configurable files.
authorMatthieu Volat <mazhe@alkumuna.eu>
Mon, 19 Dec 2016 16:38:50 +0000 (17:38 +0100)
committerAugustin Degomme <augustin.degomme@unibas.ch>
Mon, 19 Dec 2016 17:58:47 +0000 (18:58 +0100)
cmakedefine01 allows to perform C preprocessor replacements
that define a variable to 0 or 1 when configure_file is called,
instead of (not) defining the variable (see
https://cmake.org/cmake/help/v2.8.8/cmake.html#command:configure_file
for the 2.8.8 doc).

This ease the defining of config.h variables (no foreach loops
that preset them to 0), but two requirements must be met:
 1. variable name must match in cmake and config.h.in
 2. no comment on the macro line

CMakeLists.txt
include/simgrid_config.h.in
tools/cmake/Modules/FindLibunwind.cmake
tools/cmake/Tests.cmake
tools/cmake/src/internal_config.h.in

index 6a9c7c1..b2c7837 100644 (file)
@@ -179,12 +179,12 @@ include(CMakeDetermineSystem)
 IF(CMAKE_SYSTEM_PROCESSOR MATCHES ".86|AMD64|amd64")
   IF(CMAKE_SIZEOF_VOID_P EQUAL 4) # 32 bits
     message(STATUS "System processor: i686 (${CMAKE_SYSTEM_PROCESSOR}, 32 bits)")
-    set(PROCESSOR_i686 1)
-    set(PROCESSOR_x86_64 0)
+    set(SIMGRID_PROCESSOR_i686 1)
+    set(SIMGRID_PROCESSOR_x86_64 0)
   ELSE()
     message(STATUS "System processor: x86_64 (${CMAKE_SYSTEM_PROCESSOR}, 64 bits)")
-    set(PROCESSOR_i686 0)
-    set(PROCESSOR_x86_64 1)
+    set(SIMGRID_PROCESSOR_i686 0)
+    set(SIMGRID_PROCESSOR_x86_64 1)
   ENDIF()
   if (WIN32)
     message(STATUS "Disable fast raw contexts on Windows.")
@@ -192,8 +192,8 @@ IF(CMAKE_SYSTEM_PROCESSOR MATCHES ".86|AMD64|amd64")
     set(HAVE_RAW_CONTEXTS 1)
   endif()
 ELSE()
-  set(PROCESSOR_i686 0)
-  set(PROCESSOR_x86_64 0)
+  set(SIMGRID_PROCESSOR_i686 0)
+  set(SIMGRID_PROCESSOR_x86_64 0)
 ENDIF()
 
 include(CheckFunctionExists)
@@ -381,7 +381,7 @@ if(HAVE_LIBUNWIND)
     set(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-ptrace")
     # This supposes that the host machine is either an AMD or a X86.
     # This is deeply wrong, and should be fixed by manually loading -lunwind-PLAT (FIXME)
-    if(PROCESSOR_x86_64)
+    if(SIMGRID_PROCESSOR_x86_64)
       SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86_64")
     else()
       SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86")
@@ -665,22 +665,6 @@ endif()
 ### 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 HAVE_MREMAP HAVE_DLFUNC)
-  if(${var})
-    set(${var} 1)
-  else()
-    set(${var} 0)
-  endif()
-endforeach()
-
 # Avoid triggering a (full) rebuild by touching the files if they did not really change
 configure_file("${CMAKE_HOME_DIRECTORY}/tools/cmake/src/internal_config.h.in" "${CMAKE_BINARY_DIR}/src/internal_config.h.generated"    @ONLY IMMEDIATE)
 configure_file("${CMAKE_HOME_DIRECTORY}/include/simgrid_config.h.in"          "${CMAKE_BINARY_DIR}/include/simgrid_config.h.generated" @ONLY IMMEDIATE)
index d6808fc..7e54f41 100644 (file)
 
 #define SIMGRID_VERSION_STRING "@SIMGRID_VERSION_STRING@"
 
-#define HAVE_JEDULE     @HAVE_JEDULE@ /* Was Jedule compiled in?  */
-#define HAVE_LUA        @HAVE_LUA@ /* Was the Lua support compiled in? */
-#define HAVE_MALLOCATOR @HAVE_MALLOCATOR@ /* Were mallocators (object pools) compiled in? */
-#define HAVE_MC         @HAVE_MC@ /* Was the model-checking compiled in? */
-#define HAVE_NS3        @HAVE_NS3@ /* Was the NS3 support compiled in? */
+/* Was Jedule compiled in?  */
+#cmakedefine01 HAVE_JEDULE
+/* Was the Lua support compiled in? */
+#cmakedefine01 HAVE_LUA
+/* Were mallocators (object pools) compiled in? */
+#cmakedefine01 HAVE_MALLOCATOR
+/* Was the model-checking compiled in? */
+#cmakedefine01 HAVE_MC
+/* Was the NS3 support compiled in? */
+#cmakedefine01 HAVE_NS3
 
 #endif /* SIMGRID_PUBLIC_CONFIG_H */
index 67bcde6..87adb1b 100644 (file)
@@ -1,4 +1,4 @@
-if(PROCESSOR_x86_64)
+if(SIMGRID_PROCESSOR_x86_64)
   find_library(PATH_LIBUNWIND_LIB
     NAMES unwind-x86_64
     HINTS
index 4badb64..07e97ce 100644 (file)
@@ -60,7 +60,7 @@ ENDIF()
 IF(HAVE_MC)
   ADD_TESH_FACTORIES(mc-bugged1                "ucontext;raw" --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/mc --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/mc bugged1.tesh)
   ADD_TESH_FACTORIES(mc-bugged2                "ucontext;raw" --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/mc --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/mc bugged2.tesh)
-  IF(HAVE_UCONTEXT_CONTEXTS AND PROCESSOR_x86_64) # liveness model-checking works only on 64bits (for now ...)
+  IF(HAVE_UCONTEXT_CONTEXTS AND SIMGRID_PROCESSOR_x86_64) # liveness model-checking works only on 64bits (for now ...)
     ADD_TESH(mc-bugged1-liveness-ucontext         --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/mc --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/mc bugged1_liveness.tesh)
     ADD_TESH(mc-bugged1-liveness-ucontext-sparse  --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/mc --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/mc bugged1_liveness_sparse.tesh)
     ADD_TESH(mc-bugged1-liveness-visited-ucontext --setenv bindir=${CMAKE_BINARY_DIR}/examples/msg/mc --cd ${CMAKE_HOME_DIRECTORY}/examples/msg/mc bugged1_liveness_visited.tesh)
index b5c7fdc..f064746 100644 (file)
 #include "simgrid_config.h"       /* what was compiled in? */
 
 /* Non-standard header files */
-#define HAVE_EXECINFO_H @HAVE_EXECINFO_H@ /* <execinfo.h> */
-#define HAVE_FUTEX_H    @HAVE_FUTEX_H@ /* <linux/futex.h> */
-#define HAVE_SIGNAL_H   @HAVE_SIGNAL_H@ /* <signal.h> */
-#define HAVE_UNISTD_H   @HAVE_UNISTD_H@ /* <unistd.h> */
-#define HAVE_UCONTEXT_H @HAVE_UCONTEXT_H@ /* <ucontext.h> */
-#define HAVE_VALGRIND_H @HAVE_VALGRIND_H@ /* <valgrind/valgrind.h> */
+/* <execinfo.h> */
+#cmakedefine01 HAVE_EXECINFO_H
+/* <linux/futex.h> */
+#cmakedefine01 HAVE_FUTEX_H
+/* <signal.h> */
+#cmakedefine01 HAVE_SIGNAL_H
+/* <unistd.h> */
+#cmakedefine01 HAVE_UNISTD_H
+/* <ucontext.h> */
+#cmakedefine01 HAVE_UCONTEXT_H
+/* <valgrind/valgrind.h> */
+#cmakedefine01 HAVE_VALGRIND_H
 
 /* Time portability */
-#define HAVE_GETTIMEOFDAY  @HAVE_GETTIMEOFDAY@ /* Function gettimeofday */
-#define HAVE_POSIX_GETTIME @HAVE_POSIX_GETTIME@ /* Function clock_gettime */
-#define HAVE_NANOSLEEP     @HAVE_NANOSLEEP@ /* Function nanosleep */
+/* Function gettimeofday */
+#cmakedefine01 HAVE_GETTIMEOFDAY
+/* Function clock_gettime */
+#cmakedefine01 HAVE_POSIX_GETTIME
+/* Function nanosleep */
+#cmakedefine01 HAVE_NANOSLEEP
 
 /* The usable context factories */
-#define HAVE_BOOST_CONTEXTS    @HAVE_BOOST_CONTEXTS@
-#define HAVE_RAW_CONTEXTS      @HAVE_RAW_CONTEXTS@
-#define HAVE_THREAD_CONTEXTS   @HAVE_THREAD_CONTEXTS@
-#define HAVE_UCONTEXT_CONTEXTS @HAVE_UCONTEXT_CONTEXTS@
+#cmakedefine01 HAVE_BOOST_CONTEXTS
+#cmakedefine01 HAVE_RAW_CONTEXTS
+#cmakedefine01 HAVE_THREAD_CONTEXTS
+#cmakedefine01 HAVE_UCONTEXT_CONTEXTS
 
 /* Variables for the thread contexts (and parallel mode of raw contexts) */
-#define HAVE_PTHREAD              @HAVE_PTHREAD@ /* Define to 1 if threads are usable . */
-#define HAVE_PTHREAD_SETAFFINITY  @HAVE_PTHREAD_SETAFFINITY@ /* Does not seems defined on Mac nor Windows */
-#define HAVE_THREAD_LOCAL_STORAGE @HAVE_THREAD_LOCAL_STORAGE@ /* If __thread is available */
+/* Define to 1 if threads are usable . */
+#cmakedefine01 HAVE_PTHREAD
+/* Does not seems defined on Mac nor Windows */
+#cmakedefine01 HAVE_PTHREAD_SETAFFINITY
+/* If __thread is available */
+#cmakedefine01 HAVE_THREAD_LOCAL_STORAGE
 
 /* Variables for the raw contexts (to select the right assembly code) */
-#define SIMGRID_PROCESSOR_i686         @PROCESSOR_i686@
-#define SIMGRID_PROCESSOR_x86_64       @PROCESSOR_x86_64@
+#cmakedefine01 SIMGRID_PROCESSOR_i686
+#cmakedefine01 SIMGRID_PROCESSOR_x86_64
 
 /* Variables for the SysV contexts */
 @sg_makecontext_stack_addr@
 @sg_makecontext_stack_size@
 
 /* Variable for SysV, raw and Boost contexts */
-#cmakedefine PTH_STACKGROWTH @PTH_STACKGROWTH@ /* Does the stack growth upward, or downward? */
+/* Does the stack growth upward, or downward? */
+#cmakedefine01 PTH_STACKGROWTH
 
 /* MC variables */
-#define HAVE_GETDTABLESIZE    @HAVE_GETDTABLESIZE@ /* getdtablesize: get descriptor table size */
-#define HAVE_MMALLOC          @HAVE_MMALLOC@ /* Did we compile mmalloc in? */
-#define HAVE_PROCESS_VM_READV @HAVE_PROCESS_VM_READV@ /* process_vm_readv: transfer data between process address spaces */
-#define HAVE_MC               @HAVE_MC@ /* Set to true if enable_model-checking is true and the dependencies available */
+/* getdtablesize: get descriptor table size */
+#cmakedefine01 HAVE_GETDTABLESIZE
+/* Did we compile mmalloc in? */
+#cmakedefine01 HAVE_MMALLOC
+/* process_vm_readv: transfer data between process address spaces */
+#cmakedefine01 HAVE_PROCESS_VM_READV
+/* Set to true if enable_model-checking is true and the dependencies available */
+#cmakedefine01 HAVE_MC
 
 /* SMPI variables */
-#define HAVE_SMPI          @HAVE_SMPI@
-#define SMPI_FORTRAN       @SMPI_FORTRAN@
-#define HAVE_PRIVATIZATION @HAVE_PRIVATIZATION@ /* We have mmap and objdump to handle privatization */
-#define HAVE_PAPI          @HAVE_PAPI@ /* We have PAPI to fine-grain trace execution time */
+/* SMPI enabled */
+#cmakedefine01 HAVE_SMPI
+/* Fortran language is available for SMPI */
+#cmakedefine01 SMPI_FORTRAN
+/* We have mmap and objdump to handle privatization */
+#cmakedefine01 HAVE_PRIVATIZATION
+/* We have PAPI to fine-grain trace execution time */
+#cmakedefine01 HAVE_PAPI
 
 /* Other function checks */
-#define HAVE_BACKTRACE @HAVE_BACKTRACE@ /* Function backtrace */
-#define HAVE_DLFUNC    @HAVE_DLFUNC@ /* Function dlfunc */
-#define HAVE_MMAP      @HAVE_MMAP@ /* Function mmap */
-#define HAVE_MREMAP    @HAVE_MREMAP@ /* Function mremap */
-#define HAVE_SEM_INIT  @HAVE_SEM_INIT@ /* Function sem_init (part of XPG6 standard only) */
-#define HAVE_POPEN     @HAVE_POPEN@ /* Function popen */
-#define HAVE_SYSCONF   @HAVE_SYSCONF@ /* Function sysconf */
-#define HAVE_VASPRINTF @HAVE_VASPRINTF@ /* Function vasprintf */
+/* Function backtrace */
+#cmakedefine01 HAVE_BACKTRACE
+/* Function dlfunc */
+#cmakedefine01 HAVE_DLFUNC
+/* Function mmap */
+#cmakedefine01 HAVE_MMAP
+/* Function mremap */
+#cmakedefine01 HAVE_MREMAP
+/* Function sem_init (part of XPG6 standard only) */
+#cmakedefine01 HAVE_SEM_INIT
+/* Function popen */
+#cmakedefine01 HAVE_POPEN
+/* Function sysconf */
+#cmakedefine01 HAVE_SYSCONF
+/* Function vasprintf */
+#cmakedefine01 HAVE_VASPRINTF
 
 /* Other checks */
-#cmakedefine ADDR2LINE       "@ADDR2LINE@" /* Path to the addr2line tool */
-#define HAVE_GRAPHVIZ   @HAVE_GRAPHVIZ@ /* The graphviz library */
-#define HAVE_LIBUNWIND  @HAVE_LIBUNWIND@ /* The lib unwind library (for MC and backtrace display) */
+/* Path to the addr2line tool */
+#cmakedefine   ADDR2LINE "@ADDR2LINE@"
+/* The graphviz library */
+#cmakedefine01 HAVE_GRAPHVIZ
+/* The lib unwind library (for MC and backtrace display) */
+#cmakedefine01 HAVE_LIBUNWIND