Browse Source

Create .la files at the end of the cmake run

We might not have all the necessary information, e.g. all targets might
not exist yet, until we're done going through all CMakeLists.
pull/1579/head
Pierre Ossman 1 year ago
parent
commit
0043c557fc
2 changed files with 34 additions and 11 deletions
  1. 2
    0
      CMakeLists.txt
  2. 32
    11
      cmake/Modules/CMakeMacroLibtoolFile.cmake

+ 2
- 0
CMakeLists.txt View File

@@ -348,3 +348,5 @@ configure_file("${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"cmake_uninstall.cmake" IMMEDIATE @ONLY)

add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P cmake_uninstall.cmake)

libtool_generate_control_files()

+ 32
- 11
cmake/Modules/CMakeMacroLibtoolFile.cmake View File

@@ -1,4 +1,20 @@
macro(libtool_create_control_file _target)
# FIXME: Since we cannot require CMake 3.17, we cannot used deferred
# functions, and hence we have to do something similar manually

set_property(GLOBAL PROPERTY LIBTOOL_TARGETS "")

function(libtool_create_control_file target)
set_property(GLOBAL APPEND PROPERTY LIBTOOL_TARGETS ${target})
endfunction()

function(libtool_generate_control_files)
get_property(LIBTOOL_TARGETS GLOBAL PROPERTY LIBTOOL_TARGETS)
foreach(target ${LIBTOOL_TARGETS})
libtool_generate_control_file(${target})
endforeach()
endfunction()

function(libtool_generate_control_file _target)
get_target_property(_target_type ${_target} TYPE)

message("-- Creating static libtool control file for target ${_target}")
@@ -141,9 +157,11 @@ macro(libtool_create_control_file _target)
endif()
endforeach()

get_target_property(_binary_dir ${_target} BINARY_DIR)

# Write the libtool control file for the static library
set(_lname ${CMAKE_STATIC_LIBRARY_PREFIX}${_target})
set(_laname ${CMAKE_CURRENT_BINARY_DIR}/${_lname}.la)
set(_laname ${_binary_dir}/${_lname}.la)

file(WRITE ${_laname} "# ${_lname}.la - a libtool library file\n# Generated by ltmain.sh (GNU libtool) 2.2.6b\n")
file(APPEND ${_laname} "dlname=''\n\n")
@@ -162,15 +180,18 @@ macro(libtool_create_control_file _target)
file(APPEND ${_laname} "libdir='/usr/lib'\n\n")

# Make sure the timestamp is updated to trigger other make invocations
add_custom_command(TARGET ${_target} POST_BUILD COMMAND
"${CMAKE_COMMAND}" -E touch "${_laname}")
add_custom_command(OUTPUT "${_laname}" DEPENDS ${_target}
COMMENT "Updating timestamp on ${_lname}.la"
COMMAND "${CMAKE_COMMAND}" -E touch "${_laname}")

# Add custom command to symlink the static library so that autotools finds
# the library in .libs. These are executed after the specified target build.
add_custom_command(TARGET ${_target} POST_BUILD COMMAND
"${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/.libs")
add_custom_command(TARGET ${_target} POST_BUILD COMMAND
"${CMAKE_COMMAND}" -E create_symlink ../${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX} "${CMAKE_CURRENT_BINARY_DIR}/.libs/${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX}")

endmacro()
set(_libname ${_binary_dir}/.libs/${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX})
add_custom_command(OUTPUT "${_libname}" DEPENDS ${_target}
COMMENT "Creating symlink .libs/${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX}"
COMMAND "${CMAKE_COMMAND}" -E make_directory "${_binary_dir}/.libs"
COMMAND "${CMAKE_COMMAND}" -E create_symlink ../${_lname}${CMAKE_STATIC_LIBRARY_SUFFIX} "${_libname}")

add_custom_target(${_target}.la ALL
DEPENDS "${_laname}" "${_libname}")
endfunction()

Loading…
Cancel
Save