Revision: 77896
http://sourceforge.net/p/brlcad/code/77896
Author: starseeker
Date: 2020-12-03 16:41:04 +0000 (Thu, 03 Dec 2020)
Log Message:
-----------
Have cmake_host_system_information report user and hostname.
Modified Paths:
--------------
brlcad/trunk/CMakeLists.txt
Modified: brlcad/trunk/CMakeLists.txt
===================================================================
--- brlcad/trunk/CMakeLists.txt 2020-12-03 16:35:06 UTC (rev 77895)
+++ brlcad/trunk/CMakeLists.txt 2020-12-03 16:41:04 UTC (rev 77896)
@@ -1884,101 +1884,13 @@
# DATE - RFC2822 timestamp
set(BRLCAD_COMPILE_DATE \"${CONFIG_DATESTAMP}\")
-# Add definition HAVE_UNISTD_H to try_run for next couple tests, if present
-if(HAVE_UNISTD_H)
- set(UNISTD_DEF "-DHAVE_UNISTD_H")
-endif(HAVE_UNISTD_H)
-
# HOST
-if(HAVE_GETHOSTNAME)
- set(GETHOSTNAME_DEF "-DHAVE_GETHOSTNAME")
-endif(HAVE_GETHOSTNAME)
-if(HAVE_DECL_GETHOSTNAME)
- set(GETHOSTNAME_DECL_DEF "-DHAVE_DECL_GETHOSTNAME")
-endif(HAVE_DECL_GETHOSTNAME)
+cmake_host_system_information(RESULT BRLCAD_COMPILE_HOSTNAME QUERY HOSTNAME)
+string(STRIP "${BRLCAD_COMPILE_HOSTNAME}" BRLCAD_COMPILE_HOSTNAME)
-set(report_hostname_src "
-#include <stdio.h>
-#ifdef HAVE_UNISTD_H
- #include <unistd.h>
- #define GETHOSTNAME_ERROR -1
-#else
- #include <WinSock2.h>
- #define GETHOSTNAME_ERROR SOCKET_ERROR
-#endif
-
-#define MAX_HOSTNAME 2048
-
-/* strict c89 doesn't declare gethostname() */
-#if defined(HAVE_GETHOSTNAME) && !defined(HAVE_DECL_GETHOSTNAME) &&
!defined(__cplusplus) && !defined(_WINSOCKAPI_)
-extern int gethostname(char *name, size_t len);
-#endif
-
-int main(void) {
-#if defined(HAVE_GETHOSTNAME)
-{
- int ret; char hostname[MAX_HOSTNAME];
- #if !defined(HAVE_UNISTD_H)
- WORD wVersionRequested; WSADATA wsaData;
- wVersionRequested = MAKEWORD(1, 1); WSAStartup(wVersionRequested,
&wsaData);
- #endif
- ret = gethostname(hostname, MAX_HOSTNAME);
- if (ret != GETHOSTNAME_ERROR) {printf(\"%s\", hostname);} else {
printf(\"unknown\"); }
-}
-#else
- printf(\"unknown\");
-#endif
- return 0;
-}
-")
-
-file(WRITE "${CMAKE_BINARY_DIR}/CMakeTmp/report_hostname.c"
"${report_hostname_src}")
-try_run(RH_RESULT RH_COMPILED "${CMAKE_BINARY_DIR}/CMakeTmp"
- "${CMAKE_BINARY_DIR}/CMakeTmp/report_hostname.c"
- COMPILE_DEFINITIONS "${UNISTD_DEF}" "${GETHOSTNAME_DEF}"
"${GETHOSTNAME_DECL_DEF}"
- LINK_LIBRARIES "${WS2_32_LIBRARY}"
- COMPILE_OUTPUT_VARIABLE RH_COMPILE_MSGS
- RUN_OUTPUT_VARIABLE BRLCAD_COMPILE_HOSTNAME)
-if(NOT RH_COMPILED)
- message(FATAL_ERROR "Could not build hostname reporting utility:
${RH_COMPILE_MSGS}")
-endif(NOT RH_COMPILED)
-if(RH_RESULT)
- message(FATAL_ERROR "Could not run hostname reporting utility:
${BRLCAD_COMPILE_HOSTNAME}")
-endif(RH_RESULT)
-string(STRIP ${BRLCAD_COMPILE_HOSTNAME} BRLCAD_COMPILE_HOSTNAME)
-file(REMOVE "${CMAKE_BINARY_DIR}/CMakeTmp/report_hostname.c")
-
# USER
-set(report_username_src "
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_UNISTD_H
- #include <unistd.h>
-#endif
-int main(void) {
- char *name = getenv(\"USERNAME\");
- if ((name == 0) || (strlen(name) == 0)) name = getenv(\"USER\");
- if ((name == 0) || (strlen(name) == 0)) name = \"unknown\";
- printf(\"%s\", name);
- return 0;
-}
-")
-file(WRITE "${CMAKE_BINARY_DIR}/CMakeTmp/report_username.c"
"${report_username_src}")
-# Add definition HAVE_UNISTD_H to try_run
-try_run(RU_RESULT RU_COMPILED "${CMAKE_BINARY_DIR}/CMakeTmp"
- "${CMAKE_BINARY_DIR}/CMakeTmp/report_username.c"
- COMPILE_DEFINITIONS "${UNISTD_DEF}"
- COMPILE_OUTPUT_VARIABLE RU_COMPILE_MSGS
- RUN_OUTPUT_VARIABLE BRLCAD_COMPILE_USER)
-if(NOT RU_COMPILED)
- message(FATAL_ERROR "Could not build username reporting utility:
${RU_COMPILE_MSGS}")
-endif(NOT RU_COMPILED)
-if(RU_RESULT)
- message(FATAL_ERROR "Could not run username reporting utility:
${BRLCAD_COMPILE_USER}")
-endif(RU_RESULT)
-string(STRIP ${BRLCAD_COMPILE_USER} BRLCAD_COMPILE_USER)
-file(REMOVE "${CMAKE_BINARY_DIR}/CMakeTmp/report_username.c")
+set(BRLCAD_COMPILE_USER $ENV{USERNAME})
+string(STRIP "${BRLCAD_COMPILE_USER}" BRLCAD_COMPILE_USER)
if(MSVC)
# By default, do not warn when built on machines using only VS Express
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits