Attached an updated patch, apart from some formatting edits, there are some small functional changes.
- Getting the directory looks like it was allocating memory with strdup and never freeing it, as well as writing past the allocated bounds, now use a static string.
- CMake option is only available with unix (not apple)