Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -4,112 +4,64 @@ cmake_minimum_required(VERSION 3.4.3) # Where is LLVM installed? - set(LLVM_INSTALL_ROOT "" CACHE PATH "Root of LLVM install.") - # Check if the LLVM_INSTALL_ROOT valid. - if( NOT EXISTS ${LLVM_INSTALL_ROOT}/include/llvm ) - message(FATAL_ERROR "LLVM_INSTALL_ROOT (${LLVM_INSTALL_ROOT}) is not a valid LLVM installation.") - endif(NOT EXISTS ${LLVM_INSTALL_ROOT}/include/llvm) - # FileCheck, not and llvm-lit are not install by default, warn the user to copy them. - if( NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/FileCheck - OR NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/not - OR NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/llvm-lit ) + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) + include(HandleLLVMOptions) + include(AddLLVM) + + if( NOT EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck + OR NOT EXISTS ${LLVM_TOOLS_BINARY_DIR}/not + OR NOT EXISTS ${LLVM_TOOLS_BINARY_DIR}/llvm-lit ) message(WARNING "'FileCheck', 'not' and 'llvm-lit' are required by running regress tests, " "but they are not installed! Please copy them to " - "${LLVM_INSTALL_ROOT}/bin.") + "${LLVM_TOOLS_BINARY_DIR}.") endif() # 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 - OUTPUT_STRIP_TRAILING_WHITESPACE) - message(STATUS "System libs required by LLVM: ${LLVM_SYSTEM_LIBS}") - - # Determine where LLVM stores its libraries. - execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --libdir - OUTPUT_VARIABLE LLVM_LIBRARY_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) - link_directories("${LLVM_LIBRARY_DIR}") - - # Now set the header paths. - execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --includedir - OUTPUT_VARIABLE LLVM_INCLUDE_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) - include_directories( ${LLVM_INCLUDE_DIR} ) - - # Get the TARGET_TRIPLE - execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --host-target - OUTPUT_VARIABLE TARGET_TRIPLE - OUTPUT_STRIP_TRAILING_WHITESPACE) - - # And then set the cxx flags. - execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --cxxflags - OUTPUT_VARIABLE LLVM_CXX_FLAGS - OUTPUT_STRIP_TRAILING_WHITESPACE) - set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS}) - - # Check LLVM_ENABLE_ASSERTIONS - execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --assertion-mode - OUTPUT_VARIABLE LLVM_ENABLE_ASSERTIONS - OUTPUT_STRIP_TRAILING_WHITESPACE) - # Copied from LLVM's HandleLLVMOptions.cmake - if( LLVM_ENABLE_ASSERTIONS ) - # MSVC doesn't like _DEBUG on release builds. See PR 4379. - if( NOT MSVC ) - add_definitions( -D_DEBUG ) - endif() - # On non-Debug builds cmake automatically defines NDEBUG, so we - # explicitly undefine it: - if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) - add_definitions( -UNDEBUG ) - # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines. - foreach (flags_var_to_scrub - CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS_MINSIZEREL - CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_C_FLAGS_MINSIZEREL) - string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " - "${flags_var_to_scrub}" "${${flags_var_to_scrub}}") - endforeach() - endif() - endif() + include_directories(${LLVM_INCLUDE_DIRS}) # Sources available, too? - execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --src-root - OUTPUT_VARIABLE MAIN_SRC_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) - set(LLVM_SOURCE_ROOT ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree") + if (LLVM_BUILD_MAIN_SRC_DIR) + set(LLVM_SOURCE_ROOT ${LLVM_BUILD_MAIN_SRC_DIR} CACHE PATH + "Path to LLVM source tree") + else() + execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --src-root + OUTPUT_VARIABLE MAIN_SRC_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + set(LLVM_SOURCE_ROOT ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree") + endif() # Enable unit tests if available. set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest) if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h) - add_library(gtest - ${UNITTEST_DIR}/googletest/src/gtest-all.cc - ${UNITTEST_DIR}/googlemock/src/gmock-all.cc - ) - target_include_directories(gtest - PUBLIC - "${UNITTEST_DIR}/googletest/include" - "${UNITTEST_DIR}/googlemock/include" - - PRIVATE - "${UNITTEST_DIR}/googletest" - "${UNITTEST_DIR}/googlemock" - ) - target_link_libraries(gtest -lpthread) - - add_library(gtest_main ${UNITTEST_DIR}/UnitTestMain/TestMain.cpp) - target_link_libraries(gtest_main gtest) - - set(POLLY_GTEST_AVAIL 1) + # The build tree already exports the gtest target, which we can reuse + if (TARGET gtest) + # LLVM Doesn't export gtest's include directorys, so do that here + set_target_properties(gtest + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${UNITTEST_DIR}/googletest/include;${UNITTEST_DIR}/googlemock/include" + ) + set(POLLY_GTEST_AVAIL 1) + else() + add_library(gtest + ${UNITTEST_DIR}/googletest/src/gtest-all.cc + ${UNITTEST_DIR}/googlemock/src/gmock-all.cc + ) + target_include_directories(gtest + PUBLIC + "${UNITTEST_DIR}/googletest/include" + "${UNITTEST_DIR}/googlemock/include" + + PRIVATE + "${UNITTEST_DIR}/googletest" + "${UNITTEST_DIR}/googlemock" + ) + target_link_libraries(gtest -lpthread) + + add_library(gtest_main ${UNITTEST_DIR}/UnitTestMain/TestMain.cpp) + target_link_libraries(gtest_main gtest) + + set(POLLY_GTEST_AVAIL 1) + endif() endif() # Make sure the isl c files are built as fPIC Index: lib/CMakeLists.txt =================================================================== --- lib/CMakeLists.txt +++ lib/CMakeLists.txt @@ -79,58 +79,41 @@ target_link_libraries(Polly PollyPPCG) endif () -# Add Polly's LLVM dependencies. -# When built inside the LLVM source tree, these are CMake targets that will -# depend on their dependencies and CMake ensures they are added in the right -# order. -# If Polly is built independently, just add all LLVM libraries. LLVM_ROOT_DIR -# might have been configured to compile to individual libraries or a single -# libLLVM.so (called dylib), reported by llvm-config, so there is no fixed list -# of required libraries. -if (DEFINED LLVM_MAIN_SRC_DIR) - # Polly-ACC requires the NVPTX backend to work. Ask LLVM about its libraries. - set(nvptx_libs) - if (GPU_CODEGEN) - # This call emits an error if they NVPTX backend is not enable. - llvm_map_components_to_libnames(nvptx_libs NVPTX) - endif () +# Polly-ACC requires the NVPTX backend to work. Ask LLVM about its libraries. +set(nvptx_libs) +if (GPU_CODEGEN) + # This call emits an error if they NVPTX backend is not enable. + llvm_map_components_to_libnames(nvptx_libs NVPTX) +endif () - if (LLVM_LINK_LLVM_DYLIB) - # The shlib/dylib contains all the LLVM components - # (including NVPTX is enabled) already. Adding them to target_link_libraries - # would cause them being twice in the address space - # (their LLVM*.a/so and their copies in libLLVM.so) - # which results in errors when the two instances try to register the same - # command-line switches. - target_link_libraries(Polly LLVM) - else () - target_link_libraries(Polly - LLVMSupport - LLVMCore - LLVMScalarOpts - LLVMInstCombine - LLVMTransformUtils - LLVMAnalysis - LLVMipo - LLVMMC - ${nvptx_libs} -# The libraries below are required for darwin: http://PR26392 - LLVMBitReader - LLVMMCParser - LLVMObject - LLVMProfileData - LLVMTarget - LLVMVectorize - ) - endif () +if (LLVM_LINK_LLVM_DYLIB) + # The shlib/dylib contains all the LLVM components + # (including NVPTX is enabled) already. Adding them to target_link_libraries + # would cause them being twice in the address space + # (their LLVM*.a/so and their copies in libLLVM.so) + # which results in errors when the two instances try to register the same + # command-line switches. + target_link_libraries(Polly LLVM) else () - # When Polly-ACC is enabled, we assume that the host LLVM was also built with - # the NVPTX target enabled. target_link_libraries(Polly - ${LLVM_LIBS} - ${LLVM_SYSTEM_LIBS} - ) + LLVMSupport + LLVMCore + LLVMScalarOpts + LLVMInstCombine + LLVMTransformUtils + LLVMAnalysis + LLVMipo + LLVMMC + ${nvptx_libs} + # The libraries below are required for darwin: http://PR26392 + LLVMBitReader + LLVMMCParser + LLVMObject + LLVMProfileData + LLVMTarget + LLVMVectorize + ) endif () # Create a loadable module Polly.so that can be loaded using