From 0373fb254e28fc50edb2f026349dfb4555124fbd Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Sun, 13 Jan 2013 12:51:09 -0800 Subject: [PATCH] We now use @loader_path on Mac for libclang This makes sure that our local copy of libclang.dylib is preferred over the system one. --- cpp/ycm/CMakeLists.txt | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/cpp/ycm/CMakeLists.txt b/cpp/ycm/CMakeLists.txt index 2cc2f56d..8e910773 100644 --- a/cpp/ycm/CMakeLists.txt +++ b/cpp/ycm/CMakeLists.txt @@ -79,10 +79,13 @@ if ( EXTERNAL_LIBCLANG_PATH OR USE_SYSTEM_LIBCLANG ) if ( USE_SYSTEM_LIBCLANG ) find_library( EXTERNAL_LIBCLANG_PATH clang ) else() - # Setting this to true makes sure that libraries we build will have our rpath - # set even without having to do "make install" - set( CMAKE_BUILD_WITH_INSTALL_RPATH TRUE ) - set( CMAKE_INSTALL_RPATH "\$ORIGIN" ) + # For Macs, we do things differently; look further in this file. + if ( NOT APPLE ) + # Setting this to true makes sure that libraries we build will have our rpath + # set even without having to do "make install" + set( CMAKE_BUILD_WITH_INSTALL_RPATH TRUE ) + set( CMAKE_INSTALL_RPATH "\$ORIGIN" ) + endif() endif() set( LIBCLANG_TARGET ${EXTERNAL_LIBCLANG_PATH} ) @@ -110,6 +113,27 @@ target_link_libraries( ${PROJECT_NAME} ${LIBCLANG_TARGET} ) +############################################################################# + +# Things are a bit different on Macs when using an external libclang.dylib; here +# we want to make sure we use @loader_path/libclang.dylib instead of +# @rpath/libclang.dylib in the final ycm_core.so. If we use the @rpath version, +# then it may load the system libclang which the user explicitely does not want +# (otherwise the user would specify USE_SYSTEM_LIBCLANG). With @loader_path, we +# make sure that only the libclang.dylib present in the same directory as our +# ycm_core.so is used. +if ( EXTERNAL_LIBCLANG_PATH AND APPLE ) + add_custom_command( TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND install_name_tool + "-change" + "@rpath/libclang.dylib" + "@loader_path/libclang.dylib" + "$" + ) +endif() + + ############################################################################# # We don't want the "lib" prefix, it can screw up python when it tries to search