diff --git a/libs/cnmatrix/include/cnmatrix/cn_matrix.h b/libs/cnmatrix/include/cnmatrix/cn_matrix.h index 3e40b214..988a5155 100644 --- a/libs/cnmatrix/include/cnmatrix/cn_matrix.h +++ b/libs/cnmatrix/include/cnmatrix/cn_matrix.h @@ -21,7 +21,10 @@ #include -#include +#include +#ifdef _WIN32 +#include // alloca on MSVC +#endif #include "cnmatrix/cn_flt.h" #include "math.h" #include "string.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c56c0538..b2e49d29 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,6 +56,11 @@ if(USE_HIDAPI) add_definitions (-DHIDAPI) IF(WIN32) SET(SURVIVE_SRCS ${SURVIVE_SRCS} ../redist/hid-windows.c) + elseif(APPLE) + find_package(PkgConfig REQUIRED) + pkg_check_modules(HIDAPI REQUIRED hidapi) + list(APPEND ADDITIONAL_LIBRARIES ${HIDAPI_LIBRARIES}) + include_directories(${HIDAPI_INCLUDE_DIRS}) else() list(APPEND ADDITIONAL_LIBRARIES udev hidapi-libusb) endif() diff --git a/src/survive_plugins.unix.h b/src/survive_plugins.unix.h index 2f09c721..41a7c906 100644 --- a/src/survive_plugins.unix.h +++ b/src/survive_plugins.unix.h @@ -9,12 +9,19 @@ #include #include #include +#ifdef __APPLE__ +#include +#endif #include "assert.h" #pragma GCC diagnostic ignored "-Wpedantic" +#ifdef __APPLE__ +static const char* plugin_ext() { return ".dylib"; } +#else static const char* plugin_ext() { return ".so"; } +#endif #ifndef PATH_MAX #define PATH_MAX 4096 @@ -37,8 +44,17 @@ static const char *get_so_filename() { static const char *get_exe_filename() { static char exe_path[PATH_MAX] = { 0 }; if (exe_path[0] == 0) { - size_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path)); - exe_path[len] = 0; +#ifdef __APPLE__ + uint32_t size = sizeof(exe_path); + if (_NSGetExecutablePath(exe_path, &size) != 0) + exe_path[0] = 0; +#else + ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1); + if (len > 0) + exe_path[len] = 0; + else + exe_path[0] = 0; +#endif } return exe_path; }