Skip to content

Commit

Permalink
Build: Fix rpath in iOS shared libraries
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dcommander committed Mar 24, 2018
1 parent d3a1f89 commit c80ddef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -567,6 +567,9 @@ if(WITH_TURBOJPEG)
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
Expand Down
3 changes: 3 additions & 0 deletions sharedlib/CMakeLists.txt
Expand Up @@ -41,6 +41,9 @@ add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} $<TARGET_OBJECTS:simd>
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)
Expand Down

0 comments on commit c80ddef

Please sign in to comment.