{"action":"created","issue":{"url":"https://api.github.com/repos/simbody/simbody/issues/524","repository_url":"https://api.github.com/repos/simbody/simbody","labels_url":"https://api.github.com/repos/simbody/simbody/issues/524/labels{/name}","comments_url":"https://api.github.com/repos/simbody/simbody/issues/524/comments","events_url":"https://api.github.com/repos/simbody/simbody/issues/524/events","html_url":"https://github.com/simbody/simbody/pull/524","id":178463380,"number":524,"title":"Only define clock_gettime() for macOS < 10.12","user":{"login":"chrisdembia","id":846001,"avatar_url":"https://avatars.githubusercontent.com/u/846001?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisdembia","html_url":"https://github.com/chrisdembia","followers_url":"https://api.github.com/users/chrisdembia/followers","following_url":"https://api.github.com/users/chrisdembia/following{/other_user}","gists_url":"https://api.github.com/users/chrisdembia/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisdembia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisdembia/subscriptions","organizations_url":"https://api.github.com/users/chrisdembia/orgs","repos_url":"https://api.github.com/users/chrisdembia/repos","events_url":"https://api.github.com/users/chrisdembia/events{/privacy}","received_events_url":"https://api.github.com/users/chrisdembia/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-21T21:11:07Z","updated_at":"2016-09-22T15:25:39Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/simbody/simbody/pulls/524","html_url":"https://github.com/simbody/simbody/pull/524","diff_url":"https://github.com/simbody/simbody/pull/524.diff","patch_url":"https://github.com/simbody/simbody/pull/524.patch"},"body":"This PR fixes #523: OSX previously did not provide `clock_gettime()`, but macOS 10.12 now does provide this function. This PR causes Simbody's version of `clock_gettime()` to only appear if using an older version of OSX.\r\n\r\n### Background on OSX SDKs, etc.\r\n\r\nThere are two versions to consider here: the MacOSX SDK version used when compiling the source code, and the version of the OS on a user's computer (called the DEPLOYMENT_TARGET). Both the SDK and the OS version use the same numbering scheme (e.g., 10.10, 10.11, 10.12). A single SDK can be used to deploy to multiple different versions. For example, one can build Simbody with the 10.12 SDK and deploy those binaries to OSX 10.10, 10.11 (as well as 10.12). \r\n\r\nWhen a developer builds Simbody with CMake, they can specify:\r\n\r\n1. **CMAKE_OSX_SYSROOT**: the SDK to use.\r\n2. **CMAKE_OSX_DEPLOYMENT_TARGET**: the minimum version of OSX that users must have to use the resulting Simbody binaries.\r\n\r\nThe 10.12 SDK declares and defines `clock_gettime()`, and (as one would expect) 10.12 operating system provides `clock_gettime()` in a dynamic library (libSystemB.dylib maybe?).\r\n\r\nWith respect to this PR, this results in 3 scenarios:\r\n\r\n1. **SDK version < 10.12 and DEPLOYMENT_TARGET < 10.12**: This is the old scenario. Simbody must provide `clock_gettime()`.\r\n2. **SDK version >= 10.12 and DEPLOYMENT_TARGET >= 10.12**: This is the scenario that will be common for most users/developers pretty soon (in say a year?). And it is simple: Simbody should not declare or define `clock_gettime()`.\r\n3. **SDK version >= 10.12 and DEPLOYMENT_TARGET < 10.12**: This is the nasty scenario, and it's the one I was in yesterday. Basically, the SDK declares `clock_gettime()`, but it may not be on the user's system. This occurs when developers update their Xcode to Xcode 8. Updating to Xcode 8 removes the previous SDKs (e.g., MacOSX10.11.sdk) and only leaves MacOSX10.12.sdk on the developer's machine. However, a developer with Xcode 8 on their machine is likely still interested in providing Simbody to users with OSX 10.11, etc. It is true that developers like me can go find MacOSX10.11.sdk online and download it again, but this is undesirable and we shouldn't force developers with Xcode 8 to fetch older SDKs.\r\n\r\n(The scenario SDK version < 10.12 and DEPLOYMENT_TARGET >= 10.12 doesn't make sense. SDKs cannot target future versions of OSX)\r\n\r\n### Changes in this PR\r\n\r\nThis PR introduces two macros that control how Simbody builds:\r\n\r\n1. (DECLARE) **SimTK_IS_APPLE_AND_MUST_DECLARE_CLOCK_GETTIME**: This is true if the SDK version is older than 10.12, as such SDKs do not declare clock_gettime(). The 10.12 SDK declares `clock_gettime()`, so we don't need to declare it again. In fact, we can't declare it again because  `clockid_t` is different in Simbody's implementation as compared to Apple's implementation: Simbody uses `typedef long clockid_t`, while Apple uses an enum.\r\n2. (DEFINE) **SimTK_IS_APPLE_AND_MUST_DEFINE_CLOCK_GETTIME**: This is true if the DEPLOYMENT_TARGET is older than 10.12: if we want to allow users with OSX 10.10 or 10.11 to use Simbody, we must define `clock_gettime()`.\r\n\r\nI use `*_DECLARE_*` to decide if we should declare `clock_gettime()` in Timing.h and I use `*_DEFINE_*` to decide if we should define clock_gettime (and related functions) in Timing.cpp.\r\n\r\n### Testing\r\n\r\nI tested scenarios (2) and (3) above locally. On a computer with OSX 10.11, I upgraded to Xcode 8 and used the MacOSX10.12.sdk, and was able to run the tests successfully. Then I upgraded my computer to macOS 10.12 and was again able to run the tests successfully. Travis tests scenario (1), since travis is using an older OSX with an older Xcode.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/simbody/simbody/issues/comments/248936880","html_url":"https://github.com/simbody/simbody/pull/524#issuecomment-248936880","issue_url":"https://api.github.com/repos/simbody/simbody/issues/524","id":248936880,"user":{"login":"sherm1","id":4088016,"avatar_url":"https://avatars.githubusercontent.com/u/4088016?v=3","gravatar_id":"","url":"https://api.github.com/users/sherm1","html_url":"https://github.com/sherm1","followers_url":"https://api.github.com/users/sherm1/followers","following_url":"https://api.github.com/users/sherm1/following{/other_user}","gists_url":"https://api.github.com/users/sherm1/gists{/gist_id}","starred_url":"https://api.github.com/users/sherm1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sherm1/subscriptions","organizations_url":"https://api.github.com/users/sherm1/orgs","repos_url":"https://api.github.com/users/sherm1/repos","events_url":"https://api.github.com/users/sherm1/events{/privacy}","received_events_url":"https://api.github.com/users/sherm1/received_events","type":"User","site_admin":false},"created_at":"2016-09-22T15:25:39Z","updated_at":"2016-09-22T15:25:39Z","body":"Yikes -- it took me two tries to get those two comments in! I had typed both in but only one came out when I selected \"finish review\"."}}
{"actor":{"display_login":"sherm1"}}