Revision: 69957
          http://sourceforge.net/p/brlcad/code/69957
Author:   starseeker
Date:     2017-07-16 20:25:59 +0000 (Sun, 16 Jul 2017)
Log Message:
-----------
Simplify config timestamp writing

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

Removed Paths:
-------------
    brlcad/trunk/misc/CMake/test_srcs/time.c.in

Modified: brlcad/trunk/CMakeLists.txt
===================================================================
--- brlcad/trunk/CMakeLists.txt 2017-07-16 03:58:26 UTC (rev 69956)
+++ brlcad/trunk/CMakeLists.txt 2017-07-16 20:25:59 UTC (rev 69957)
@@ -2742,9 +2742,7 @@
 set(BRLCAD_COMPILE_COUNT ${buildCounter})
 
 # DATE - RFC2822 timestamp
-file(READ ${CONFIG_TIMESTAMP_FILE} DATESTAMP)
-string(STRIP ${DATESTAMP} DATESTAMP)
-set(BRLCAD_COMPILE_DATE \"${DATESTAMP}\")
+set(BRLCAD_COMPILE_DATE \"${CONFIG_DATESTAMP}\")
 
 # HOST
 set(BRLCAD_HOSTNAME_FILE "${BRLCAD_BINARY_DIR}/CMakeTmp/BRLCAD_BUILD_HOST")

Modified: brlcad/trunk/misc/CMake/BRLCAD_Util.cmake
===================================================================
--- brlcad/trunk/misc/CMake/BRLCAD_Util.cmake   2017-07-16 03:58:26 UTC (rev 
69956)
+++ brlcad/trunk/misc/CMake/BRLCAD_Util.cmake   2017-07-16 20:25:59 UTC (rev 
69957)
@@ -307,38 +307,76 @@
 
 #---------------------------------------------------------------------------
 # Set variables reporting time of configuration.  Sets CONFIG_DATE and
-# CONFIG_TIMESTAMP_FILE in parent scope. (TODO - is the latter necessary?)
+# CONFIG_DATESTAMP in parent scope.
 #
 # Unfortunately, CMake doesn't give you variables with current day,
 # month, etc.  There are several possible approaches to this, but most
 # (e.g. the date command) are not cross platform. We build a small C
-# file which writes out the needed values to files in the build
-# directory. Those files are then read and stripped by CMake.
+# program which supplies the needed info.
 function(set_config_time)
-  set(CONFIG_TIME_DAY_FILE "${BRLCAD_BINARY_DIR}/include/conf/CONFIG_TIME_DAY")
-  set(CONFIG_TIME_MONTH_FILE 
"${BRLCAD_BINARY_DIR}/include/conf/CONFIG_TIME_MONTH")
-  set(CONFIG_TIME_YEAR_FILE 
"${BRLCAD_BINARY_DIR}/include/conf/CONFIG_TIME_YEAR")
-  set(CONFIG_TIMESTAMP_FILE 
"${BRLCAD_BINARY_DIR}/include/conf/CONFIG_TIMESTAMP" PARENT_SCOPE)
-  DISTCLEAN(${CONFIG_TIME_DAY_FILE} ${CONFIG_TIME_MONTH_FILE}
-    ${CONFIG_TIME_YEAR_FILE} ${CONFIG_TIMESTAMP_FILE})
-  file(MAKE_DIRECTORY "${BRLCAD_BINARY_DIR}/include")
-  file(MAKE_DIRECTORY "${BRLCAD_BINARY_DIR}/include/conf")
-  configure_file("${BRLCAD_CMAKE_DIR}/test_srcs/time.c.in" 
"${CMAKE_BINARY_DIR}/CMakeTmp/time.c")
-  try_run(TIME_RESULT TIME_COMPILED
-    "${CMAKE_BINARY_DIR}/CMakeTmp"
-    "${CMAKE_BINARY_DIR}/CMakeTmp/time.c"
-    OUTPUT_VARIABLE COMPILEMESSAGES)
-  if(TIME_RESULT MATCHES "^0$")
-    file(READ ${CONFIG_TIME_DAY_FILE} CONFIG_DAY)
-    string(STRIP ${CONFIG_DAY} CONFIG_DAY)
-    file(READ ${CONFIG_TIME_MONTH_FILE} CONFIG_MONTH)
-    string(STRIP ${CONFIG_MONTH} CONFIG_MONTH)
-    file(READ ${CONFIG_TIME_YEAR_FILE} CONFIG_YEAR)
-    string(STRIP ${CONFIG_YEAR} CONFIG_YEAR)
-    set(CONFIG_DATE "${CONFIG_YEAR}${CONFIG_MONTH}${CONFIG_DAY}" PARENT_SCOPE)
-  else(TIME_RESULT MATCHES "^0$")
-    message(FATAL_ERROR "Code to determine current date and time failed!\n")
-  endif(TIME_RESULT MATCHES "^0$")
+
+  # We don't want any parent C flags here - hopefully, the below code will
+  # "just work" in any environment we are about.  The gnu89 standard doesn't
+  # like the %z print specifier, but unless/until we hit a compiler that really
+  # can't deal with it don't worry about it.
+  set(CMAKE_C_FLAGS "")
+
+  set(rfc2822_src "
+/* RFC2822 timestamp and individual day, month and year files */
+
+#include <time.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc, const char **argv) {
+   time_t t = time(NULL);
+   struct tm *currenttime = localtime(&t);
+   if (argc <= 1) {
+      char rfc2822[200];
+      strftime(rfc2822, sizeof(rfc2822), \"%a, %d %b %Y %H:%M:%S %z\", 
currenttime);
+      printf(\"%s\", rfc2822);
+      return 0;
+   }
+   if (strncmp(argv[1], \"day\", 4) == 0) {
+      printf(\"%02d\", currenttime->tm_mday);
+   }
+   if (strncmp(argv[1], \"month\", 5) == 0) {
+      printf(\"%02d\", currenttime->tm_mon + 1);
+   }
+   if (strncmp(argv[1], \"year\", 4) == 0) {
+      printf(\"%d\", currenttime->tm_year + 1900);
+   }
+   return 0;
+}")
+
+  # Build the code so we can run it
+  file(WRITE "${CMAKE_BINARY_DIR}/CMakeTmp/rfc2822.c" "${rfc2822_src}")
+  try_compile(rfc2822_build "${CMAKE_BINARY_DIR}/CMakeTmp"
+    SOURCES "${CMAKE_BINARY_DIR}/CMakeTmp/rfc2822.c"
+    OUTPUT_VARIABLE RFC2822_BUILD_INFO
+    COPY_FILE "${CMAKE_BINARY_DIR}/CMakeTmp/rfc2822")
+  if(NOT rfc2822_build)
+    message(FATAL_ERROR "Could not build rfc2822 timestamp pretty-printing 
utility: ${RFC2822_BUILD_INFO}")
+  endif(NOT rfc2822_build)
+  file(REMOVE "${CMAKE_BINARY_DIR}/CMakeTmp/rfc2822.c")
+
+  # Build up and set CONFIG_DATE
+  execute_process(COMMAND "${CMAKE_BINARY_DIR}/CMakeTmp/rfc2822" day 
OUTPUT_VARIABLE CONFIG_DAY)
+  string(STRIP ${CONFIG_DAY} CONFIG_DAY)
+  execute_process(COMMAND "${CMAKE_BINARY_DIR}/CMakeTmp/rfc2822" month 
OUTPUT_VARIABLE CONFIG_MONTH)
+  string(STRIP ${CONFIG_MONTH} CONFIG_MONTH)
+  execute_process(COMMAND "${CMAKE_BINARY_DIR}/CMakeTmp/rfc2822" year 
OUTPUT_VARIABLE CONFIG_YEAR)
+  string(STRIP ${CONFIG_YEAR} CONFIG_YEAR)
+  set(CONFIG_DATE "${CONFIG_YEAR}${CONFIG_MONTH}${CONFIG_DAY}" PARENT_SCOPE)
+
+  # Set DATESTAMP
+  execute_process(COMMAND "${CMAKE_BINARY_DIR}/CMakeTmp/rfc2822" 
OUTPUT_VARIABLE RFC2822_STRING)
+  string(STRIP ${RFC2822_STRING} RFC2822_STRING)
+  set(CONFIG_DATESTAMP "${RFC2822_STRING}" PARENT_SCOPE)
+
+  # Cleanup
+  file(REMOVE "${CMAKE_BINARY_DIR}/CMakeTmp/rfc2822")
+
 endfunction(set_config_time)
 
 # Local Variables:

Deleted: brlcad/trunk/misc/CMake/test_srcs/time.c.in
===================================================================
--- brlcad/trunk/misc/CMake/test_srcs/time.c.in 2017-07-16 03:58:26 UTC (rev 
69956)
+++ brlcad/trunk/misc/CMake/test_srcs/time.c.in 2017-07-16 20:25:59 UTC (rev 
69957)
@@ -1,33 +0,0 @@
-/* RFC2822 timestamp and individual day, month and year files */
-
-#include <time.h>
-#include <stdio.h>
-#include <string.h>
-
-int main(void) {
-  char rfc2822[200];
-  FILE *outfpts = NULL;
-  FILE *outfpday = NULL;
-  FILE *outfpmonth = NULL;
-  FILE *outfpyear = NULL;
-  time_t t;
-  struct tm *currenttime;
-  t = time(NULL);
-  currenttime = localtime(&t);
-  strftime(rfc2822, sizeof(rfc2822), "%a, %d %b %Y %H:%M:%S %z", currenttime);
-  outfpts = fopen("${CONFIG_TIMESTAMP_FILE}", "w");
-  outfpday = fopen("${CONFIG_TIME_DAY_FILE}", "w");
-  outfpmonth = fopen("${CONFIG_TIME_MONTH_FILE}", "w");
-  outfpyear = fopen("${CONFIG_TIME_YEAR_FILE}", "w");
-  fprintf(outfpts, "%s", rfc2822);
-  if (currenttime->tm_mday < 10) fprintf(outfpday, "0");
-  fprintf(outfpday, "%d", currenttime->tm_mday);
-  if (currenttime->tm_mon < 10) fprintf(outfpmonth, "0");
-  fprintf(outfpmonth, "%d", currenttime->tm_mon + 1);
-  fprintf(outfpyear, "%d", currenttime->tm_year + 1900);
-  fclose(outfpts);
-  fclose(outfpday);
-  fclose(outfpmonth);
-  fclose(outfpyear);
-  return 0;
-}

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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to