Build: Fix rpath in iOS shared libraries

When attempting to configure an iOS/ARM build with Xcode 7.2 and CMake
2.8.12, I got the following errors:

CMake Error at CMakeLists.txt:560 (add_library):
  Attempting to use MACOSX_RPATH without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG
  being set.  This could be because you are using a Mac OS X version less
  than 10.5 or because CMake's platform configuration is corrupt.
(x 3)

CMake Error at sharedlib/CMakeLists.txt:38 (add_library):
  Attempting to use MACOSX_RPATH without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG
  being set.  This could be because you are using a Mac OS X version less
  than 10.5 or because CMake's platform configuration is corrupt.
(x 3)

Upgrading to CMake 3.x (tried 3.0 and 3.1) got rid of the errors, but
the resulting shared libs still did not use @rpath as expected.  Note
also that CMake 3.x (at least the two versions I tested) does not
automatically set the MACOSX_RPATH property as claimed.  I could find
nothing in the release notes for later CMake releases to indicate that
either problem has been fixed.  What I did find was this little nugget
of code in the Darwin platform module:

https://github.com/Kitware/CMake/blob/f6b93fbf3ae00a9157af2f6497bed074d585cea9/Modules/Platform/Darwin.cmake#L33-L36

This sets CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG="-Wl,-rpath," only if you
are running OS X 10.5 or later.  It makes no such check for iOS, perhaps
because shared libraries aren't much of a thing with iOS apps.  In any
event, this commit simply sets CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG if it
isn't set already, and that fixes all of the aforementioned problems.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5dfd5d7..cc548f5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -567,6 +567,9 @@
       set_target_properties(turbojpeg PROPERTIES LINK_FLAGS -Wl,--kill-at)
     endif()
     if(APPLE)
+      if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
+        set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
+      endif()
       set_target_properties(turbojpeg PROPERTIES MACOSX_RPATH 1)
     endif()
     set_target_properties(turbojpeg PROPERTIES
diff --git a/sharedlib/CMakeLists.txt b/sharedlib/CMakeLists.txt
index 95aed25..2d60170 100755
--- a/sharedlib/CMakeLists.txt
+++ b/sharedlib/CMakeLists.txt
@@ -41,6 +41,9 @@
 set_target_properties(jpeg PROPERTIES SOVERSION ${SO_MAJOR_VERSION}
   VERSION ${SO_MAJOR_VERSION}.${SO_AGE}.${SO_MINOR_VERSION})
 if(APPLE)
+  if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
+    set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
+  endif()
   set_target_properties(jpeg PROPERTIES MACOSX_RPATH 1)
 endif()
 if(MAPFLAG)