summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKWSys Upstream <kwrobot@kitware.com>2017-04-12 09:08:58 -0400
committerBrad King <brad.king@kitware.com>2017-04-12 09:10:22 -0400
commit85841e8bd5e678f69271272db7f838f873347812 (patch)
treeeb74d111e23c0b680a97ddb0a24d475983826100
parente9c5505bf9c51c34dea703b86a293ff04475db54 (diff)
downloadcmake-85841e8bd5e678f69271272db7f838f873347812.tar.gz
KWSys 2017-04-12 (23a4c211)
Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit 23a4c211e90c1cfd399c3632141dbd549a5db8cf (master). Upstream Shortlog ----------------- Brad King (2): 41a9dfef SystemInformation: Fix dynamic loader failure on WinXP SP2 3ead6158 SystemTools: Fix stat() wrapper compilation with Borland Daniel Pfeifer (1): ce5b0d34 Disable include-what-you-use Mathieu Westphal (1): a2bf6bb3 SystemTools: Add cross-platform stat() wrapper
-rw-r--r--CMakeLists.txt6
-rw-r--r--SystemInformation.cxx23
-rw-r--r--SystemTools.cxx33
-rw-r--r--SystemTools.hxx.in24
-rw-r--r--testSystemTools.cxx13
5 files changed, 95 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index de68118f1a..28fe9e7ae0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -796,6 +796,8 @@ ENDFOREACH()
IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
ADD_LIBRARY(${KWSYS_NAMESPACE} ${KWSYS_LIBRARY_TYPE}
${KWSYS_C_SRCS} ${KWSYS_CXX_SRCS})
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY C_INCLUDE_WHAT_YOU_USE "")
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE "")
SET_PROPERTY(TARGET ${KWSYS_NAMESPACE} PROPERTY LABELS ${KWSYS_LABELS_LIB})
IF(KWSYS_USE_DynamicLoader)
IF(UNIX)
@@ -940,6 +942,8 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
ENDIF()
IF(KWSYS_USE_ConsoleBuf)
ADD_EXECUTABLE(testConsoleBufChild testConsoleBufChild.cxx)
+ SET_PROPERTY(TARGET testConsoleBufChild PROPERTY C_INCLUDE_WHAT_YOU_USE "")
+ SET_PROPERTY(TARGET testConsoleBufChild PROPERTY CXX_INCLUDE_WHAT_YOU_USE "")
SET_PROPERTY(TARGET testConsoleBufChild PROPERTY LABELS ${KWSYS_LABELS_EXE})
TARGET_LINK_LIBRARIES(testConsoleBufChild ${KWSYS_NAMESPACE})
SET(KWSYS_CXX_TESTS ${KWSYS_CXX_TESTS}
@@ -967,6 +971,8 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
${KWSYS_CXX_TESTS}
)
ADD_EXECUTABLE(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_CXX_TEST_SRCS})
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY C_INCLUDE_WHAT_YOU_USE "")
+ SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY CXX_INCLUDE_WHAT_YOU_USE "")
SET_PROPERTY(TARGET ${KWSYS_NAMESPACE}TestsCxx PROPERTY LABELS ${KWSYS_LABELS_EXE})
TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE}TestsCxx ${KWSYS_NAMESPACE})
diff --git a/SystemInformation.cxx b/SystemInformation.cxx
index 93312e9dd4..70f1a434ed 100644
--- a/SystemInformation.cxx
+++ b/SystemInformation.cxx
@@ -4341,18 +4341,35 @@ unsigned char SystemInformationImplementation::GetAPICId()
void SystemInformationImplementation::CPUCountWindows()
{
#if defined(_WIN32)
- std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> ProcInfo;
this->NumberOfPhysicalCPU = 0;
this->NumberOfLogicalCPU = 0;
+ typedef BOOL(WINAPI * GetLogicalProcessorInformationType)(
+ PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
+ static GetLogicalProcessorInformationType pGetLogicalProcessorInformation =
+ (GetLogicalProcessorInformationType)GetProcAddress(
+ GetModuleHandleW(L"kernel32"), "GetLogicalProcessorInformation");
+
+ if (!pGetLogicalProcessorInformation) {
+ // Fallback to approximate implementation on ancient Windows versions.
+ SYSTEM_INFO info;
+ ZeroMemory(&info, sizeof(info));
+ GetSystemInfo(&info);
+ this->NumberOfPhysicalCPU =
+ static_cast<unsigned int>(info.dwNumberOfProcessors);
+ this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
+ return;
+ }
+
+ std::vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> ProcInfo;
{
DWORD Length = 0;
- DWORD rc = GetLogicalProcessorInformation(NULL, &Length);
+ DWORD rc = pGetLogicalProcessorInformation(NULL, &Length);
assert(FALSE == rc);
(void)rc; // Silence unused variable warning in Borland C++ 5.81
assert(GetLastError() == ERROR_INSUFFICIENT_BUFFER);
ProcInfo.resize(Length / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));
- rc = GetLogicalProcessorInformation(&ProcInfo[0], &Length);
+ rc = pGetLogicalProcessorInformation(&ProcInfo[0], &Length);
assert(rc != FALSE);
(void)rc; // Silence unused variable warning in Borland C++ 5.81
}
diff --git a/SystemTools.cxx b/SystemTools.cxx
index 65b7b26b5b..100a49ce89 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -54,7 +54,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/stat.h>
#include <time.h>
#if defined(_WIN32) && !defined(_MSC_VER) && defined(__GNUC__)
@@ -1258,6 +1257,38 @@ bool SystemTools::TestFileAccess(const std::string& filename,
}
//----------------------------------------------------------------------------
+int SystemTools::Stat(const char* path, SystemTools::Stat_t* buf)
+{
+ if (!path) {
+ errno = EFAULT;
+ return -1;
+ }
+ return SystemTools::Stat(std::string(path), buf);
+}
+
+//----------------------------------------------------------------------------
+int SystemTools::Stat(const std::string& path, SystemTools::Stat_t* buf)
+{
+ if (path.empty()) {
+ errno = ENOENT;
+ return -1;
+ }
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ // Ideally we should use ConvertToWindowsExtendedPath to support
+ // long paths, but _wstat64 rejects paths with '?' in them, thinking
+ // they are wildcards.
+ std::wstring const& wpath = Encoding::ToWide(path);
+#if defined(__BORLANDC__)
+ return _wstati64(wpath.c_str(), buf);
+#else
+ return _wstat64(wpath.c_str(), buf);
+#endif
+#else
+ return stat(path.c_str(), buf);
+#endif
+}
+
+//----------------------------------------------------------------------------
#ifdef __CYGWIN__
bool SystemTools::PathCygwinToWin32(const char* path, char* win32_path)
{
diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in
index 7a5256b236..53abce7a0d 100644
--- a/SystemTools.hxx.in
+++ b/SystemTools.hxx.in
@@ -13,6 +13,9 @@
#include <@KWSYS_NAMESPACE@/String.hxx>
#include <sys/types.h>
+// include sys/stat.h after sys/types.h
+#include <sys/stat.h>
+
#if !defined(_WIN32) || defined(__CYGWIN__)
#include <unistd.h> // For access permissions for use with access()
#endif
@@ -324,6 +327,27 @@ public:
TestFilePermissions permissions);
static bool TestFileAccess(const std::string& filename,
TestFilePermissions permissions);
+/**
+ * Cross platform wrapper for stat struct
+ */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#if defined(__BORLANDC__)
+ typedef struct stati64 Stat_t;
+#else
+ typedef struct _stat64 Stat_t;
+#endif
+#else
+ typedef struct stat Stat_t;
+#endif
+
+ /**
+ * Cross platform wrapper for stat system call
+ *
+ * On Windows this may not work for paths longer than 250 characters
+ * due to limitations of the underlying '_wstat64' call.
+ */
+ static int Stat(const char* path, Stat_t* buf);
+ static int Stat(const std::string& path, Stat_t* buf);
/**
* Converts Cygwin path to Win32 path. Uses dictionary container for
diff --git a/testSystemTools.cxx b/testSystemTools.cxx
index 8e1ea258a8..9b08a04a03 100644
--- a/testSystemTools.cxx
+++ b/testSystemTools.cxx
@@ -135,6 +135,19 @@ static bool CheckFileOperations()
res = false;
}
+ kwsys::SystemTools::Stat_t buf;
+ if (kwsys::SystemTools::Stat(testTxtFile.c_str(), &buf) != 0) {
+ std::cerr << "Problem with Stat - unable to stat text file: "
+ << testTxtFile << std::endl;
+ res = false;
+ }
+
+ if (kwsys::SystemTools::Stat(testBinFile, &buf) != 0) {
+ std::cerr << "Problem with Stat - unable to stat bin file: " << testBinFile
+ << std::endl;
+ res = false;
+ }
+
if (!kwsys::SystemTools::MakeDirectory(testNewDir)) {
std::cerr << "Problem with MakeDirectory for: " << testNewDir << std::endl;
res = false;