Hash :
c80ddef7
Author :
Date :
2018-03-23T23:17:08
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
# Anything that must be linked against the shared C library on Windows must
# be built in this subdirectory, because CMake doesn't allow us to override
# the compiler flags for each build type except at directory scope. Note
# to CMake developers: Add a COMPILE_FLAGS_<CONFIG> target property, or
# better yet, provide a friendly way of configuring a Windows target to use the
# static C library.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
if(MSVC)
# Build all configurations against shared C library
foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${var} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${var} "${${var}}")
endif()
endforeach()
endif()
foreach(src ${JPEG_SOURCES})
set(JPEG_SRCS ${JPEG_SRCS} ../${src})
endforeach()
if(WITH_SIMD AND MSVC_IDE)
# This tells CMake that the "source" files haven't been generated yet
set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)
endif()
if(WIN32)
if(WITH_MEM_SRCDST)
set(DEFFILE ../win/jpeg${SO_MAJOR_VERSION}-memsrcdst.def)
else()
set(DEFFILE ../win/jpeg${SO_MAJOR_VERSION}.def)
endif()
endif()
add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} $<TARGET_OBJECTS:simd>
${SIMD_OBJS})
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)
set_target_properties(jpeg PROPERTIES
LINK_FLAGS "${MAPFLAG}${CMAKE_CURRENT_BINARY_DIR}/../libjpeg.map")
endif()
if(MSVC)
set_target_properties(jpeg PROPERTIES SUFFIX ${SO_MAJOR_VERSION}.dll)
# The jsimd_*.c file is built using /MT, so this prevents a linker warning.
set_target_properties(jpeg PROPERTIES LINK_FLAGS "/NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBCMTD")
elseif(MINGW)
set_target_properties(jpeg PROPERTIES SUFFIX -${SO_MAJOR_VERSION}.dll)
endif()
if(WIN32)
set(USE_SETMODE "-DUSE_SETMODE")
endif()
if(WITH_12BIT)
set(COMPILE_FLAGS "-DGIF_SUPPORTED -DPPM_SUPPORTED ${USE_SETMODE}")
else()
set(COMPILE_FLAGS "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED ${USE_SETMODE}")
set(CJPEG_BMP_SOURCES ../rdbmp.c ../rdtarga.c)
set(DJPEG_BMP_SOURCES ../wrbmp.c ../wrtarga.c)
endif()
add_executable(cjpeg ../cjpeg.c ../cdjpeg.c ../rdgif.c ../rdppm.c
../rdswitch.c ${CJPEG_BMP_SOURCES})
set_property(TARGET cjpeg PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS})
target_link_libraries(cjpeg jpeg)
add_executable(djpeg ../djpeg.c ../cdjpeg.c ../rdcolmap.c ../rdswitch.c
../wrgif.c ../wrppm.c ${DJPEG_BMP_SOURCES})
set_property(TARGET djpeg PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS})
target_link_libraries(djpeg jpeg)
add_executable(jpegtran ../jpegtran.c ../cdjpeg.c ../rdswitch.c ../transupp.c)
target_link_libraries(jpegtran jpeg)
set_property(TARGET jpegtran PROPERTY COMPILE_FLAGS "${USE_SETMODE}")
add_executable(jcstest ../jcstest.c)
target_link_libraries(jcstest jpeg)
install(TARGETS jpeg cjpeg djpeg jpegtran
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})