2011-04-29 14:27:02 +08:00
|
|
|
# Check if this is a in tree build.
|
|
|
|
if (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
|
|
|
project(Polly)
|
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
|
|
|
# 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)
|
2012-03-16 21:24:42 +08:00
|
|
|
#FileCheck is not install by default, warn the user to Copy FileCheck
|
2012-03-16 22:34:27 +08:00
|
|
|
if( NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/FileCheck
|
|
|
|
OR NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/not)
|
2014-08-18 08:40:13 +08:00
|
|
|
message(WARNING "FileCheck or not are required by running regress tests, "
|
2012-03-16 22:34:27 +08:00
|
|
|
"but they are not installed! Please copy it to "
|
|
|
|
"${LLVM_INSTALL_ROOT}/bin.")
|
|
|
|
endif(NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/FileCheck
|
|
|
|
OR NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/not)
|
2011-04-29 14:27:02 +08:00
|
|
|
# Add the llvm header path.
|
|
|
|
include_directories(${LLVM_INSTALL_ROOT}/include/)
|
2012-03-16 21:24:42 +08:00
|
|
|
|
2012-03-27 15:56:07 +08:00
|
|
|
# Get the system librarys that will link into LLVM.
|
|
|
|
function(get_system_libs return_var)
|
|
|
|
# Returns in `return_var' a list of system libraries used by LLVM.
|
|
|
|
if( NOT MSVC )
|
|
|
|
if( MINGW )
|
|
|
|
set(system_libs ${system_libs} imagehlp psapi)
|
|
|
|
elseif( CMAKE_HOST_UNIX )
|
|
|
|
if( HAVE_LIBDL )
|
|
|
|
set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
|
|
|
|
endif()
|
|
|
|
if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
|
|
|
|
set(system_libs ${system_libs} pthread)
|
|
|
|
endif()
|
|
|
|
endif( MINGW )
|
|
|
|
endif( NOT MSVC )
|
|
|
|
set(${return_var} ${system_libs} PARENT_SCOPE)
|
|
|
|
endfunction(get_system_libs)
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
# 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} )
|
|
|
|
|
2012-03-27 15:56:07 +08:00
|
|
|
# Get the TARGET_TRIPLE
|
|
|
|
execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --host-target
|
|
|
|
OUTPUT_VARIABLE TARGET_TRIPLE
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
# 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})
|
2015-02-05 05:56:28 +08:00
|
|
|
|
|
|
|
# Make sure the isl c files are built as fPIC
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
2011-04-29 14:27:02 +08:00
|
|
|
endif(NOT DEFINED LLVM_MAIN_SRC_DIR)
|
|
|
|
|
|
|
|
set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
2012-10-21 23:51:49 +08:00
|
|
|
# Add path for custom modules
|
|
|
|
set(CMAKE_MODULE_PATH
|
|
|
|
${CMAKE_MODULE_PATH}
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
|
|
)
|
|
|
|
|
|
|
|
include("polly_macros")
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
# Add appropriate flags for GCC
|
|
|
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
# FIXME: Turn off exceptions, RTTI:
|
|
|
|
# -fno-exceptions -fno-rtti
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -fno-exceptions -fno-rtti")
|
|
|
|
endif ()
|
|
|
|
|
2011-07-01 03:50:04 +08:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
|
|
|
|
|
2015-02-05 04:55:43 +08:00
|
|
|
# Define the FLAGS for the compilation of isl and imath
|
|
|
|
#
|
|
|
|
# Those are the only C files we have in the repository. Hence, we can just use
|
|
|
|
# the CFLAGS to identify them.
|
|
|
|
#
|
|
|
|
# We first set the visibility of all isl functions to hidden to ensure we do
|
|
|
|
# not clash with other isl versions that got linked into a program that uses
|
|
|
|
# Polly. (This happens e.g when linking Polly with dragonegg)
|
|
|
|
#
|
|
|
|
# We also disable all warnings, as these should be fixed upstream. There is
|
|
|
|
# no value in reporting them here.
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -w")
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
# Add path for custom modules
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
|
|
|
|
|
2014-02-22 21:28:31 +08:00
|
|
|
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
|
|
|
2012-08-03 20:50:07 +08:00
|
|
|
option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
|
|
|
|
if (POLLY_ENABLE_GPGPU_CODEGEN)
|
|
|
|
# Do not require CUDA, as GPU code generation test cases can be run without
|
|
|
|
# a cuda library.
|
|
|
|
FIND_PACKAGE(CUDA)
|
|
|
|
set(GPU_CODEGEN TRUE)
|
|
|
|
endif(POLLY_ENABLE_GPGPU_CODEGEN)
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
INCLUDE_DIRECTORIES( ${ISL_INCLUDE_DIR} )
|
2014-02-22 10:15:39 +08:00
|
|
|
if (GMP_FOUND)
|
|
|
|
INCLUDE_DIRECTORIES( ${GMP_INCLUDE_DIR} )
|
|
|
|
endif(GMP_FOUND)
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2012-06-06 20:16:10 +08:00
|
|
|
# Support GPGPU code generation if the library is available.
|
|
|
|
if (CUDALIB_FOUND)
|
|
|
|
INCLUDE_DIRECTORIES( ${CUDALIB_INCLUDE_DIR} )
|
|
|
|
endif(CUDALIB_FOUND)
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
include_directories(
|
2014-05-29 00:54:42 +08:00
|
|
|
BEFORE
|
2011-04-29 14:27:02 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/JSON/include
|
2015-02-05 04:55:43 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/imath
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl
|
2011-04-29 14:27:02 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
|
|
|
)
|
|
|
|
|
2013-01-19 22:17:52 +08:00
|
|
|
install(DIRECTORY include/
|
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.h"
|
|
|
|
PATTERN ".svn" EXCLUDE
|
|
|
|
)
|
|
|
|
|
|
|
|
install(DIRECTORY ${POLLY_BINARY_DIR}/include/
|
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.h"
|
|
|
|
PATTERN "CMakeFiles" EXCLUDE
|
2011-04-29 14:27:02 +08:00
|
|
|
PATTERN ".svn" EXCLUDE
|
|
|
|
)
|
|
|
|
|
|
|
|
add_definitions( -D_GNU_SOURCE )
|
|
|
|
|
|
|
|
add_subdirectory(include)
|
|
|
|
add_subdirectory(lib)
|
|
|
|
add_subdirectory(test)
|
|
|
|
add_subdirectory(tools)
|
|
|
|
# TODO: docs.
|
|
|
|
|
|
|
|
|
|
|
|
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
|
|
|
|
${POLLY_BINARY_DIR}/include/polly/Config/config.h )
|
|
|
|
|
2013-02-15 00:19:16 +08:00
|
|
|
# Add target to check formatting of polly files
|
|
|
|
file( GLOB_RECURSE files *.h *.cpp)
|
2013-03-23 09:04:48 +08:00
|
|
|
file( GLOB_RECURSE jsonfiles lib/JSON/*.h lib/JSON/*.cpp)
|
2015-02-05 04:55:43 +08:00
|
|
|
file( GLOB_RECURSE islfiles lib/External/isl/*.h lib/External/isl/*.c
|
|
|
|
lib/External/isl/include/isl/*.h lib/External/isl/imath/*.h
|
|
|
|
lib/External/isl/imath/*.c)
|
|
|
|
list( REMOVE_ITEM files ${jsonfiles} ${islfiles})
|
2013-02-15 00:19:16 +08:00
|
|
|
add_custom_command( OUTPUT formatting COMMAND
|
2013-11-23 06:42:13 +08:00
|
|
|
CLANG_FORMAT=${LLVM_BINARY_DIR}/bin/clang-format
|
2013-02-15 00:19:16 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/utils/check_format.sh ${files})
|
2013-02-15 00:42:50 +08:00
|
|
|
add_custom_target(polly-check-format DEPENDS formatting)
|
2013-05-07 15:30:31 +08:00
|
|
|
add_custom_command( OUTPUT formatting-update COMMAND
|
2013-11-23 06:42:13 +08:00
|
|
|
CLANG_FORMAT=${LLVM_BINARY_DIR}/bin/clang-format
|
2013-05-07 15:30:31 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/utils/update_format.sh ${files})
|
|
|
|
add_custom_target(polly-update-format DEPENDS formatting-update)
|
2014-03-14 04:24:48 +08:00
|
|
|
|
|
|
|
# Set the variable POLLY_LINK_LIBS in the llvm/tools/ dir.
|
|
|
|
set(POLLY_LINK_LIBS ${POLLY_LINK_LIBS} PARENT_SCOPE)
|