blob: a265789ea3c1abd362661f0d0d51bab34f451687 [file] [log] [blame]
Henrik Andersson23029cc2011-06-09 09:13:23 +00001macro(libtool_create_control_file _target)
Henrik Andersson23029cc2011-06-09 09:13:23 +00002 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}")
DRCa18a88f2011-06-22 00:08:26 +00006 # No support for shared libraries, as TigerVNC only needs libtool config
7 # files for static libraries.
Henrik Andersson23029cc2011-06-09 09:13:23 +00008 if("${_target_type}" MATCHES "^[^STATIC_LIBRARY]$")
DRCa18a88f2011-06-22 00:08:26 +00009 message(ERROR " - trying to use libtool_create_control_file for non-static library target.")
Henrik Andersson23029cc2011-06-09 09:13:23 +000010 endif()
11
12 #
DRCa18a88f2011-06-22 00:08:26 +000013 # 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 Andersson23029cc2011-06-09 09:13:23 +000016 #
17 foreach(library ${${_target}_LIB_DEPENDS})
DRCa18a88f2011-06-22 00:08:26 +000018 # Assume all entries are shared libs if platform-specific static library
19 # extension is not matched.
Henrik Andersson23029cc2011-06-09 09:13:23 +000020 if("${library}" MATCHES "[^.+\\${CMAKE_STATIC_LIBRARY_SUFFIX}]$")
Henrik Andersson23029cc2011-06-09 09:13:23 +000021 if("${library}" MATCHES ".+\\${CMAKE_SHARED_LIBRARY_SUFFIX}$")
DRCa18a88f2011-06-22 00:08:26 +000022 # Shared library extension matched, so extract the path and library
23 # name, then add the result to the libtool dependency libs. This
24 # will always be an absolute path, because that's what CMake uses
25 # internally.
DRCdadfbec2011-06-22 00:01:39 +000026 get_filename_component(_shared_lib ${library} NAME_WE)
27 get_filename_component(_shared_lib_path ${library} PATH)
28 string(REPLACE "lib" "" _shared_lib ${_shared_lib})
Henrik Andersson23029cc2011-06-09 09:13:23 +000029 set(_target_dependency_libs "${_target_dependency_libs} -L${_shared_lib_path} -l${_shared_lib}")
30 else()
DRCa18a88f2011-06-22 00:08:26 +000031 # No shared library extension matched. Check whether target is a CMake
32 # target.
DRCdadfbec2011-06-22 00:01:39 +000033 get_target_property(_ltp ${library} TYPE)
DRC801ef7c2011-06-22 00:11:00 +000034 if(NOT _ltp AND NOT ${library} STREQUAL "general")
DRCa18a88f2011-06-22 00:08:26 +000035 # Not a CMake target, so use find_library() to attempt to locate the
36 # library in a system directory.
DRCdadfbec2011-06-22 00:01:39 +000037 find_library(FL ${library})
38 if(FL)
DRCa18a88f2011-06-22 00:08:26 +000039 # Found library, so extract the path and library name, then add the
40 # result to the libtool dependency libs.
DRCdadfbec2011-06-22 00:01:39 +000041 get_filename_component(_shared_lib ${FL} NAME_WE)
42 get_filename_component(_shared_lib_path ${FL} PATH)
43 string(REPLACE "lib" "" _shared_lib ${_shared_lib})
DRC801ef7c2011-06-22 00:11:00 +000044 set(_target_dependency_libs "${_target_dependency_libs} -L${_shared_lib_path} -l${_shared_lib}")
DRCdadfbec2011-06-22 00:01:39 +000045 else()
DRCa18a88f2011-06-22 00:08:26 +000046 # No shared library found, so ignore target.
DRCdadfbec2011-06-22 00:01:39 +000047 endif()
Pierre Ossman818550b2014-11-03 14:17:10 +010048 # Need to clear FL to get new results next loop
49 unset(FL CACHE)
DRCdadfbec2011-06-22 00:01:39 +000050 else()
DRCa18a88f2011-06-22 00:08:26 +000051 # Target is a CMake target, so ignore if (CMake targets are static
52 # libs in TigerVNC.)
DRCdadfbec2011-06-22 00:01:39 +000053 endif()
Henrik Andersson23029cc2011-06-09 09:13:23 +000054 endif()
55 else()
DRCa18a88f2011-06-22 00:08:26 +000056 # Detected a static library. Check whether the library pathname is
57 # absolute and, if not, use find_library() to get the abolute path.
Henrik Andersson23029cc2011-06-09 09:13:23 +000058 get_filename_component(_name ${library} NAME)
59 string(REPLACE "${_name}" "" _path ${library})
DRC801ef7c2011-06-22 00:11:00 +000060 if(NOT "${_path}" STREQUAL "")
DRCa18a88f2011-06-22 00:08:26 +000061 # Pathname is absolute, so add it to the libtool library dependencies
62 # as-is.
Henrik Andersson23029cc2011-06-09 09:13:23 +000063 set(_target_dependency_libs "${_target_dependency_libs} ${library}")
64 else()
DRCa18a88f2011-06-22 00:08:26 +000065 # Pathname is not absolute, so use find_library() to get the absolute
66 # path.
DRCdadfbec2011-06-22 00:01:39 +000067 find_library(FL ${library})
68 if(FL)
DRCa18a88f2011-06-22 00:08:26 +000069 # Absolute pathname found. Add it.
DRCdadfbec2011-06-22 00:01:39 +000070 set(_target_dependency_libs "${_target_dependency_libs} ${FL}")
71 else()
DRCa18a88f2011-06-22 00:08:26 +000072 # No absolute pathname found. Ignore it.
DRCdadfbec2011-06-22 00:01:39 +000073 endif()
Pierre Ossman818550b2014-11-03 14:17:10 +010074 # Need to clear FL to get new results next loop
75 unset(FL CACHE)
Henrik Andersson23029cc2011-06-09 09:13:23 +000076 endif()
77 endif()
78 endforeach()
79
DRCa18a88f2011-06-22 00:08:26 +000080 # Write the libtool control file for the static library
Henrik Andersson23029cc2011-06-09 09:13:23 +000081 get_filename_component(_lname ${_target_location} NAME_WE)
82 set(_laname ${CMAKE_CURRENT_BINARY_DIR}/${_lname}.la)
DRC754ff592011-08-09 02:26:30 +000083
Henrik Andersson23029cc2011-06-09 09:13:23 +000084 file(WRITE ${_laname} "# ${_lname}.la - a libtool library file\n# Generated by ltmain.sh (GNU libtool) 2.2.6b\n")
85 file(APPEND ${_laname} "dlname=''\n\n")
86 file(APPEND ${_laname} "library_names=''\n\n")
Henrik Andersson697954f2011-06-09 13:26:05 +000087 file(APPEND ${_laname} "old_library='${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX}'\n\n")
Henrik Andersson23029cc2011-06-09 09:13:23 +000088 file(APPEND ${_laname} "inherited_linker_flags=''\n\n")
89 file(APPEND ${_laname} "dependency_libs=' ${_target_dependency_libs}'\n\n")
90 file(APPEND ${_laname} "weak_library_names=''\n\n")
91 file(APPEND ${_laname} "current=\n")
92 file(APPEND ${_laname} "age=\n")
93 file(APPEND ${_laname} "revision=\n\n")
94 file(APPEND ${_laname} "installed=no\n\n")
95 file(APPEND ${_laname} "shouldnotlink=no\n\n")
96 file(APPEND ${_laname} "dlopen=''\n")
97 file(APPEND ${_laname} "dlpreopen=''\n\n")
98 file(APPEND ${_laname} "libdir=''\n\n")
99
Henrik Andersson697954f2011-06-09 13:26:05 +0000100
DRCa18a88f2011-06-22 00:08:26 +0000101 # Add custom command to symlink the static library so that autotools finds
102 # the library in .libs. These are executed after the specified target build.
Henrik Andersson697954f2011-06-09 13:26:05 +0000103 add_custom_command(TARGET ${_target} POST_BUILD COMMAND
Brian Hinz491b9502013-04-27 20:14:50 +0000104 "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/.libs")
Henrik Andersson697954f2011-06-09 13:26:05 +0000105 add_custom_command(TARGET ${_target} POST_BUILD COMMAND
Brian Hinz491b9502013-04-27 20:14:50 +0000106 "${CMAKE_COMMAND}" -E create_symlink ${_target_location} "${CMAKE_CURRENT_BINARY_DIR}/.libs/${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX}")
Henrik Andersson697954f2011-06-09 13:26:05 +0000107
DRC5dc23af2011-06-09 22:06:05 +0000108endmacro()