From 4ca97fc6ac8824a07f6cd119dca4983a1e7dfecd Mon Sep 17 00:00:00 2001
From: Chuck Atkins <chuck.atkins@kitware.com>
Date: Tue, 2 Jan 2018 11:12:40 -0500
Subject: [PATCH] SystemTools: Disable getpwnam for static linux builds

On Linux, getpwnam requires a dynamic glibc at runtime so it can't
really be used in a "fully static" build  and will cause an excessive
number of linker warnings pertaining to such.
---
 CMakeLists.txt  | 8 ++++++++
 SystemTools.cxx | 3 ++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 351e38d..bec1650 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -494,6 +494,14 @@ IF(KWSYS_USE_SystemTools)
     KWSYS_CXX_STAT_HAS_ST_MTIM=${KWSYS_CXX_STAT_HAS_ST_MTIM}
     KWSYS_CXX_STAT_HAS_ST_MTIMESPEC=${KWSYS_CXX_STAT_HAS_ST_MTIMESPEC}
     )
+
+  # Disable getpwnam for static linux builds since it depends on shared glibc
+  GET_PROPERTY(SHARED_LIBS_SUPPORTED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
+  IF(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT SHARED_LIBS_SUPPORTED)
+    SET_PROPERTY(SOURCE SystemTools.cxx APPEND PROPERTY COMPILE_DEFINITIONS
+      HAVE_GETPWNAM=0
+      )
+  ENDIF()
 ENDIF()
 
 IF(KWSYS_USE_SystemInformation)
diff --git a/SystemTools.cxx b/SystemTools.cxx
index f547362..a73f542 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -107,7 +107,8 @@ extern char** environ;
 
 // getpwnam doesn't exist on Windows and Cray Xt3/Catamount
 // same for TIOCGWINSZ
-#if defined(_WIN32) || defined(__LIBCATAMOUNT__)
+#if defined(_WIN32) || defined(__LIBCATAMOUNT__) ||                           \
+  (defined(HAVE_GETPWNAM) && HAVE_GETPWNAM == 0)
 #undef HAVE_GETPWNAM
 #undef HAVE_TTY_INFO
 #else
-- 
GitLab