xref: /llvm-project/cmake/Modules/GetDarwinLinkerVersion.cmake (revision 3bc71c2abfa00413fd15cf0e5c08af6ec0d4768b)
1*3bc71c2aSUsama Hameed# Get the linker version on Darwin
2*3bc71c2aSUsama Hameedfunction(get_darwin_linker_version variable)
3*3bc71c2aSUsama Hameed  set(LINK_VERSION)
4*3bc71c2aSUsama Hameed  set(LD_V_OUTPUT)
5*3bc71c2aSUsama Hameed  execute_process(
6*3bc71c2aSUsama Hameed    COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
7*3bc71c2aSUsama Hameed    RESULT_VARIABLE HAD_ERROR
8*3bc71c2aSUsama Hameed    OUTPUT_VARIABLE LD_V_OUTPUT
9*3bc71c2aSUsama Hameed    )
10*3bc71c2aSUsama Hameed  if (HAD_ERROR)
11*3bc71c2aSUsama Hameed    message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
12*3bc71c2aSUsama Hameed  endif()
13*3bc71c2aSUsama Hameed  if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
14*3bc71c2aSUsama Hameed    string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" LINK_VERSION ${LD_V_OUTPUT})
15*3bc71c2aSUsama Hameed  elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
16*3bc71c2aSUsama Hameed    string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" LINK_VERSION ${LD_V_OUTPUT})
17*3bc71c2aSUsama Hameed  endif()
18*3bc71c2aSUsama Hameed  set(${variable} ${LINK_VERSION} PARENT_SCOPE)
19*3bc71c2aSUsama Hameedendfunction()
20