diff --git a/CMakeLists.txt b/CMakeLists.txt index 60544139..6a6ba6f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,7 +109,7 @@ endif() # FIND SQLITE3 if (ENABLE_SQLITE3) - if (NOT CMAKE_COMPILER_IS_GNUCXX) + if (MSVC) ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/msvc-deps) else() if (WIN32) @@ -248,6 +248,16 @@ if(ENABLE_TESTS) endif() endif() +if (APPLE) + FIND_LIBRARY(IOKIT_FRAMEWORK IOKit) + FIND_LIBRARY(SECURITY_FRAMEWORK Security) + FIND_LIBRARY(APPKIT_FRAMEWORK AppKit) + FIND_LIBRARY(SYSTEMCONFIGURATION_FRAMEWORK SystemConfiguration) + FIND_LIBRARY(SECURITYINTERFACE_FRAMEWORK SecurityInterface) + MARK_AS_ADVANCED(IOKIT_FRAMEWORK APPKIT_FRAMEWORK SYSTEMCONFIGURATION_FRAMEWORK SECURITY_FRAMEWORK SECURITYINTERFACE_FRAMEWORK) + SET (APPLE_FRAMEWORKS ${IOKIT_FRAMEWORK} ${APPKIT_FRAMEWORK} ${SYSTEMCONFIGURATION_FRAMEWORK} ${SECURITY_FRAMEWORK} ${SECURITYINTERFACE_FRAMEWORK}) +endif() + message(" Supported features") message("-----------------------") diff --git a/backends/swiften/main.cpp b/backends/swiften/main.cpp index 93137352..db6ea37b 100644 --- a/backends/swiften/main.cpp +++ b/backends/swiften/main.cpp @@ -17,9 +17,11 @@ #endif #ifndef __FreeBSD__ +#ifndef __MACH__ // malloc_trim #include "malloc.h" #endif +#endif // Boost #include @@ -189,9 +191,11 @@ class SwiftenPlugin : public NetworkPlugin { #ifndef WIN32 #ifndef __FreeBSD__ +#ifndef __MACH__ // force returning of memory chunks allocated by libxml2 to kernel malloc_trim(0); #endif +#endif #endif } diff --git a/spectrum/src/main.cpp b/spectrum/src/main.cpp index 176c618d..ed5d9b51 100644 --- a/spectrum/src/main.cpp +++ b/spectrum/src/main.cpp @@ -28,8 +28,10 @@ #include #include "libgen.h" #ifndef __FreeBSD__ +#ifndef __MACH__ #include #endif +#endif #else #include #define getpid _getpid @@ -308,10 +310,12 @@ int main(int argc, char **argv) setlocale(LC_ALL, ""); #ifndef WIN32 #ifndef __FreeBSD__ +#ifndef __MACH__ mallopt(M_CHECK_ACTION, 2); mallopt(M_PERTURB, 0xb); #endif #endif +#endif #ifndef WIN32 if (signal(SIGINT, spectrum_sigint_handler) == SIG_ERR) { diff --git a/spectrum_manager/src/CMakeLists.txt b/spectrum_manager/src/CMakeLists.txt index a9a9ffc6..53b4e41e 100644 --- a/spectrum_manager/src/CMakeLists.txt +++ b/spectrum_manager/src/CMakeLists.txt @@ -7,7 +7,10 @@ ADD_DEPENDENCIES(spectrum2_manager pb) SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include/transport/protocol.pb.cc PROPERTIES GENERATED 1) target_link_libraries(spectrum2_manager ${SWIFTEN_LIBRARY} ${PROTOBUF_LIBRARIES}) - + +if(APPLE) +target_link_libraries(spectrum2_manager ${APPLE_FRAMEWORKS}) +endif() INSTALL(TARGETS spectrum2_manager RUNTIME DESTINATION bin) INSTALL(FILES diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9053aa4d..3e49efa8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,7 @@ FILE(GLOB SRC *.cpp *.h) FILE(GLOB_RECURSE SWIFTEN_SRC ../include/Swiften/*.cpp) # Build without openssl on msvc -if (CMAKE_COMPILER_IS_GNUCXX) +if (NOT MSVC) string(REGEX REPLACE "[^;]+;?/Schannel/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") else() string(REGEX REPLACE "[^;]+;?/OpenSSL/[^;]+;?" "" SWIFTEN_SRC "${SWIFTEN_SRC}") @@ -55,6 +55,9 @@ endif() SET_TARGET_PROPERTIES(transport PROPERTIES VERSION ${TRANSPORT_VERSION} SOVERSION ${TRANSPORT_VERSION} ) +if (APPLE) + TARGET_LINK_LIBRARIES(transport ${APPLE_FRAMEWORKS}) +endif() INSTALL(TARGETS transport LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries) diff --git a/src/memoryusage.cpp b/src/memoryusage.cpp index d620569b..31ef5f8c 100644 --- a/src/memoryusage.cpp +++ b/src/memoryusage.cpp @@ -29,19 +29,37 @@ #ifndef WIN32 #include #endif -#ifdef BSD +#ifdef __MACH__ +#include +#elif BSD #include #include #include #include #include - #endif namespace Transport { #ifndef WIN32 -#ifdef BSD +#ifdef __MACH__ + +void process_mem_usage(double& vm_usage, double& resident_set, pid_t pid) { + + struct task_basic_info t_info; + mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT; + + if (KERN_SUCCESS != task_info(mach_task_self(), + TASK_BASIC_INFO, (task_info_t)&t_info, + &t_info_count)) { + vm_usage = 0; + resident_set = 0; + return; + } + vm_usage = t_info.virtual_size; + resident_set = t_info.resident_size; +} +#elif BSD void process_mem_usage(double& vm_usage, double& resident_set, pid_t pid) { int mib[4]; size_t size; diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 23ffa53d..4a36eebf 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -33,9 +33,11 @@ #include "Swiften/Elements/StreamError.h" #include "Swiften/Elements/MUCPayload.h" #include "Swiften/Elements/ChatState.h" -#ifndef __FreeBSD__ +#ifndef __FreeBSD__ +#ifndef __MACH__ #include "malloc.h" #endif +#endif // #include "valgrind/memcheck.h" namespace Transport { @@ -130,9 +132,11 @@ void UserManager::removeUser(User *user, bool onUserBehalf) { delete user; #ifndef WIN32 #ifndef __FreeBSD__ +#ifndef __MACH__ malloc_trim(0); #endif #endif +#endif // VALGRIND_DO_LEAK_CHECK; }