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