[libcxx-commits] [libcxx] d275da1 - [libc++] Fix eager generator expression in DefineLinkerScript

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 31 08:21:06 PDT 2020


Author: Louis Dionne
Date: 2020-07-31T11:20:19-04:00
New Revision: d275da17e4f0a17615b24c352aab0d34f647bfa7

URL: https://github.com/llvm/llvm-project/commit/d275da17e4f0a17615b24c352aab0d34f647bfa7
DIFF: https://github.com/llvm/llvm-project/commit/d275da17e4f0a17615b24c352aab0d34f647bfa7.diff

LOG: [libc++] Fix eager generator expression in DefineLinkerScript

As explained in https://gitlab.kitware.com/cmake/cmake/-/issues/21045,
both branches of an $<IF> generator expression are evaluated eagerly
by CMake. As a result, if the non-selected branch contains an invalid
generator expression (such as getting the OUTPUT_NAME property of a
non-existent target), a hard error will occur.

This failed builds using the cxxrt ABI library, which doesn't create
a CMake target currently.

Added: 
    

Modified: 
    libcxx/cmake/Modules/DefineLinkerScript.cmake

Removed: 
    


################################################################################
diff  --git a/libcxx/cmake/Modules/DefineLinkerScript.cmake b/libcxx/cmake/Modules/DefineLinkerScript.cmake
index 41426bf06714..be7f026af7e8 100644
--- a/libcxx/cmake/Modules/DefineLinkerScript.cmake
+++ b/libcxx/cmake/Modules/DefineLinkerScript.cmake
@@ -34,7 +34,13 @@ function(define_linker_script target)
       if ("${lib}" STREQUAL "cxx-headers")
         continue()
       endif()
-      set(libname "$<IF:$<TARGET_EXISTS:${lib}>,$<TARGET_PROPERTY:${lib},OUTPUT_NAME>,${lib}>")
+      # 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()


        


More information about the libcxx-commits mailing list