diff --git a/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp b/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp index 9367cf1fd..4ebeec1f3 100644 --- a/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp +++ b/externals/coda-oss/modules/c++/sys/source/OSUnix.cpp @@ -30,6 +30,17 @@ #include #include +#if defined(__APPLE__) + +#include +#include +#include +#include +#include +#include + +#endif + #include "sys/OSUnix.h" #include "sys/File.h" @@ -275,12 +286,47 @@ size_t sysconfCaller(int name) void sys::OSUnix::getMemInfo(size_t &totalPhysMem, size_t &freePhysMem) const { + // Unfortunately sysctl is the best way to do this on OSX, + // but sysctl is deprecated in favor of sysconf on linux +#if defined(__APPLE__) + long long physMem = 0; + size_t size = sizeof(physMem); + int status = sysctlbyname("hw.memsize", &physMem, &size, 0, 0); + if(status) + { + throw sys::SystemException(Ctxt("Call to sysctl() has failed")); + } + + mach_port_t machPort = mach_host_self(); + mach_msg_type_number_t count = HOST_VM_INFO_COUNT; + vm_size_t pageSize = 0; + vm_statistics_data_t vmstat; + + if(KERN_SUCCESS != host_statistics(machPort, HOST_VM_INFO, + (host_info_t) &vmstat, &count)) + { + throw sys::SystemException(Ctxt("Call to host_statistics() has failed")); + } + + if(KERN_SUCCESS != host_page_size(machPort, &pageSize)) + { + throw sys::SystemException(Ctxt("Call to host_page_size has failed")); + } + + long long freeBytes = vmstat.free_count * pageSize; + + totalPhysMem = physMem / 1024 / 1024; + freePhysMem = freeBytes / 1024 / 1024; + +#else long long pageSize = sysconfCaller(_SC_PAGESIZE); long long totalNumPages = sysconfCaller(_SC_PHYS_PAGES); long long availNumPages = sysconfCaller(_SC_AVPHYS_PAGES); totalPhysMem = (pageSize*totalNumPages/1024)/1024; freePhysMem = (pageSize*availNumPages/1024)/1024; + +#endif } void sys::DirectoryUnix::close() diff --git a/externals/coda-oss/modules/c++/sys/tests/OSTest.cpp b/externals/coda-oss/modules/c++/sys/tests/OSTest.cpp index 753c7dd2b..70708e807 100644 --- a/externals/coda-oss/modules/c++/sys/tests/OSTest.cpp +++ b/externals/coda-oss/modules/c++/sys/tests/OSTest.cpp @@ -47,6 +47,13 @@ int main(int argc, char **argv) std::cout << "The delimiter on this platform: " << os.getDelimiter() << std::endl; std::cout << "The process id: " << os.getProcessId() << std::endl; + + size_t freeMemory = 0; + size_t physMemory = 0; + os.getMemInfo(physMemory, freeMemory); + std::cout << "Total physical memory (MB): " << physMemory << std::endl; + std::cout << "Total free memory (MB): " << freeMemory << std::endl; + //std::cout << "The user is: " << os.getUsername() << std::endl; ///////////////////////////////////////////// // File exists check!!! diff --git a/projects/csm/wscript b/projects/csm/wscript index 1ccea34e9..473686d4d 100644 --- a/projects/csm/wscript +++ b/projects/csm/wscript @@ -5,6 +5,7 @@ PLUGIN = 'CSM' REMOVEPLUGINPREFIX = True import sys, os, re +from waflib import Errors DIRS = 'external' @@ -22,6 +23,7 @@ def configure(conf): linuxRegex = r'.*-.*-linux-.*|i686-pc-.*|linux' solarisRegex = r'sparc-sun.*|i.86-pc-solaris.*|sunos' winRegex = r'win32' + osxRegex = r'darwin' if re.match(linuxRegex, sys.platform): platformName = 'linux' elif re.match(solarisRegex, sys.platform): @@ -37,6 +39,8 @@ def configure(conf): # For example, if you're building with VS 2008 Express, use: # --enable-32bit "--msvc_version=msvc 9.0Exp" platformName = 'winVC' + str(conf.env['MSVC_VERSION']).replace('.', '') + elif re.match(osxRegex,sys.platform): + platformName='darwin' else: raise Errors.WafError('Unsupported platform %s' % sys.platform)