remove `#!/usr/bin/env sh`
[liba.git] / cmake / InstallLibtool.cmake
blobba37842a41ecbd26283503100b285226c8231513
1 function(install_libtool)
2   set(one_value_keywords "CURRENT;AGE;REVISION;INSTALLED;SHOULDNOTLINK;DLOPEN;DLPREOPEN;LIBDIR")
3   set(multi_value_keywords "TARGETS;DEPENDENCY_LIBS;WEAK_LIBRARY_NAMES;INHERITED_LINKER_FLAGS")
4   cmake_parse_arguments(LT "" "${one_value_keywords}" "${multi_value_keywords}" ${ARGN})
5   list(APPEND LT_TARGETS ${LT_UNPARSED_ARGUMENTS})
6   if(NOT DEFINED LT_INSTALLED OR LT_INSTALLED)
7     set(LT_INSTALLED yes)
8   else()
9     set(LT_INSTALLED no)
10   endif()
11   if(NOT DEFINED LT_SHOULDNOTLINK OR LT_SHOULDNOTLINK)
12     set(LT_SHOULDNOTLINK yes)
13   else()
14     set(LT_SHOULDNOTLINK no)
15   endif()
16   if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
17     set(CMAKE_INSTALL_LIBDIR lib)
18   endif()
19   if(NOT DEFINED LT_LIBDIR)
20     set(LT_LIBDIR ${CMAKE_INSTALL_LIBDIR})
21   elseif(IS_ABSOLUTE ${LT_LIBDIR})
22     get_filename_component(LT_LIBDIR ${LT_LIBDIR} NAME)
23   endif()
24   foreach(target ${LT_TARGETS})
25     get_property(name TARGET ${target} PROPERTY OUTPUT_NAME)
26     if(NOT name)
27       set(name ${CMAKE_STATIC_LIBRARY_PREFIX}${target})
28     else()
29       set(name ${CMAKE_STATIC_LIBRARY_PREFIX}${name})
30     endif()
31     get_property(type TARGET ${target} PROPERTY TYPE)
32     if(type MATCHES "(SHARED|MODULE)_LIBRARY")
33       if(UNIX)
34         set(LT_DLNAME $<TARGET_FILE_NAME:${target}>)
35       else()
36         set(LT_DLNAME $<TARGET_LINKER_FILE_NAME:${target}>)
37       endif()
38       list(APPEND LT_LIBRARY_NAMES ${LT_DLNAME})
39       get_property(version TARGET ${target} PROPERTY VERSION)
40       get_property(soversion TARGET ${target} PROPERTY SOVERSION)
41       if(UNIX AND (DEFINED version AND DEFINED soversion))
42         set(LT_DLNAME $<TARGET_SONAME_FILE_NAME:${target}>)
43         list(APPEND LT_LIBRARY_NAMES $<TARGET_SONAME_FILE_NAME:${target}>)
44       endif()
45       if(UNIX AND (DEFINED version OR DEFINED soversion))
46         list(APPEND LT_LIBRARY_NAMES $<TARGET_LINKER_FILE_NAME:${target}>)
47       endif()
48       string(REGEX MATCHALL "[0-9]+" version "${version}.0.0.0")
49       list(GET version 0 major)
50       list(GET version 1 minor)
51       list(GET version 2 patch)
52       math(EXPR LT_CURRENT "${major}+${minor}")
53       math(EXPR LT_REVISION "${patch}")
54       math(EXPR LT_AGE "${minor}")
55     elseif(type MATCHES "STATIC_LIBRARY")
56       set(LT_OLD_LIBRARY $<TARGET_FILE_NAME:${target}>)
57       if(NOT DEFINED LT_DLNAME)
58         set(LT_DLNAME $<TARGET_FILE_NAME:${target}>)
59       endif()
60     endif()
61   endforeach()
62   file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}.la
63   CONTENT "# ${name}.la - a libtool library file
64 # Generated by CMake ${CMAKE_VERSION} (like GNU libtool)\n#
65 # Please DO NOT delete this file!\n# It is necessary for linking the library.\n
66 # The name that we can dlopen(3).\ndlname='${LT_DLNAME}'\n
67 # Names of this library.\nlibrary_names='$<JOIN:${LT_LIBRARY_NAMES}, >'\n
68 # The name of the static archive.\nold_library='${LT_OLD_LIBRARY}'\n
69 # Linker flags that cannot go in dependency_libs.\ninherited_linker_flags='$<JOIN:${LT_INHERITED_LINKER_FLAGS}, >'\n
70 # Libraries that this one depends upon.\ndependency_libs='$<JOIN:${LT_DEPENDENCY_LIBS}, >'\n
71 # Names of additional weak libraries provided by this library\nweak_library_names='$<JOIN:${WEAK_LIBRARY_NAMES}, >'\n
72 # Version information for ${name}.\ncurrent=${LT_CURRENT}\nage=${LT_AGE}\nrevision=${LT_REVISION}\n
73 # Is this an already installed library?\ninstalled=${LT_INSTALLED}\n
74 # Should we warn about portability when linking against -modules?\nshouldnotlink=${LT_SHOULDNOTLINK}\n
75 # Files to dlopen/dlpreopen\ndlopen='${LD_DLOPEN}'\ndlpreopen='${LD_DLPREOPEN}'\n
76 # Directory that this library needs to be installed in:\nlibdir='${CMAKE_INSTALL_PREFIX}/${LT_LIBDIR}'
78   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}.la DESTINATION ${LT_LIBDIR})
79 endfunction()