head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.1
	netbsd-11-0-RC3:1.1.1.1
	netbsd-11-0-RC2:1.1.1.1
	netbsd-11-0-RC1:1.1.1.1
	perseant-exfatfs-base-20250801:1.1.1.1
	netbsd-11:1.1.1.1.0.10
	netbsd-11-base:1.1.1.1
	netbsd-10-1-RELEASE:1.1.1.1
	perseant-exfatfs-base-20240630:1.1.1.1
	perseant-exfatfs:1.1.1.1.0.8
	perseant-exfatfs-base:1.1.1.1
	netbsd-10-0-RELEASE:1.1.1.1
	netbsd-10-0-RC6:1.1.1.1
	netbsd-10-0-RC5:1.1.1.1
	netbsd-10-0-RC4:1.1.1.1
	netbsd-10-0-RC3:1.1.1.1
	netbsd-10-0-RC2:1.1.1.1
	netbsd-10-0-RC1:1.1.1.1
	netbsd-10:1.1.1.1.0.6
	netbsd-10-base:1.1.1.1
	cjep_sun2x-base1:1.1.1.1
	cjep_sun2x:1.1.1.1.0.4
	cjep_sun2x-base:1.1.1.1
	cjep_staticlib_x:1.1.1.1.0.2
	cjep_staticlib_x-base1:1.1.1.1
	LLVM-249b40b558955afe5ac2b549edcf2d7f859c8cc9:1.1.1.1
	LLVM:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2021.05.30.01.29.20;	author joerg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	ELgSWj1pehxUV6VC;

1.1.1.1
date	2021.05.30.01.29.20;	author joerg;	state Exp;
branches
	1.1.1.1.2.1;
next	;
commitid	ELgSWj1pehxUV6VC;

1.1.1.1.2.1
date	2021.05.30.01.29.20;	author cjep;	state dead;
branches;
next	1.1.1.1.2.2;
commitid	eWz9SBW0XqKjJlVC;

1.1.1.1.2.2
date	2021.05.31.22.07.30;	author cjep;	state Exp;
branches;
next	;
commitid	eWz9SBW0XqKjJlVC;


desc
@@


1.1
log
@Initial revision
@
text
@# This function defines a linker script in place of the symlink traditionally
# created for shared libraries.
#
# More specifically, this function goes through the PUBLIC and INTERFACE
# library dependencies of <target> and gathers them into a linker script,
# such that those libraries are linked against when the shared library for
# <target> is linked against.
#
# Arguments:
#   <target>: A target representing a shared library. A linker script will be
#             created in place of that target's TARGET_LINKER_FILE, which is
#             the symlink pointing to the actual shared library (usually
#             libFoo.so pointing to libFoo.so.1, which itself points to
#             libFoo.so.1.0).

function(define_linker_script target)
  if (NOT TARGET "${target}")
    message(FATAL_ERROR "The provided target '${target}' is not actually a target.")
  endif()

  get_target_property(target_type "${target}" TYPE)
  if (NOT "${target_type}" STREQUAL "SHARED_LIBRARY")
    message(FATAL_ERROR "The provided target '${target}' is not a shared library (its type is '${target_type}').")
  endif()

  set(symlink "$<TARGET_LINKER_FILE:${target}>")
  set(soname "$<TARGET_SONAME_FILE_NAME:${target}>")

  get_target_property(interface_libs "${target}" INTERFACE_LINK_LIBRARIES)

  set(link_libraries)
  if (interface_libs)
    foreach(lib IN LISTS interface_libs)
      if ("${lib}" STREQUAL "cxx-headers")
        continue()
      endif()
      # If ${lib} is not a target, we use a dummy target which we know will
      # have an OUTPUT_NAME property so that CMake doesn't fail when evaluating
      # the non-selected branch of the `IF`. It doesn't matter what it evaluates
      # to because it's not selected, but it must not cause an error.
      # See https://gitlab.kitware.com/cmake/cmake/-/issues/21045.
      set(output_name_tgt "$<IF:$<TARGET_EXISTS:${lib}>,${lib},${target}>")
      set(libname "$<IF:$<TARGET_EXISTS:${lib}>,$<TARGET_PROPERTY:${output_name_tgt},OUTPUT_NAME>,${lib}>")
      list(APPEND link_libraries "${CMAKE_LINK_LIBRARY_FLAG}${libname}")
    endforeach()
  endif()
  string(REPLACE ";" " " link_libraries "${link_libraries}")

  set(linker_script "INPUT(${soname} ${link_libraries})")
  add_custom_command(TARGET "${target}" POST_BUILD
    COMMAND "${CMAKE_COMMAND}" -E remove "${symlink}"
    COMMAND "${CMAKE_COMMAND}" -E echo "${linker_script}" > "${symlink}"
    COMMENT "Generating linker script: '${linker_script}' as file ${symlink}"
    VERBATIM
  )
endfunction()
@


1.1.1.1
log
@Import libc++ 249b40b558955afe5ac2b549edcf2d7f859c8cc9
@
text
@@


1.1.1.1.2.1
log
@file DefineLinkerScript.cmake was added on branch cjep_staticlib_x on 2021-05-31 22:07:30 +0000
@
text
@d1 56
@


1.1.1.1.2.2
log
@sync with head
@
text
@a0 56
# This function defines a linker script in place of the symlink traditionally
# created for shared libraries.
#
# More specifically, this function goes through the PUBLIC and INTERFACE
# library dependencies of <target> and gathers them into a linker script,
# such that those libraries are linked against when the shared library for
# <target> is linked against.
#
# Arguments:
#   <target>: A target representing a shared library. A linker script will be
#             created in place of that target's TARGET_LINKER_FILE, which is
#             the symlink pointing to the actual shared library (usually
#             libFoo.so pointing to libFoo.so.1, which itself points to
#             libFoo.so.1.0).

function(define_linker_script target)
  if (NOT TARGET "${target}")
    message(FATAL_ERROR "The provided target '${target}' is not actually a target.")
  endif()

  get_target_property(target_type "${target}" TYPE)
  if (NOT "${target_type}" STREQUAL "SHARED_LIBRARY")
    message(FATAL_ERROR "The provided target '${target}' is not a shared library (its type is '${target_type}').")
  endif()

  set(symlink "$<TARGET_LINKER_FILE:${target}>")
  set(soname "$<TARGET_SONAME_FILE_NAME:${target}>")

  get_target_property(interface_libs "${target}" INTERFACE_LINK_LIBRARIES)

  set(link_libraries)
  if (interface_libs)
    foreach(lib IN LISTS interface_libs)
      if ("${lib}" STREQUAL "cxx-headers")
        continue()
      endif()
      # If ${lib} is not a target, we use a dummy target which we know will
      # have an OUTPUT_NAME property so that CMake doesn't fail when evaluating
      # the non-selected branch of the `IF`. It doesn't matter what it evaluates
      # to because it's not selected, but it must not cause an error.
      # See https://gitlab.kitware.com/cmake/cmake/-/issues/21045.
      set(output_name_tgt "$<IF:$<TARGET_EXISTS:${lib}>,${lib},${target}>")
      set(libname "$<IF:$<TARGET_EXISTS:${lib}>,$<TARGET_PROPERTY:${output_name_tgt},OUTPUT_NAME>,${lib}>")
      list(APPEND link_libraries "${CMAKE_LINK_LIBRARY_FLAG}${libname}")
    endforeach()
  endif()
  string(REPLACE ";" " " link_libraries "${link_libraries}")

  set(linker_script "INPUT(${soname} ${link_libraries})")
  add_custom_command(TARGET "${target}" POST_BUILD
    COMMAND "${CMAKE_COMMAND}" -E remove "${symlink}"
    COMMAND "${CMAKE_COMMAND}" -E echo "${linker_script}" > "${symlink}"
    COMMENT "Generating linker script: '${linker_script}' as file ${symlink}"
    VERBATIM
  )
endfunction()
@


