Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 1 | macro(libtool_create_control_file _target) |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 2 | get_target_property(_target_type ${_target} TYPE) |
| 3 | |
| 4 | message("-- Creating static libtool control file for target ${_target}") |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 5 | # No support for shared libraries, as TigerVNC only needs libtool config |
| 6 | # files for static libraries. |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 7 | if("${_target_type}" MATCHES "^[^STATIC_LIBRARY]$") |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 8 | message(ERROR " - trying to use libtool_create_control_file for non-static library target.") |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 9 | endif() |
| 10 | |
| 11 | # |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 12 | # Parse the target_LIB_DEPENDS variable to determine which libraries to put |
| 13 | # into libtool control file as library dependencies, and handle a few corner |
| 14 | # cases. |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 15 | # |
Pierre Ossman | 216d591 | 2014-11-03 14:18:44 +0100 | [diff] [blame] | 16 | |
| 17 | # First we need to split up any internal entries |
| 18 | set(target_libs "") |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 19 | foreach(library ${${_target}_LIB_DEPENDS}) |
Pierre Ossman | 216d591 | 2014-11-03 14:18:44 +0100 | [diff] [blame] | 20 | if("${library}" MATCHES " ") |
| 21 | string(REPLACE " " ";" lib_list "${library}") |
| 22 | list(APPEND target_libs ${lib_list}) |
| 23 | else() |
| 24 | list(APPEND target_libs "${library}") |
| 25 | endif() |
| 26 | endforeach() |
| 27 | |
Pierre Ossman | 881a8e2 | 2014-11-03 14:20:46 +0100 | [diff] [blame] | 28 | set(STATIC_MODE OFF) |
| 29 | |
Pierre Ossman | 216d591 | 2014-11-03 14:18:44 +0100 | [diff] [blame] | 30 | foreach(library ${target_libs}) |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 31 | # Assume all entries are shared libs if platform-specific static library |
| 32 | # extension is not matched. |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 33 | if("${library}" MATCHES "[^.+\\${CMAKE_STATIC_LIBRARY_SUFFIX}]$") |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 34 | if("${library}" MATCHES ".+\\${CMAKE_SHARED_LIBRARY_SUFFIX}$") |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 35 | # Shared library extension matched, so extract the path and library |
| 36 | # name, then add the result to the libtool dependency libs. This |
| 37 | # will always be an absolute path, because that's what CMake uses |
| 38 | # internally. |
DRC | dadfbec | 2011-06-22 00:01:39 +0000 | [diff] [blame] | 39 | get_filename_component(_shared_lib ${library} NAME_WE) |
| 40 | get_filename_component(_shared_lib_path ${library} PATH) |
| 41 | string(REPLACE "lib" "" _shared_lib ${_shared_lib}) |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 42 | set(_target_dependency_libs "${_target_dependency_libs} -L${_shared_lib_path} -l${_shared_lib}") |
| 43 | else() |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 44 | # No shared library extension matched. Check whether target is a CMake |
| 45 | # target. |
DRC | dadfbec | 2011-06-22 00:01:39 +0000 | [diff] [blame] | 46 | get_target_property(_ltp ${library} TYPE) |
Pierre Ossman | 881a8e2 | 2014-11-03 14:20:46 +0100 | [diff] [blame] | 47 | if(_ltp OR ${library} STREQUAL "general") |
| 48 | # Target is a CMake target, so ignore (CMake targets are static |
| 49 | # libs in TigerVNC.) |
| 50 | elseif(${library} STREQUAL "-Wl,-Bstatic") |
| 51 | # All following libraries should be static |
| 52 | set(STATIC_MODE ON) |
| 53 | elseif(${library} STREQUAL "-Wl,-Bdynamic") |
| 54 | # All following libraries should be dynamic |
| 55 | set(STATIC_MODE OFF) |
| 56 | else() |
| 57 | # Normal library, so use find_library() to attempt to locate the |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 58 | # library in a system directory. |
Pierre Ossman | 40a5f9e | 2014-11-03 14:20:01 +0100 | [diff] [blame] | 59 | |
| 60 | # Need to remove -l prefix |
| 61 | if (${library} MATCHES "^\\${CMAKE_LINK_LIBRARY_FLAG}") |
| 62 | string(REPLACE ${CMAKE_LINK_LIBRARY_FLAG} "" library ${library}) |
| 63 | endif() |
| 64 | |
Pierre Ossman | 881a8e2 | 2014-11-03 14:20:46 +0100 | [diff] [blame] | 65 | if(STATIC_MODE) |
| 66 | set(library ${CMAKE_STATIC_LIBRARY_PREFIX}${library}${CMAKE_STATIC_LIBRARY_SUFFIX}) |
| 67 | endif() |
| 68 | |
DRC | dadfbec | 2011-06-22 00:01:39 +0000 | [diff] [blame] | 69 | find_library(FL ${library}) |
| 70 | if(FL) |
Pierre Ossman | 881a8e2 | 2014-11-03 14:20:46 +0100 | [diff] [blame] | 71 | # Found library. Depending on if it's static or not we might |
| 72 | # extract the path and library name, then add the |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 73 | # result to the libtool dependency libs. |
Pierre Ossman | 881a8e2 | 2014-11-03 14:20:46 +0100 | [diff] [blame] | 74 | if(STATIC_MODE) |
| 75 | set(_target_dependency_libs "${_target_dependency_libs} ${FL}") |
| 76 | else() |
| 77 | get_filename_component(_shared_lib ${FL} NAME_WE) |
| 78 | get_filename_component(_shared_lib_path ${FL} PATH) |
| 79 | string(REPLACE "lib" "" _shared_lib ${_shared_lib}) |
| 80 | set(_target_dependency_libs "${_target_dependency_libs} -L${_shared_lib_path} -l${_shared_lib}") |
| 81 | endif() |
DRC | dadfbec | 2011-06-22 00:01:39 +0000 | [diff] [blame] | 82 | else() |
Pierre Ossman | 881a8e2 | 2014-11-03 14:20:46 +0100 | [diff] [blame] | 83 | # No library found, so ignore target. |
DRC | dadfbec | 2011-06-22 00:01:39 +0000 | [diff] [blame] | 84 | endif() |
Pierre Ossman | 818550b | 2014-11-03 14:17:10 +0100 | [diff] [blame] | 85 | # Need to clear FL to get new results next loop |
| 86 | unset(FL CACHE) |
DRC | dadfbec | 2011-06-22 00:01:39 +0000 | [diff] [blame] | 87 | endif() |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 88 | endif() |
| 89 | else() |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 90 | # Detected a static library. Check whether the library pathname is |
klemens | 0536d09 | 2017-01-28 20:56:56 +0100 | [diff] [blame] | 91 | # absolute and, if not, use find_library() to get the absolute path. |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 92 | get_filename_component(_name ${library} NAME) |
| 93 | string(REPLACE "${_name}" "" _path ${library}) |
DRC | 801ef7c | 2011-06-22 00:11:00 +0000 | [diff] [blame] | 94 | if(NOT "${_path}" STREQUAL "") |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 95 | # Pathname is absolute, so add it to the libtool library dependencies |
| 96 | # as-is. |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 97 | set(_target_dependency_libs "${_target_dependency_libs} ${library}") |
| 98 | else() |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 99 | # Pathname is not absolute, so use find_library() to get the absolute |
| 100 | # path. |
DRC | dadfbec | 2011-06-22 00:01:39 +0000 | [diff] [blame] | 101 | find_library(FL ${library}) |
| 102 | if(FL) |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 103 | # Absolute pathname found. Add it. |
DRC | dadfbec | 2011-06-22 00:01:39 +0000 | [diff] [blame] | 104 | set(_target_dependency_libs "${_target_dependency_libs} ${FL}") |
| 105 | else() |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 106 | # No absolute pathname found. Ignore it. |
DRC | dadfbec | 2011-06-22 00:01:39 +0000 | [diff] [blame] | 107 | endif() |
Pierre Ossman | 818550b | 2014-11-03 14:17:10 +0100 | [diff] [blame] | 108 | # Need to clear FL to get new results next loop |
| 109 | unset(FL CACHE) |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 110 | endif() |
| 111 | endif() |
| 112 | endforeach() |
| 113 | |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 114 | # Write the libtool control file for the static library |
Pierre Ossman | c27f5da | 2017-10-06 14:29:54 +0200 | [diff] [blame^] | 115 | set(_lname ${CMAKE_STATIC_LIBRARY_PREFIX}${_target}) |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 116 | set(_laname ${CMAKE_CURRENT_BINARY_DIR}/${_lname}.la) |
DRC | 754ff59 | 2011-08-09 02:26:30 +0000 | [diff] [blame] | 117 | |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 118 | file(WRITE ${_laname} "# ${_lname}.la - a libtool library file\n# Generated by ltmain.sh (GNU libtool) 2.2.6b\n") |
| 119 | file(APPEND ${_laname} "dlname=''\n\n") |
| 120 | file(APPEND ${_laname} "library_names=''\n\n") |
Henrik Andersson | 697954f | 2011-06-09 13:26:05 +0000 | [diff] [blame] | 121 | file(APPEND ${_laname} "old_library='${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX}'\n\n") |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 122 | file(APPEND ${_laname} "inherited_linker_flags=''\n\n") |
| 123 | file(APPEND ${_laname} "dependency_libs=' ${_target_dependency_libs}'\n\n") |
| 124 | file(APPEND ${_laname} "weak_library_names=''\n\n") |
| 125 | file(APPEND ${_laname} "current=\n") |
| 126 | file(APPEND ${_laname} "age=\n") |
| 127 | file(APPEND ${_laname} "revision=\n\n") |
| 128 | file(APPEND ${_laname} "installed=no\n\n") |
| 129 | file(APPEND ${_laname} "shouldnotlink=no\n\n") |
| 130 | file(APPEND ${_laname} "dlopen=''\n") |
| 131 | file(APPEND ${_laname} "dlpreopen=''\n\n") |
Pierre Ossman | de2df7e | 2015-04-30 09:28:37 +0200 | [diff] [blame] | 132 | file(APPEND ${_laname} "libdir='/usr/lib'\n\n") |
Henrik Andersson | 23029cc | 2011-06-09 09:13:23 +0000 | [diff] [blame] | 133 | |
Pierre Ossman | 4495b72 | 2016-12-11 14:04:37 +0100 | [diff] [blame] | 134 | # Make sure the timestamp is updated to trigger other make invocations |
| 135 | add_custom_command(TARGET ${_target} POST_BUILD COMMAND |
| 136 | "${CMAKE_COMMAND}" -E touch "${_laname}") |
| 137 | |
Henrik Andersson | 697954f | 2011-06-09 13:26:05 +0000 | [diff] [blame] | 138 | |
DRC | a18a88f | 2011-06-22 00:08:26 +0000 | [diff] [blame] | 139 | # Add custom command to symlink the static library so that autotools finds |
| 140 | # the library in .libs. These are executed after the specified target build. |
Henrik Andersson | 697954f | 2011-06-09 13:26:05 +0000 | [diff] [blame] | 141 | add_custom_command(TARGET ${_target} POST_BUILD COMMAND |
Brian Hinz | 491b950 | 2013-04-27 20:14:50 +0000 | [diff] [blame] | 142 | "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/.libs") |
Henrik Andersson | 697954f | 2011-06-09 13:26:05 +0000 | [diff] [blame] | 143 | add_custom_command(TARGET ${_target} POST_BUILD COMMAND |
Pierre Ossman | c27f5da | 2017-10-06 14:29:54 +0200 | [diff] [blame^] | 144 | "${CMAKE_COMMAND}" -E create_symlink ../${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX} "${CMAKE_CURRENT_BINARY_DIR}/.libs/${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX}") |
Henrik Andersson | 697954f | 2011-06-09 13:26:05 +0000 | [diff] [blame] | 145 | |
DRC | 5dc23af | 2011-06-09 22:06:05 +0000 | [diff] [blame] | 146 | endmacro() |