[polly] r301095 - [CMake] Fix unittests in out-of-LLVM-tree builds.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 22 16:02:46 PDT 2017


Author: meinersbur
Date: Sat Apr 22 18:02:46 2017
New Revision: 301095

URL: http://llvm.org/viewvc/llvm-project?rev=301095&view=rev
Log:
[CMake] Fix unittests in out-of-LLVM-tree builds.

Unittests are linked against a subset of LLVM libraries and its
transitive dependencies resolved by CMake. The information about indirect
library dependency is not available when building separately from
LLVM, which result in missing symbol errors while linking.

Resolve this issue by querying llvm-config about the available
LLVM libraries and link against all of them, since dependence
information is still not available.

Modified:
    polly/trunk/CMakeLists.txt
    polly/trunk/unittests/CMakeLists.txt

Modified: polly/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/CMakeLists.txt?rev=301095&r1=301094&r2=301095&view=diff
==============================================================================
--- polly/trunk/CMakeLists.txt (original)
+++ polly/trunk/CMakeLists.txt Sat Apr 22 18:02:46 2017
@@ -20,6 +20,11 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR)
   # Add the llvm header path.
   include_directories(${LLVM_INSTALL_ROOT}/include/)
 
+  # Get LLVM's own libraries.
+  execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --libs
+                  OUTPUT_VARIABLE LLVM_LIBS
+                  OUTPUT_STRIP_TRAILING_WHITESPACE)
+
   # Get the system librarys that will link into LLVM.
   execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --system-libs
                   OUTPUT_VARIABLE LLVM_SYSTEM_LIBS

Modified: polly/trunk/unittests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/unittests/CMakeLists.txt?rev=301095&r1=301094&r2=301095&view=diff
==============================================================================
--- polly/trunk/unittests/CMakeLists.txt (original)
+++ polly/trunk/unittests/CMakeLists.txt Sat Apr 22 18:02:46 2017
@@ -7,27 +7,27 @@ set_target_properties(PollyUnitTests PRO
 function(add_polly_unittest test_name)
   if(COMMAND add_unittest)
     add_unittest(PollyUnitTests ${test_name} ${ARGN})
+    target_link_libraries(${test_name} Polly)
+
+    # The Polly target does not depend on its required libraries, except:
+    # - BUILD_SHARED_LIBS=ON
+    #     in which case calling target_link_libraries again is redundant.
+    # - LLVM_LINK_LLVM_DYLIB=ON
+    #     in which case it depends on libLLVM.so, so no additional libs needed.
+    #     We are also not allowed to link against the plain LLVM* libraries,
+    #     which would result in multiple instances of these to be loaded.
+    if (NOT LLVM_LINK_LLVM_DYLIB)
+      target_link_libraries(${test_name} LLVMCore LLVMSupport LLVMDemangle LLVMipo)
+    endif ()
   else()
     add_executable(${test_name} EXCLUDE_FROM_ALL ${ARGN})
     set_target_properties(${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 
-    target_link_libraries(${test_name} gtest_main gtest)
+    target_link_libraries(${test_name} gtest_main gtest Polly ${LLVM_LIBS})
     add_dependencies(PollyUnitTests ${test_name})
 
     set_property(TARGET ${test_name} PROPERTY FOLDER "Polly")
   endif()
-  target_link_libraries(${test_name} Polly)
-
-  # The Polly target does not depend on its required libraries, except:
-  # - BUILD_SHARED_LIBS=ON
-  #     in which case calling target_link_libraries again is redundant.
-  # - LLVM_LINK_LLVM_DYLIB=ON
-  #     in which case it depends on libLLVM.so, so no additional libs needed.
-  #     We are also not allowed to link against the plain LLVM* libraries,
-  #     which would result in multiple instances of these to be loaded.
-  if (NOT LLVM_LINK_LLVM_DYLIB)
-    target_link_libraries(${test_name} LLVMCore LLVMSupport LLVMDemangle LLVMipo)
-  endif ()
 endfunction()
 
 add_subdirectory(Isl)




More information about the llvm-commits mailing list