blob: d6bcc8f7f285eea7bfdbafa6260a258d5a53eb71 [file] [log] [blame]
John Ericsond3b756c2022-01-18 07:05:471include(GNUInstallDirs)
2
Tobias Grosser75805372011-04-29 06:27:023# Check if this is a in tree build.
4if (NOT DEFINED LLVM_MAIN_SRC_DIR)
5 project(Polly)
Louis Dionneafa1afd2020-04-22 15:15:056 cmake_minimum_required(VERSION 3.13.4)
Tobias Grosser75805372011-04-29 06:27:027
8 # Where is LLVM installed?
Philip Pfaffed99c4062017-07-11 11:24:259 find_package(LLVM CONFIG REQUIRED)
10 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
11 include(HandleLLVMOptions)
12 include(AddLLVM)
13
Tobias Grosser75805372011-04-29 06:27:0214 # Add the llvm header path.
Philip Pfaffed99c4062017-07-11 11:24:2515 include_directories(${LLVM_INCLUDE_DIRS})
Michael Kruse84bf8a32015-09-11 20:47:1416
Michael Kruse05cf9c22016-08-25 12:36:1517 # Sources available, too?
Philip Pfaffed99c4062017-07-11 11:24:2518 if (LLVM_BUILD_MAIN_SRC_DIR)
19 set(LLVM_SOURCE_ROOT ${LLVM_BUILD_MAIN_SRC_DIR} CACHE PATH
20 "Path to LLVM source tree")
21 else()
22 execute_process(COMMAND "${LLVM_TOOLS_BINARY_DIR}/llvm-config" --src-root
23 OUTPUT_VARIABLE MAIN_SRC_DIR
24 OUTPUT_STRIP_TRAILING_WHITESPACE)
25 set(LLVM_SOURCE_ROOT ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
26 endif()
Michael Kruse05cf9c22016-08-25 12:36:1527
28 # Enable unit tests if available.
Philip Pfaffe54df93d2017-07-11 11:37:3529 set(POLLY_GTEST_AVAIL 0)
Michael Kruse05cf9c22016-08-25 12:36:1530 set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest)
31 if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
Michał Górnyc8b629a2020-08-05 08:15:4132 if (NOT TARGET gtest)
33 add_subdirectory(${UNITTEST_DIR} utils/unittest)
Philip Pfaffed99c4062017-07-11 11:24:2534 endif()
Michał Górnyc8b629a2020-08-05 08:15:4135 set(POLLY_GTEST_AVAIL 1)
Michael Kruse05cf9c22016-08-25 12:36:1536 endif()
37
Rainer Orth26d659b2020-08-27 08:59:5138 if (LLVM_ENABLE_PIC)
39 # Make sure the isl c files are built as fPIC if possible
40 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
41 endif ()
Michael Kruseabf05b12017-04-22 23:02:5342
43 # Set directory for polly-isl-test.
44 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
Michael Kruse05cf9c22016-08-25 12:36:1545else ()
46 set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
47 set(POLLY_GTEST_AVAIL 1)
48endif ()
Tobias Grosser75805372011-04-29 06:27:0249
50set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
51set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
52
John Ericsone68215c2022-01-03 21:09:3353if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
54 set(LLVM_COMMON_CMAKE_UTILS ${POLLY_SOURCE_DIR}/../cmake)
55endif()
56
57# Make sure that our source directory is on the current cmake module path so that
58# we can include cmake files from this directory.
59list(INSERT CMAKE_MODULE_PATH 0
60 "${POLLY_SOURCE_DIR}/cmake"
61 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
Tobias Grosserbc822eb2012-10-21 15:51:4962 )
63
64include("polly_macros")
65
Tobias Grosser75805372011-04-29 06:27:0266# Add appropriate flags for GCC
67if (CMAKE_COMPILER_IS_GNUCXX)
68 # FIXME: Turn off exceptions, RTTI:
69 # -fno-exceptions -fno-rtti
70 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")
Michael Kruse441357d2015-07-21 12:22:3671elseif (MSVC)
72 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
73 add_definitions("-D_HAS_EXCEPTIONS=0")
74else ()
75 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
Tobias Grosser75805372011-04-29 06:27:0276endif ()
77
Rafael Espindolafa0841c2014-02-22 13:28:3178SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
79
Tobias Grosser6217e182012-08-03 12:50:0780option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
Philip Pfaffe4d240932018-06-07 21:10:4981set(GPU_CODEGEN FALSE)
Tobias Grosser6217e182012-08-03 12:50:0782if (POLLY_ENABLE_GPGPU_CODEGEN)
Siddharth Bhat17f01962017-05-07 21:03:4683 # Do not require CUDA/OpenCL, as GPU code generation test cases can be run
84 # without a CUDA/OpenCL library.
Philip Pfaffe4d240932018-06-07 21:10:4985 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
86 FIND_PACKAGE(CUDA)
87 FIND_PACKAGE(OpenCL)
88 set(GPU_CODEGEN TRUE)
89 else()
90 message(WARNING "The LLVM NVPTX target is required for GPU code generation")
91 endif()
Tobias Grosser6217e182012-08-03 12:50:0792endif(POLLY_ENABLE_GPGPU_CODEGEN)
Tobias Grosser75805372011-04-29 06:27:0293
Tobias Grossere9385172016-07-14 10:22:1994
Tobias Grosser88aeaf62012-06-06 12:16:1095# Support GPGPU code generation if the library is available.
Philip Pfaffe182807a2017-06-06 19:20:4896if (CUDA_FOUND)
Siddharth Bhat17f01962017-05-07 21:03:4697 add_definitions(-DHAS_LIBCUDART)
Philip Pfaffe182807a2017-06-06 19:20:4898 INCLUDE_DIRECTORIES( ${CUDA_INCLUDE_DIRS} )
99endif(CUDA_FOUND)
Siddharth Bhat17f01962017-05-07 21:03:46100if (OpenCL_FOUND)
101 add_definitions(-DHAS_LIBOPENCL)
102 INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} )
103endif(OpenCL_FOUND)
Tobias Grosser88aeaf62012-06-06 12:16:10104
Michael Kruse64693802017-02-27 17:54:25105option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
106if (NOT POLLY_BUNDLED_ISL)
107 find_package(ISL MODULE REQUIRED)
108 message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}")
109 set(ISL_TARGET ISL)
110else()
111 set(ISL_INCLUDE_DIRS
112 ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
113 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
114 )
115 set(ISL_TARGET PollyISL)
116endif()
117
Tobias Grosser75805372011-04-29 06:27:02118include_directories(
Johannes Doerfert34558182014-05-28 16:54:42119 BEFORE
Tobias Grosser75805372011-04-29 06:27:02120 ${CMAKE_CURRENT_SOURCE_DIR}/include
Michael Kruse64693802017-02-27 17:54:25121 ${ISL_INCLUDE_DIRS}
Tobias Grossere9385172016-07-14 10:22:19122 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
Tobias Grossera56f8f82016-07-15 07:50:36123 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
Tobias Grosser75805372011-04-29 06:27:02124 ${CMAKE_CURRENT_BINARY_DIR}/include
125 )
126
Eugene Zelenko2487cb22016-06-21 18:14:01127if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
128 install(DIRECTORY include/
John Ericsond3b756c2022-01-18 07:05:47129 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
Eugene Zelenko2487cb22016-06-21 18:14:01130 FILES_MATCHING
131 PATTERN "*.h"
Eugene Zelenko2487cb22016-06-21 18:14:01132 )
Tobias Grosser71036882013-01-19 14:17:52133
Eugene Zelenko2487cb22016-06-21 18:14:01134 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
John Ericsond3b756c2022-01-18 07:05:47135 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
Eugene Zelenko2487cb22016-06-21 18:14:01136 FILES_MATCHING
137 PATTERN "*.h"
138 PATTERN "CMakeFiles" EXCLUDE
Eugene Zelenko2487cb22016-06-21 18:14:01139 )
140endif()
Tobias Grosser75805372011-04-29 06:27:02141
142add_definitions( -D_GNU_SOURCE )
143
Tobias Grosserb6948c12016-02-04 07:16:36144add_subdirectory(docs)
Tobias Grosser75805372011-04-29 06:27:02145add_subdirectory(lib)
146add_subdirectory(test)
Michael Kruse05cf9c22016-08-25 12:36:15147if (POLLY_GTEST_AVAIL)
148 add_subdirectory(unittests)
149endif ()
Tobias Grosser75805372011-04-29 06:27:02150add_subdirectory(tools)
Michael Krusea9520b92017-03-09 17:58:20151add_subdirectory(cmake)
Tobias Grosser75805372011-04-29 06:27:02152# TODO: docs.
153
154
155configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
156 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
157
Tobias Grosserc38af882013-02-14 16:19:16158# Add target to check formatting of polly files
Michael Kruse05cf9c22016-08-25 12:36:15159file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
Philip Pfaffebbb86712017-05-15 13:20:26160file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h)
Michael Kruse49c21222017-02-05 15:26:56161list( REMOVE_ITEM files ${external})
Michael Kruse69f37882015-09-14 16:59:50162
163set(check_format_depends)
164set(update_format_depends)
165set(i 0)
166foreach (file IN LISTS files)
167 add_custom_command(OUTPUT polly-check-format${i}
Tobias Grosser5da48f32015-10-15 12:18:37168 COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
Michael Kruse69f37882015-09-14 16:59:50169 VERBATIM
170 COMMENT "Checking format of ${file}..."
171 )
172 list(APPEND check_format_depends "polly-check-format${i}")
173
174 add_custom_command(OUTPUT polly-update-format${i}
Tobias Grosser5da48f32015-10-15 12:18:37175 COMMAND clang-format -sort-includes -i -style=llvm ${file}
Michael Kruse69f37882015-09-14 16:59:50176 VERBATIM
177 COMMENT "Updating format of ${file}..."
178 )
179 list(APPEND update_format_depends "polly-update-format${i}")
180
181 math(EXPR i ${i}+1)
182endforeach ()
183
184add_custom_target(polly-check-format DEPENDS ${check_format_depends})
Michael Kruse6362f5a2015-07-21 12:40:01185set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
Michael Kruse69f37882015-09-14 16:59:50186
187add_custom_target(polly-update-format DEPENDS ${update_format_depends})
Michael Kruse6362f5a2015-07-21 12:40:01188set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")
Sebastian Popa8fb7242014-03-13 20:24:48189