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)
|
2016-08-25 18:35:22 +08:00
|
|
|
# FileCheck, not and llvm-lit are not install by default, warn the user to copy them.
|
2012-03-16 22:34:27 +08:00
|
|
|
if( NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/FileCheck
|
2016-08-25 18:35:22 +08:00
|
|
|
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 "
|
2012-03-16 22:34:27 +08:00
|
|
|
"${LLVM_INSTALL_ROOT}/bin.")
|
2016-08-25 18:35:22 +08:00
|
|
|
endif()
|
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.
|
2016-08-25 22:58:29 +08:00
|
|
|
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}")
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2016-08-25 22:43:04 +08:00
|
|
|
# Determine where LLVM stores its libraries.
|
2016-08-25 19:28:52 +08:00
|
|
|
execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --libdir
|
|
|
|
OUTPUT_VARIABLE LLVM_LIBRARY_DIR
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
link_directories("${LLVM_LIBRARY_DIR}")
|
|
|
|
|
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
|
|
|
|
2015-09-12 04:47:14 +08:00
|
|
|
# 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()
|
|
|
|
|
2016-08-25 20:36:15 +08:00
|
|
|
# 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")
|
|
|
|
|
|
|
|
# Enable unit tests if available.
|
|
|
|
set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest)
|
|
|
|
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
|
2017-01-11 09:07:37 +08:00
|
|
|
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"
|
|
|
|
)
|
2016-08-25 22:58:29 +08:00
|
|
|
target_link_libraries(gtest ${LLVM_SYSTEM_LIBS})
|
2016-08-25 20:36:15 +08:00
|
|
|
|
|
|
|
add_library(gtest_main ${UNITTEST_DIR}/UnitTestMain/TestMain.cpp)
|
|
|
|
target_link_libraries(gtest_main gtest)
|
|
|
|
|
|
|
|
set(POLLY_GTEST_AVAIL 1)
|
|
|
|
endif()
|
|
|
|
|
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")
|
2016-08-25 20:36:15 +08:00
|
|
|
else ()
|
|
|
|
set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
|
|
|
|
set(POLLY_GTEST_AVAIL 1)
|
|
|
|
endif ()
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
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")
|
2015-07-21 20:22:36 +08:00
|
|
|
elseif (MSVC)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
|
|
|
|
add_definitions("-D_HAS_EXCEPTIONS=0")
|
|
|
|
else ()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
|
2011-04-29 14:27:02 +08:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
# 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)
|
2016-07-14 18:22:19 +08:00
|
|
|
else(POLLY_ENABLE_GPGPU_CODEGEN)
|
|
|
|
set(GPU_CODEGEN FALSE)
|
2012-08-03 20:50:07 +08:00
|
|
|
endif(POLLY_ENABLE_GPGPU_CODEGEN)
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2016-07-14 18:22:19 +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-06-26 00:50:13 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
|
2015-02-05 04:55:43 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
|
2016-07-14 18:22:19 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
|
2016-07-15 15:50:36 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External
|
2011-04-29 14:27:02 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
|
|
|
)
|
|
|
|
|
2016-06-22 02:14:01 +08:00
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
|
|
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
|
|
|
|
PATTERN ".svn" EXCLUDE
|
|
|
|
)
|
|
|
|
endif()
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
add_definitions( -D_GNU_SOURCE )
|
|
|
|
|
2016-02-04 15:16:36 +08:00
|
|
|
add_subdirectory(docs)
|
2011-04-29 14:27:02 +08:00
|
|
|
add_subdirectory(lib)
|
|
|
|
add_subdirectory(test)
|
2016-08-25 20:36:15 +08:00
|
|
|
if (POLLY_GTEST_AVAIL)
|
|
|
|
add_subdirectory(unittests)
|
|
|
|
endif ()
|
2011-04-29 14:27:02 +08:00
|
|
|
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
|
2016-08-25 20:36:15 +08:00
|
|
|
file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
|
2013-03-23 09:04:48 +08:00
|
|
|
file( GLOB_RECURSE jsonfiles lib/JSON/*.h lib/JSON/*.cpp)
|
2016-07-05 23:26:33 +08:00
|
|
|
file( GLOB_RECURSE external lib/External/*.h lib/External/*.c)
|
|
|
|
list( REMOVE_ITEM files ${jsonfiles} ${external})
|
2015-09-15 00:59:50 +08:00
|
|
|
|
|
|
|
set(check_format_depends)
|
|
|
|
set(update_format_depends)
|
|
|
|
set(i 0)
|
|
|
|
foreach (file IN LISTS files)
|
|
|
|
add_custom_command(OUTPUT polly-check-format${i}
|
2015-10-15 20:18:37 +08:00
|
|
|
COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
|
2015-09-15 00:59:50 +08:00
|
|
|
VERBATIM
|
|
|
|
COMMENT "Checking format of ${file}..."
|
|
|
|
)
|
|
|
|
list(APPEND check_format_depends "polly-check-format${i}")
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT polly-update-format${i}
|
2015-10-15 20:18:37 +08:00
|
|
|
COMMAND clang-format -sort-includes -i -style=llvm ${file}
|
2015-09-15 00:59:50 +08:00
|
|
|
VERBATIM
|
|
|
|
COMMENT "Updating format of ${file}..."
|
|
|
|
)
|
|
|
|
list(APPEND update_format_depends "polly-update-format${i}")
|
|
|
|
|
|
|
|
math(EXPR i ${i}+1)
|
|
|
|
endforeach ()
|
|
|
|
|
|
|
|
add_custom_target(polly-check-format DEPENDS ${check_format_depends})
|
2015-07-21 20:40:01 +08:00
|
|
|
set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
|
2015-09-15 00:59:50 +08:00
|
|
|
|
|
|
|
add_custom_target(polly-update-format DEPENDS ${update_format_depends})
|
2015-07-21 20:40:01 +08:00
|
|
|
set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")
|
2014-03-14 04:24:48 +08:00
|
|
|
|