[XRay] Detect terminfo library
authorDean Michael Berris <dberris@google.com>
Wed, 19 Sep 2018 01:35:52 +0000 (01:35 +0000)
committerDean Michael Berris <dberris@google.com>
Wed, 19 Sep 2018 01:35:52 +0000 (01:35 +0000)
Instead of assuming `-ltinfo` works, check whether there's terminfo
support on the host where LLVMSupport is compiled.

Follow-up to D52220.

llvm-svn: 342523

compiler-rt/cmake/config-ix.cmake
compiler-rt/lib/xray/tests/CMakeLists.txt

index 1c60c3d..cffca98 100644 (file)
@@ -105,6 +105,20 @@ check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL)
 check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT)
 check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
 check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
+
+# Look for terminfo library, used in unittests that depend on LLVMSupport.
+if(LLVM_ENABLE_TERMINFO)
+  foreach(library tinfo terminfo curses ncurses ncursesw)
+    string(TOUPPER ${library} library_suffix)
+    check_library_exists(
+      ${library} setupterm "" COMPILER_RT_HAS_TERMINFO)
+    if(COMPILER_RT_HAS_TERMINFO)
+      set(COMPILER_RT_TERMINFO_LIB "${library}")
+      break()
+    endif()
+  endforeach()
+endif()
+
 if (ANDROID AND COMPILER_RT_HAS_LIBDL)
   # Android's libstdc++ has a dependency on libdl.
   list(APPEND CMAKE_REQUIRED_LIBRARIES dl)
index 6e12297..3b33f78 100644 (file)
@@ -54,6 +54,11 @@ if (NOT APPLE)
   append_list_if(COMPILER_RT_HAS_LIBRT -lrt XRAY_UNITTEST_LINK_FLAGS)
   append_list_if(COMPILER_RT_HAS_LIBDL -ldl XRAY_UNITTEST_LINK_FLAGS)
   append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread XRAY_UNITTEST_LINK_FLAGS)
+
+  # Needed by LLVMSupport.
+  append_list_if(
+    COMPILER_RT_HAS_TERMINFO
+    -l${COMPILER_RT_TERMINFO_LIB} XRAY_UNITTEST_LINK_FLAGS)
 endif()
 
 macro(add_xray_unittest testname)
@@ -75,7 +80,7 @@ macro(add_xray_unittest testname)
         DEPS gtest xray llvm-xray LLVMXRay LLVMTestingSupport
         CFLAGS ${XRAY_UNITTEST_CFLAGS}
         LINK_FLAGS ${TARGET_LINK_FLAGS} ${XRAY_UNITTEST_LINK_FLAGS}
-        -lLLVMXRay -lLLVMSupport -lLLVMTestingSupport -ltinfo
+        -lLLVMXRay -lLLVMSupport -lLLVMTestingSupport
         )
       set_target_properties(XRayUnitTests
         PROPERTIES