Revision: 50653
          http://brlcad.svn.sourceforge.net/brlcad/?rev=50653&view=rev
Author:   starseeker
Date:     2012-05-24 15:26:12 +0000 (Thu, 24 May 2012)
Log Message:
-----------
This should improve the behavior and robustness of the type checking macro in 
BRL-CAD.  While we're at it, make the variable names automatic and deduced from 
the type itself.

Modified Paths:
--------------
    brlcad/trunk/CMakeLists.txt
    brlcad/trunk/misc/CMake/BRLCAD_CheckFunctions.cmake

Modified: brlcad/trunk/CMakeLists.txt
===================================================================
--- brlcad/trunk/CMakeLists.txt 2012-05-24 13:22:17 UTC (rev 50652)
+++ brlcad/trunk/CMakeLists.txt 2012-05-24 15:26:12 UTC (rev 50653)
@@ -1595,19 +1595,19 @@
 BRLCAD_STRUCT_MEMBER("struct stat" st_rdev sys/stat.h STRUCT_STAT_ST_RDEV)
 
 # socklen_t
-BRLCAD_TYPE_SIZE("socklen_t" SOCKLEN_T "sys/types.h")
-if(NOT SOCKLEN_T)
-  BRLCAD_TYPE_SIZE("socklen_t" SOCKLEN_T "sys/socket.h")
-endif(NOT SOCKLEN_T)
+BRLCAD_TYPE_SIZE("socklen_t" "sys/types.h")
+if(NOT HAVE_SOCKLEN_T)
+  BRLCAD_TYPE_SIZE("socklen_t" "sys/socket.h")
+endif(NOT HAVE_SOCKLEN_T)
 
-BRLCAD_TYPE_SIZE("int" INT "")
-BRLCAD_TYPE_SIZE("long" LONG "")
-BRLCAD_TYPE_SIZE("long long" LONG_LONG "")
-BRLCAD_TYPE_SIZE("size_t" SIZE "")
-BRLCAD_TYPE_SIZE("ssize_t" SSIZE "")
-BRLCAD_TYPE_SIZE("uint64_t" UINT64 "")
-BRLCAD_TYPE_SIZE("uintptr_t" UINTPTR "")
-BRLCAD_TYPE_SIZE("sig_t" SIG "signal.h")
+BRLCAD_TYPE_SIZE("int" "")
+BRLCAD_TYPE_SIZE("long" "")
+BRLCAD_TYPE_SIZE("long long" "")
+BRLCAD_TYPE_SIZE("size_t" "")
+BRLCAD_TYPE_SIZE("ssize_t" "")
+BRLCAD_TYPE_SIZE("uint64_t" "")
+BRLCAD_TYPE_SIZE("uintptr_t" "")
+BRLCAD_TYPE_SIZE("sig_t" "signal.h")
 
 # see if the compiler supports %z as a size_t print width specifier
 BRLCAD_CHECK_C99_FORMAT_SPECIFIERS()

Modified: brlcad/trunk/misc/CMake/BRLCAD_CheckFunctions.cmake
===================================================================
--- brlcad/trunk/misc/CMake/BRLCAD_CheckFunctions.cmake 2012-05-24 13:22:17 UTC 
(rev 50652)
+++ brlcad/trunk/misc/CMake/BRLCAD_CheckFunctions.cmake 2012-05-24 15:26:12 UTC 
(rev 50653)
@@ -104,16 +104,28 @@
 # header list may be specified.  Adds HAVE_ and SIZEOF_ defines to
 # config header.
 ###
-macro(BRLCAD_TYPE_SIZE typename var headers)
+macro(BRLCAD_TYPE_SIZE typename headers)
   set(CMAKE_C_FLAGS_TMP "${CMAKE_C_FLAGS}")
   set(CMAKE_C_FLAGS "")
+  set(CMAKE_EXTRA_INCLUDE_FILES_BAK "${CMAKE_EXTRA_INCLUDE_FILES}")
   set(CMAKE_EXTRA_INCLUDE_FILES "${headers}")
-  CHECK_TYPE_SIZE(${typename} HAVE_${var}_T)
-  set(CMAKE_EXTRA_INCLUDE_FILES)
-  if(CONFIG_H_FILE AND HAVE_${var}_T)
-    CONFIG_H_APPEND(BRLCAD "#define HAVE_${var}_T 1\n")
-    CONFIG_H_APPEND(BRLCAD "#define SIZEOF_${var}_T ${HAVE_${var}_T}\n")
-  endif(CONFIG_H_FILE AND HAVE_${var}_T)
+  # Generate a variable name from the type - need to make sure
+  # we end up with a valid variable string.
+  string(REGEX REPLACE "[^a-zA-Z0-9]" "_" var ${typename})
+  string(TOUPPER "${var}" var)
+  # Proceed with type check.  To make sure checks are re-run when
+  # re-testing the same type with different headers, create a test 
+  # variable incorporating both the typename and the headers string
+  string(REGEX REPLACE "[^a-zA-Z0-9]" "_" testvar "HAVE_${typename}${headers}")
+  string(TOUPPER "${testvar}" testvar)
+  CHECK_TYPE_SIZE(${typename} ${testvar})
+  set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES_BAK}")
+  # Produce config.h lines as appropriate
+  if(CONFIG_H_FILE AND ${testvar})
+  message("var: ${var} testvar: ${testvar}: ${${testvar}}")
+    CONFIG_H_APPEND(BRLCAD "#define HAVE_${var} 1\n")
+    CONFIG_H_APPEND(BRLCAD "#define SIZEOF_${var} ${${testvar}}\n")
+  endif(CONFIG_H_FILE AND ${testvar})
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_TMP}")
 endmacro(BRLCAD_TYPE_SIZE)
 
@@ -155,9 +167,13 @@
 
 # Special purpose macros
 
+# Load local variation on CHECK_C_SOURCE_RUNS that will accept a
+# C file as well as the actual C code - some tests are easier to
+# define in separate files.  This feature has been submitted back
+# to the CMake project, but as of CMake 2.8.7 is not part of the
+# default CHECK_C_SOURCE_RUNS functionality.
 include(CheckCSourceRuns)
 
-
 ###
 # Undocumented.
 ###
@@ -177,7 +193,6 @@
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_TMP}")
 endmacro(BRLCAD_CHECK_BASENAME var)
 
-
 ###
 # Undocumented.
 ###
@@ -197,14 +212,6 @@
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_TMP}")
 endmacro(BRLCAD_CHECK_DIRNAME var)
 
-
-# Load local variation on CHECK_C_SOURCE_RUNS that will accept a
-# C file as well as the actual C code - some tests are easier to
-# define in separate files.  This feature has been submitted back
-# to the CMake project, but as of CMake 2.8.7 is not part of the
-# default CHECK_C_SOURCE_RUNS functionality.
-include(CheckCSourceRuns)
-
 ###
 # Undocumented.
 # Based on AC_HEADER_SYS_WAIT

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to