[Polly][CMake] Use the CMake Package instead of llvm-config in out-of-tree builds
Summary: As of now, Polly uses llvm-config to set up LLVM dependencies in an out-of-tree build. This is problematic for two reasons: 1) Right now, in-tree and out-of-tree builds in fact do different things. E.g., in an in-tree build, libPolly depends on a handful of LLVM libraries, while in an out-of-tree build it depends on all of them. This means that we often need to treat both paths seperately. 2) I'm specifically unhappy with the way libPolly is linked right now, because it just blindly links against all the LLVM libs. That doesn't make a lot of sense. For instance, one of these libs is LLVMTableGen, which contains a command line definition of a -o option. This means that I can not link an out-of-tree libPolly into a tool which might want to offer a -o option as well. This patch (mostly) drop the use of llvm-config in favor of LLVMs exported cmake package. However, building Polly with unittests requires access to the gtest sources (in the LLVM source tree). If we're building against an LLVM installation, this source tree is unavailable and must specified. I'm using llvm-config to provide a default in this case. Reviewers: Meinersbur, grosser Reviewed By: grosser Subscribers: tstellar, bollu, chapuni, mgorny, pollydev, llvm-commits Differential Revision: https://reviews.llvm.org/D33299 llvm-svn: 307650
This commit is contained in:
parent
b4d500f1fb
commit
d99c406e3d
@ -4,93 +4,37 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
||||
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 )
|
||||
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.")
|
||||
endif()
|
||||
find_package(LLVM CONFIG REQUIRED)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
|
||||
include(HandleLLVMOptions)
|
||||
include(AddLLVM)
|
||||
|
||||
# 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
|
||||
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_TOOLS_BINARY_DIR}/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)
|
||||
# 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
|
||||
@ -111,6 +55,7 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
||||
|
||||
set(POLLY_GTEST_AVAIL 1)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Make sure the isl c files are built as fPIC
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||
|
@ -1,9 +1,4 @@
|
||||
# Keep this in sync with llvm/cmake/CMakeLists.txt!
|
||||
if (LLVM_INSTALL_ROOT)
|
||||
# this simplifies things down the road, by not requiring to distinguish
|
||||
# between in-tree and out of tree builds
|
||||
set(LLVM_BINARY_DIR ${LLVM_INSTALL_ROOT})
|
||||
endif()
|
||||
|
||||
set(LLVM_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
|
||||
set(POLLY_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/polly")
|
||||
|
@ -79,15 +79,6 @@ if (GPU_CODEGEN)
|
||||
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)
|
||||
@ -125,14 +116,6 @@ if (DEFINED LLVM_MAIN_SRC_DIR)
|
||||
LLVMVectorize
|
||||
)
|
||||
endif ()
|
||||
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}
|
||||
)
|
||||
endif ()
|
||||
|
||||
# Create a loadable module Polly.so that can be loaded using
|
||||
# LLVM's/clang's "-load" option.
|
||||
|
@ -1,104 +1,41 @@
|
||||
set(POLLY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
set(POLLY_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/..")
|
||||
set(LLVM_SHLIBEXT "${CMAKE_SHARED_MODULE_SUFFIX}")
|
||||
|
||||
add_custom_target(check-polly)
|
||||
set_target_properties(check-polly PROPERTIES FOLDER "Polly")
|
||||
|
||||
if (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
||||
|
||||
# We are building polly out of tree, adjust the settings.
|
||||
# FIXME: FileCheck is not available in llvm install directory at the moment.
|
||||
set(LLVM_LIT ${LLVM_INSTALL_ROOT}/bin/llvm-lit)
|
||||
if (POLLY_BUNDLED_ISL)
|
||||
set(POLLY_TEST_DEPS LLVMPolly polly-isl-test)
|
||||
endif (POLLY_BUNDLED_ISL)
|
||||
if (POLLY_GTEST_AVAIL)
|
||||
list(APPEND POLLY_TEST_DEPS PollyUnitTests)
|
||||
if(NOT LLVM_MAIN_SRC_DIR)
|
||||
find_program(LLVM_OPT NAMES opt HINTS ${LLVM_TOOLS_BINARY_DIR})
|
||||
find_program(LLVM_FILECHECK NAMES FileCheck HINTS ${LLVM_TOOLS_BINARY_DIR})
|
||||
find_program(LLVM_NOT NAMES not HINTS ${LLVM_TOOLS_BINARY_DIR})
|
||||
if (NOT LLVM_OPT)
|
||||
message(WARNING "LLVM's opt program could not be found. Please set LLVM_OPT.")
|
||||
endif()
|
||||
|
||||
set(LLVM_BINARY_DIR "${LLVM_INSTALL_ROOT}")
|
||||
set(LLVM_TOOLS_DIR "${LLVM_INSTALL_ROOT}/bin")
|
||||
set(LLVM_LIBS_DIR "${LLVM_INSTALL_ROOT}/lib")
|
||||
set(POLLY_LIB_DIR "${POLLY_BINARY_DIR}/lib")
|
||||
|
||||
include(FindPythonInterp)
|
||||
if(PYTHONINTERP_FOUND)
|
||||
option(POLLY_TEST_DISABLE_BAR "Run Polly tests with --no-progress-bar" OFF)
|
||||
set(POLLY_TEST_EXTRA_ARGS)
|
||||
if (MSVC OR XCODE OR POLLY_TEST_DISABLE_BAR)
|
||||
set(POLLY_TEST_EXTRA_ARGS "--no-progress-bar")
|
||||
if (NOT LLVM_FILECHECK)
|
||||
message(WARNING "LLVM's FileCheck program could not be found. "
|
||||
"Please set LLVM_FILECHECK. Please set LLVM_FILECHECK.")
|
||||
endif()
|
||||
|
||||
option(POLLY_TEST_USE_VG "Run Polly tests under Valgrind" OFF)
|
||||
if(POLLY_TEST_USE_VG)
|
||||
set(POLLY_TEST_EXTRA_ARGS ${POLLY_TEST_EXTRA_ARGS} "--vg")
|
||||
if (NOT LLVM_NOT)
|
||||
message(WARNING "LLVM's not program could not be found. Please set LLVM_NOT.")
|
||||
endif()
|
||||
get_filename_component(EXTRA_PATHS ${LLVM_OPT} DIRECTORY)
|
||||
list(APPEND POLLY_TEST_EXTRA_PATHS "${EXTRA_PATHS}")
|
||||
get_filename_component(EXTRA_PATHS ${LLVM_FILECHECK} DIRECTORY)
|
||||
list(APPEND POLLY_TEST_EXTRA_PATHS "${EXTRA_PATHS}")
|
||||
get_filename_component(EXTRA_PATHS ${LLVM_NOT} DIRECTORY)
|
||||
list(APPEND POLLY_TEST_EXTRA_PATHS "${EXTRA_PATHS}")
|
||||
list(REMOVE_DUPLICATES POLLY_TEST_EXTRA_PATHS)
|
||||
message(STATUS "Extra paths: ${POLLY_TEST_EXTRA_PATHS}")
|
||||
if ("${POLLY_TEST_EXTRA_PATHS}" STREQUAL "${LLVM_TOOLS_BINARY_DIR}")
|
||||
set(POLLY_TEST_EXTRA_PATHS "")
|
||||
endif()
|
||||
|
||||
# Parameters required for lit.site.cfg.in
|
||||
set(LLVM_SOURCE_DIR ${LLVM_SOURCE_ROOT})
|
||||
if (CMAKE_CFG_INTDIR STREQUAL ".")
|
||||
set(LLVM_BUILD_MODE ".")
|
||||
else ()
|
||||
set(LLVM_BUILD_MODE "%(build_mode)s")
|
||||
endif ()
|
||||
set(ENABLE_SHARED "1")
|
||||
set(SHLIBDIR "${LLVM_BINARY_DIR}/bin")
|
||||
set(LINK_POLLY_INTO_TOOLS "OFF")
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
|
||||
|
||||
add_custom_target(check-polly-tests
|
||||
COMMAND ${LLVM_LIT}
|
||||
--param polly_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
|
||||
--param polly_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
|
||||
--param build_config=${CMAKE_CFG_INTDIR}
|
||||
-sv ${POLLY_TEST_EXTRA_ARGS}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS ${POLLY_TEST_DEPS}
|
||||
COMMENT "Running Polly regression/unit tests")
|
||||
set_target_properties(check-polly-tests PROPERTIES FOLDER "Polly")
|
||||
add_dependencies(check-polly check-polly-tests)
|
||||
|
||||
if (POLLY_GTEST_AVAIL)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg)
|
||||
|
||||
add_custom_target(check-polly-unittests
|
||||
COMMAND ${LLVM_LIT}
|
||||
--param polly_site_config=${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
|
||||
--param build_config=${CMAKE_CFG_INTDIR}
|
||||
-sv ${POLLY_TEST_EXTRA_ARGS}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/Unit
|
||||
DEPENDS PollyUnitTests
|
||||
COMMENT "Running Polly unit tests")
|
||||
set_target_properties(check-polly-unittests PROPERTIES FOLDER "Polly")
|
||||
endif ()
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UnitIsl/lit.site.cfg.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg)
|
||||
|
||||
|
||||
if (POLLY_BUNDLED_ISL)
|
||||
add_custom_target(check-polly-isl
|
||||
command ${LLVM_LIT}
|
||||
--param polly_site_config=${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg
|
||||
--param build_config=${CMAKE_CFG_INTDIR}
|
||||
-sv ${POLLY_TEST_EXTRA_ARGS}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS polly-isl-test
|
||||
COMMENT "Running isl unit tests")
|
||||
set_target_properties(check-polly-isl PROPERTIES FOLDER "Polly")
|
||||
endif (POLLY_BUNDLED_ISL)
|
||||
set(LLVM_OPT "${LLVM_TOOLS_BINARY_DIR}/opt")
|
||||
set(LLVM_FILECHECK "${LLVM_TOOLS_BINARY_DIR}/FileCheck")
|
||||
set(LLVM_NOT "${LLVM_TOOLS_BINARY_DIR}/not")
|
||||
set(POLLY_TEST_EXTRA_PATHS "")
|
||||
endif()
|
||||
|
||||
else (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
||||
|
||||
set(LLVM_LIT ${LLVM_TOOLS_BINARY_DIR}/llvm-lit)
|
||||
set(POLLY_TEST_DEPS llvm-config opt LLVMPolly FileCheck not)
|
||||
set(POLLY_TEST_DEPS LLVMPolly)
|
||||
if (POLLY_BUNDLED_ISL)
|
||||
list(APPEND POLLY_TEST_DEPS polly-isl-test)
|
||||
endif()
|
||||
@ -109,7 +46,7 @@ else (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
||||
set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}")
|
||||
set(LLVM_TOOLS_DIR "${LLVM_TOOLS_BINARY_DIR}")
|
||||
set(LLVM_LIBS_DIR "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
|
||||
set(POLLY_LIB_DIR "${LLVM_LIBS_DIR}")
|
||||
set(POLLY_LIB_DIR "${POLLY_BINARY_DIR}/lib")
|
||||
|
||||
configure_lit_site_cfg(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
|
||||
@ -164,15 +101,9 @@ else (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
||||
add_dependencies(check-polly polly-check-format)
|
||||
endif ()
|
||||
|
||||
endif (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/update_check.py
|
||||
${CMAKE_CURRENT_BINARY_DIR}/update_check.py)
|
||||
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/update_check.py
|
||||
DESTINATION ${LLVM_TOOLS_DIR}
|
||||
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
|
||||
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
|
||||
# Add a legacy target spelling: polly-test
|
||||
add_custom_target(polly-test)
|
||||
|
@ -39,7 +39,9 @@ if polly_obj_root is not None:
|
||||
llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
|
||||
if not llvm_tools_dir:
|
||||
lit_config.fatal('No LLVM tools dir set!')
|
||||
path = os.path.pathsep.join((llvm_tools_dir, config.environment['PATH']))
|
||||
extra_paths = getattr(config, 'extra_paths', [])
|
||||
base_paths = [llvm_tools_dir, config.environment['PATH']]
|
||||
path = os.path.pathsep.join(base_paths + extra_paths)
|
||||
config.environment['PATH'] = path
|
||||
|
||||
llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
|
||||
|
@ -10,6 +10,7 @@ config.target_triple = "@TARGET_TRIPLE@"
|
||||
config.enable_gpgpu_codegen = "@GPU_CODEGEN@"
|
||||
config.link_polly_into_tools = "@LINK_POLLY_INTO_TOOLS@"
|
||||
config.targets_to_build = "@TARGETS_TO_BUILD@"
|
||||
config.extra_paths = "@POLLY_TEST_EXTRA_PATHS@".split(";")
|
||||
|
||||
## Check the current platform with regex
|
||||
import re
|
||||
|
Loading…
x
Reference in New Issue
Block a user