Skip to content

Commit 5e96fe9

Browse files
author
Chris Bieneman
committed
[CMake] Bug 25059 - CMake libllvm.so.$MAJOR.$MINOR shared object name not compatible with ldconfig
Summary: This change makes the CMake build system generate libraries for Linux and Darwin matching the makefile build system. Linux libraries follow the pattern lib${name}.${MAJOR}.${MINOR}.so so that ldconfig won't pick it up incorrectly. Darwin libraries are not versioned. Note: On linux the non-versioned symlink is generated at install-time not build time. I plan to fix that eventually, but I expect that is good enough for the purposes of fixing this bug. Reviewers: loladiro, tstellarAMD Subscribers: axw, llvm-commits Differential Revision: http://reviews.llvm.org/D13841 llvm-svn: 252093
1 parent 88a12f5 commit 5e96fe9

2 files changed

Lines changed: 53 additions & 8 deletions

File tree

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,12 @@ endfunction(set_windows_version_resource_properties)
324324
# Same semantics as target_link_libraries().
325325
# ADDITIONAL_HEADERS
326326
# May specify header files for IDE generators.
327+
# SONAME
328+
# Should set SONAME link flags and create symlinks
327329
# )
328330
function(llvm_add_library name)
329331
cmake_parse_arguments(ARG
330-
"MODULE;SHARED;STATIC;DISABLE_LLVM_LINK_LLVM_DYLIB"
332+
"MODULE;SHARED;STATIC;DISABLE_LLVM_LINK_LLVM_DYLIB;SONAME"
331333
"OUTPUT_NAME"
332334
"ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS;OBJLIBS"
333335
${ARGN})
@@ -432,11 +434,6 @@ function(llvm_add_library name)
432434
PREFIX ""
433435
)
434436
endif()
435-
436-
set_target_properties(${name}
437-
PROPERTIES
438-
SOVERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}
439-
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
440437
endif()
441438

442439
if(ARG_MODULE OR ARG_SHARED)
@@ -501,7 +498,7 @@ endfunction()
501498

502499
macro(add_llvm_library name)
503500
cmake_parse_arguments(ARG
504-
"SHARED"
501+
"SHARED;SONAME"
505502
""
506503
""
507504
${ARGN})
@@ -544,6 +541,19 @@ macro(add_llvm_library name)
544541
-DCMAKE_INSTALL_COMPONENT=${name}
545542
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
546543
endif()
544+
if(ARG_SHARED AND UNIX)
545+
if(NOT APPLE AND ARG_SONAME)
546+
set(library_name ${name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}${LLVM_VERSION_SUFFIX})
547+
set(api_name ${name}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
548+
set_target_properties(${name} PROPERTIES OUTPUT_NAME ${library_name})
549+
llvm_install_library_symlink(${api_name} ${library_name} SHARED
550+
COMPONENT ${name}
551+
ALWAYS_GENERATE)
552+
llvm_install_library_symlink(${name} ${library_name} SHARED
553+
COMPONENT ${name}
554+
ALWAYS_GENERATE)
555+
endif()
556+
endif()
547557
endif()
548558
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
549559
endif()
@@ -1042,6 +1052,41 @@ function(add_lit_testsuites project directory)
10421052
endif()
10431053
endfunction()
10441054

1055+
function(llvm_install_library_symlink name dest type)
1056+
cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
1057+
foreach(path ${CMAKE_MODULE_PATH})
1058+
if(EXISTS ${path}/LLVMInstallSymlink.cmake)
1059+
set(INSTALL_SYMLINK ${path}/LLVMInstallSymlink.cmake)
1060+
break()
1061+
endif()
1062+
endforeach()
1063+
1064+
set(component ${ARG_COMPONENT})
1065+
if(NOT component)
1066+
set(component ${name})
1067+
endif()
1068+
1069+
set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX})
1070+
set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX})
1071+
1072+
set(output_dir lib)
1073+
if(WIN32 AND "${type}" STREQUAL "SHARED")
1074+
set(output_dir bin)
1075+
endif()
1076+
1077+
install(SCRIPT ${INSTALL_SYMLINK}
1078+
CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
1079+
COMPONENT ${component})
1080+
1081+
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE)
1082+
add_custom_target(install-${name}
1083+
DEPENDS ${name} ${dest} install-${dest}
1084+
COMMAND "${CMAKE_COMMAND}"
1085+
-DCMAKE_INSTALL_COMPONENT=${name}
1086+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
1087+
endif()
1088+
endfunction()
1089+
10451090
function(llvm_install_symlink name dest)
10461091
cmake_parse_arguments(ARG "ALWAYS_GENERATE" "" "" ${ARGN})
10471092
foreach(path ${CMAKE_MODULE_PATH})

llvm/tools/llvm-shlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if(LLVM_DYLIB_EXPORTED_SYMBOL_FILE)
3838
add_custom_target(libLLVMExports DEPENDS ${LLVM_EXPORTED_SYMBOL_FILE})
3939
endif()
4040
41-
add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB ${SOURCES})
41+
add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})
4242
4343
list(REMOVE_DUPLICATES LIB_NAMES)
4444
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") # FIXME: It should be "GNU ld for elf"

0 commit comments

Comments
 (0)