blob: 09f9494d408bb0cac115f4d19a26b26a786d449f [file] [log] [blame]
Henrik Andersson23029cc2011-06-09 09:13:23 +00001macro(libtool_create_control_file _target)
2 # Get target properties to fill into control file
3 get_target_property(_target_location ${_target} LOCATION)
4 get_target_property(_target_type ${_target} TYPE)
5
6 message("-- Creating static libtool control file for target ${_target}")
7 # No support for shared libraries as tigervnc only needs libtool config files
8 # for static libraries
9 if("${_target_type}" MATCHES "^[^STATIC_LIBRARY]$")
10 message(ERROR " - trying to use libtool_create_control_file on non static library target.")
11 endif()
12
13 #
14 # Parse the target_LIB_DEPENDS of libraries to put into libtool control file
15 # as library dependencies and handle a few corners...
16 #
17 foreach(library ${${_target}_LIB_DEPENDS})
18 # Assume all entries as shared if not platform specific static library
19 # extension is matched
20 if("${library}" MATCHES "[^.+\\${CMAKE_STATIC_LIBRARY_SUFFIX}]$")
21 # Check if we have shared extenstion or not
22 if("${library}" MATCHES ".+\\${CMAKE_SHARED_LIBRARY_SUFFIX}$")
23 # We got an shared library lets cut it down to path and library name then
24 # add to libtool dependency libs, we always assume this is a absoult path
25 # because this is how cmake does..
26 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})
29 set(_target_dependency_libs "${_target_dependency_libs} -L${_shared_lib_path} -l${_shared_lib}")
30 else()
31 # No shared library suffix found, might also be a cmake target.
32 # Dont continue if we have a target name as lib due to we
33 # assume static linkage against out targets
34 get_target_property(_ltp ${library} TYPE)
35 if(${_ltp})
36 # No cmake target soo let's use find_library to see if we found any useful to use
37 find_library(FL ${library})
38 if(FL)
39 # Found library, lets cut it down to make libtool happy
40 get_filename_component(_shared_lib ${FL} NAME_WE)
41 get_filename_component(_shared_lib_path ${FL} PATH)
42 string(REPLACE "lib" "" _shared_lib ${_shared_lib})
43 set(_target_dependency_libs "${_target_dependency_libs} -L${_share_lib_path} -l${_shared_lib}")
44 else()
45 # Nothing found, lets ignore it
46 endif()
47 else()
48 # taget detected lets ignore it
49 endif()
50 endif()
51 else()
52 # Detected a static library, we want the absolute path so lets check if we have that
53 # if not try use find_library to get one
54 get_filename_component(_name ${library} NAME)
55 string(REPLACE "${_name}" "" _path ${library})
56 if(NOT "${_path}" MATCHES "")
57 # We got a full path to static library lets add as is to libtool library dependencies
58 set(_target_dependency_libs "${_target_dependency_libs} ${library}")
59 else()
60 # there no path for the static library lets use find_library to find one
61 find_library(FL ${library})
62 if(FL)
63 # got the library lets add it..
64 set(_target_dependency_libs "${_target_dependency_libs} ${FL}")
65 else()
66 # Nothing found, let's ignore it
67 endif()
68 endif()
69 endif()
70 endforeach()
71
72 # Write the libtool control file for static library
73 get_filename_component(_lname ${_target_location} NAME_WE)
74 set(_laname ${CMAKE_CURRENT_BINARY_DIR}/${_lname}.la)
75
76 file(WRITE ${_laname} "# ${_lname}.la - a libtool library file\n# Generated by ltmain.sh (GNU libtool) 2.2.6b\n")
77 file(APPEND ${_laname} "dlname=''\n\n")
78 file(APPEND ${_laname} "library_names=''\n\n")
Henrik Andersson697954f2011-06-09 13:26:05 +000079 file(APPEND ${_laname} "old_library='${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX}'\n\n")
Henrik Andersson23029cc2011-06-09 09:13:23 +000080 file(APPEND ${_laname} "inherited_linker_flags=''\n\n")
81 file(APPEND ${_laname} "dependency_libs=' ${_target_dependency_libs}'\n\n")
82 file(APPEND ${_laname} "weak_library_names=''\n\n")
83 file(APPEND ${_laname} "current=\n")
84 file(APPEND ${_laname} "age=\n")
85 file(APPEND ${_laname} "revision=\n\n")
86 file(APPEND ${_laname} "installed=no\n\n")
87 file(APPEND ${_laname} "shouldnotlink=no\n\n")
88 file(APPEND ${_laname} "dlopen=''\n")
89 file(APPEND ${_laname} "dlpreopen=''\n\n")
90 file(APPEND ${_laname} "libdir=''\n\n")
91
Henrik Andersson697954f2011-06-09 13:26:05 +000092
93 # Add custom command to symlink the static library soo that autotools finds the library in .libs
94 # these are executed after the specified target build.
95 add_custom_command(TARGET ${_target} POST_BUILD COMMAND
96 cmake -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/.libs")
97 add_custom_command(TARGET ${_target} POST_BUILD COMMAND
98 cmake -E create_symlink ${_target_location} "${CMAKE_CURRENT_SOURCE_DIR}/.libs/${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX}")
99
Henrik Andersson23029cc2011-06-09 09:13:23 +0000100endmacro()