summaryrefslogtreecommitdiffstats
path: root/Source/kwsys
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-04-12 13:10:22 (GMT)
committerBrad King <brad.king@kitware.com>2017-04-12 13:10:22 (GMT)
commitada8e0cac4b50d07f4d07ecd584bf00e7afd3ac5 (patch)
treec336973c11619343de55064f40353059ad010fcf /Source/kwsys
parentfddd559406558a2037733e5b760e9dd04e9edfd1 (diff)
parent85841e8bd5e678f69271272db7f838f873347812 (diff)
downloadCMake-ada8e0cac4b50d07f4d07ecd584bf00e7afd3ac5.zip
CMake-ada8e0cac4b50d07f4d07ecd584bf00e7afd3ac5.tar.gz
CMake-ada8e0cac4b50d07f4d07ecd584bf00e7afd3ac5.tar.bz2
Merge branch 'upstream-KWSys' into update-kwsys
* upstream-KWSys: KWSys 2017-04-12 (23a4c211)
Diffstat (limited to 'Source/kwsys')
-rw-r--r--Source/kwsys/CMakeLists.txt6
-rw-r--r--Source/kwsys/SystemInformation.cxx23
-rw-r--r--Source/kwsys/SystemTools.cxx33
-rw-r--r--Source/kwsys/SystemTools.hxx.in24
-rw-r--r--Source/kwsys/testSystemTools.cxx13
5 files changed, 95 insertions, 4 deletions
diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt
index de68118..28fe9e7 100644
--- a/Source/kwsys/CMakeLists.txt
+++ b/Source/kwsys/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/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx
index 93312e9..70f1a43 100644
--- a/Source/kwsys/SystemInformation.cxx
+++ b/Source/kwsys/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/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 65b7b26..100a49c 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/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/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in
index 7a5256b..53abce7 100644
--- a/Source/kwsys/SystemTools.hxx.in
+++ b/Source/kwsys/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/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx
index 8e1ea25..9b08a04 100644
--- a/Source/kwsys/testSystemTools.cxx
+++ b/Source/kwsys/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;