]> source.dussan.org Git - tigervnc.git/commitdiff
Create .la files at the end of the cmake run 1579/head
authorPierre Ossman <ossman@cendio.se>
Wed, 16 Nov 2022 06:59:55 +0000 (07:59 +0100)
committerPierre Ossman <ossman@cendio.se>
Tue, 10 Jan 2023 18:41:13 +0000 (19:41 +0100)
We might not have all the necessary information, e.g. all targets might
not exist yet, until we're done going through all CMakeLists.

CMakeLists.txt
cmake/Modules/CMakeMacroLibtoolFile.cmake

index ce47949cea353d9d95a6ebd712ce9001bff39a54..48e49924177d0e143cd008da5eb7f1dccdc405e6 100644 (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()
index 7395a3f191dd098a29287177dbff8ab0378b7f0e..12ba99092e98c0bee0b47b6784b574d3f1af3cd3 100644 (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()