blob: 2e906fdd8fc73ab8f0f3a61f5d6835ea4272dc16 [file] [log] [blame]
Tobias Grosser75805372011-04-29 06:27:021# Check if this is a in tree build.
2if (NOT DEFINED LLVM_MAIN_SRC_DIR)
3 project(Polly)
Louis Dionneafa1afd2020-04-22 15:15:054 cmake_minimum_required(VERSION 3.13.4)
John Ericsondf31ff12022-01-19 06:45:075 set(POLLY_STANDALONE_BUILD TRUE)
6endif()
Tobias Grosser75805372011-04-29 06:27:027
John Ericsondf31ff12022-01-19 06:45:078# Must go below project(..)
9include(GNUInstallDirs)
10
11if(POLLY_STANDALONE_BUILD)
Tobias Grosser75805372011-04-29 06:27:0212 # Where is LLVM installed?
Philip Pfaffed99c4062017-07-11 11:24:2513 find_package(LLVM CONFIG REQUIRED)
14 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
15 include(HandleLLVMOptions)
16 include(AddLLVM)
17
Tobias Grosser75805372011-04-29 06:27:0218 # Add the llvm header path.
Philip Pfaffed99c4062017-07-11 11:24:2519 include_directories(${LLVM_INCLUDE_DIRS})
Michael Kruse84bf8a32015-09-11 20:47:1420
Michael Kruse05cf9c22016-08-25 12:36:1521 # Sources available, too?
Philip Pfaffed99c4062017-07-11 11:24:2522 if (LLVM_BUILD_MAIN_SRC_DIR)
John Ericson4c511422022-08-20 21:38:0523 set(default_llvm_src "${LLVM_BUILD_MAIN_SRC_DIR}")
Philip Pfaffed99c4062017-07-11 11:24:2524 else()
John Ericson4c511422022-08-20 21:38:0525 set(default_llvm_src "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
Philip Pfaffed99c4062017-07-11 11:24:2526 endif()
John Ericson4c511422022-08-20 21:38:0527 set(LLVM_SOURCE_ROOT ${default_llvm_src} CACHE PATH "Path to LLVM source tree")
Michael Kruse05cf9c22016-08-25 12:36:1528
29 # Enable unit tests if available.
Philip Pfaffe54df93d2017-07-11 11:37:3530 set(POLLY_GTEST_AVAIL 0)
Michael Kruse05cf9c22016-08-25 12:36:1531 set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest)
32 if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
Michał Górnyc8b629a2020-08-05 08:15:4133 if (NOT TARGET gtest)
34 add_subdirectory(${UNITTEST_DIR} utils/unittest)
Philip Pfaffed99c4062017-07-11 11:24:2535 endif()
Michał Górnyc8b629a2020-08-05 08:15:4136 set(POLLY_GTEST_AVAIL 1)
Michael Kruse05cf9c22016-08-25 12:36:1537 endif()
38
Rainer Orth26d659b2020-08-27 08:59:5139 if (LLVM_ENABLE_PIC)
40 # Make sure the isl c files are built as fPIC if possible
41 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
42 endif ()
Michael Kruseabf05b12017-04-22 23:02:5343
44 # Set directory for polly-isl-test.
45 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
Michael Kruse05cf9c22016-08-25 12:36:1546else ()
47 set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
48 set(POLLY_GTEST_AVAIL 1)
49endif ()
Tobias Grosser75805372011-04-29 06:27:0250
51set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
52set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
53
John Ericsone68215c2022-01-03 21:09:3354if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
55 set(LLVM_COMMON_CMAKE_UTILS ${POLLY_SOURCE_DIR}/../cmake)
56endif()
57
58# Make sure that our source directory is on the current cmake module path so that
59# we can include cmake files from this directory.
60list(INSERT CMAKE_MODULE_PATH 0
61 "${POLLY_SOURCE_DIR}/cmake"
62 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
Tobias Grosserbc822eb2012-10-21 15:51:4963 )
64
65include("polly_macros")
66
Tobias Grosser75805372011-04-29 06:27:0267# Add appropriate flags for GCC
68if (CMAKE_COMPILER_IS_GNUCXX)
69 # FIXME: Turn off exceptions, RTTI:
70 # -fno-exceptions -fno-rtti
71 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:3672elseif (MSVC)
73 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
74 add_definitions("-D_HAS_EXCEPTIONS=0")
75else ()
76 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
Tobias Grosser75805372011-04-29 06:27:0277endif ()
78
Rafael Espindolafa0841c2014-02-22 13:28:3179SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
80
Tobias Grosser6217e182012-08-03 12:50:0781option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
Philip Pfaffe4d240932018-06-07 21:10:4982set(GPU_CODEGEN FALSE)
Tobias Grosser6217e182012-08-03 12:50:0783if (POLLY_ENABLE_GPGPU_CODEGEN)
Siddharth Bhat17f01962017-05-07 21:03:4684 # Do not require CUDA/OpenCL, as GPU code generation test cases can be run
85 # without a CUDA/OpenCL library.
Philip Pfaffe4d240932018-06-07 21:10:4986 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
87 FIND_PACKAGE(CUDA)
88 FIND_PACKAGE(OpenCL)
89 set(GPU_CODEGEN TRUE)
90 else()
91 message(WARNING "The LLVM NVPTX target is required for GPU code generation")
92 endif()
Tobias Grosser6217e182012-08-03 12:50:0793endif(POLLY_ENABLE_GPGPU_CODEGEN)
Tobias Grosser75805372011-04-29 06:27:0294
Tobias Grossere9385172016-07-14 10:22:1995
Tobias Grosser88aeaf62012-06-06 12:16:1096# Support GPGPU code generation if the library is available.
Philip Pfaffe182807a2017-06-06 19:20:4897if (CUDA_FOUND)
Siddharth Bhat17f01962017-05-07 21:03:4698 add_definitions(-DHAS_LIBCUDART)
Philip Pfaffe182807a2017-06-06 19:20:4899 INCLUDE_DIRECTORIES( ${CUDA_INCLUDE_DIRS} )
100endif(CUDA_FOUND)
Siddharth Bhat17f01962017-05-07 21:03:46101if (OpenCL_FOUND)
102 add_definitions(-DHAS_LIBOPENCL)
103 INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} )
104endif(OpenCL_FOUND)
Tobias Grosser88aeaf62012-06-06 12:16:10105
Michael Kruse64693802017-02-27 17:54:25106option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
107if (NOT POLLY_BUNDLED_ISL)
108 find_package(ISL MODULE REQUIRED)
109 message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}")
110 set(ISL_TARGET ISL)
111else()
112 set(ISL_INCLUDE_DIRS
113 ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
114 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
115 )
116 set(ISL_TARGET PollyISL)
117endif()
118
Tobias Grosser75805372011-04-29 06:27:02119include_directories(
Johannes Doerfert34558182014-05-28 16:54:42120 BEFORE
Tobias Grosser75805372011-04-29 06:27:02121 ${CMAKE_CURRENT_SOURCE_DIR}/include
Michael Kruse64693802017-02-27 17:54:25122 ${ISL_INCLUDE_DIRS}
Tobias Grossere9385172016-07-14 10:22:19123 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
Tobias Grossera56f8f82016-07-15 07:50:36124 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
Tobias Grosser75805372011-04-29 06:27:02125 ${CMAKE_CURRENT_BINARY_DIR}/include
126 )
127
Eugene Zelenko2487cb22016-06-21 18:14:01128if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
129 install(DIRECTORY include/
John Ericsond3b756c2022-01-18 07:05:47130 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
Eugene Zelenko2487cb22016-06-21 18:14:01131 FILES_MATCHING
132 PATTERN "*.h"
Eugene Zelenko2487cb22016-06-21 18:14:01133 )
Tobias Grosser71036882013-01-19 14:17:52134
Eugene Zelenko2487cb22016-06-21 18:14:01135 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
John Ericsond3b756c2022-01-18 07:05:47136 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
Eugene Zelenko2487cb22016-06-21 18:14:01137 FILES_MATCHING
138 PATTERN "*.h"
139 PATTERN "CMakeFiles" EXCLUDE
Eugene Zelenko2487cb22016-06-21 18:14:01140 )
141endif()
Tobias Grosser75805372011-04-29 06:27:02142
143add_definitions( -D_GNU_SOURCE )
144
Tobias Grosserb6948c12016-02-04 07:16:36145add_subdirectory(docs)
Tobias Grosser75805372011-04-29 06:27:02146add_subdirectory(lib)
147add_subdirectory(test)
Michael Kruse05cf9c22016-08-25 12:36:15148if (POLLY_GTEST_AVAIL)
149 add_subdirectory(unittests)
150endif ()
Tobias Grosser75805372011-04-29 06:27:02151add_subdirectory(tools)
Michael Krusea9520b92017-03-09 17:58:20152add_subdirectory(cmake)
Tobias Grosser75805372011-04-29 06:27:02153# TODO: docs.
154
155
156configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
157 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
158
Tobias Grosserc38af882013-02-14 16:19:16159# Add target to check formatting of polly files
Michael Kruse05cf9c22016-08-25 12:36:15160file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
Philip Pfaffebbb86712017-05-15 13:20:26161file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h)
Michael Kruse49c21222017-02-05 15:26:56162list( REMOVE_ITEM files ${external})
Michael Kruse69f37882015-09-14 16:59:50163
164set(check_format_depends)
165set(update_format_depends)
166set(i 0)
167foreach (file IN LISTS files)
168 add_custom_command(OUTPUT polly-check-format${i}
Tobias Grosser5da48f32015-10-15 12:18:37169 COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
Michael Kruse69f37882015-09-14 16:59:50170 VERBATIM
171 COMMENT "Checking format of ${file}..."
172 )
173 list(APPEND check_format_depends "polly-check-format${i}")
174
175 add_custom_command(OUTPUT polly-update-format${i}
Tobias Grosser5da48f32015-10-15 12:18:37176 COMMAND clang-format -sort-includes -i -style=llvm ${file}
Michael Kruse69f37882015-09-14 16:59:50177 VERBATIM
178 COMMENT "Updating format of ${file}..."
179 )
180 list(APPEND update_format_depends "polly-update-format${i}")
181
182 math(EXPR i ${i}+1)
183endforeach ()
184
185add_custom_target(polly-check-format DEPENDS ${check_format_depends})
Michael Kruse6362f5a2015-07-21 12:40:01186set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
Michael Kruse69f37882015-09-14 16:59:50187
188add_custom_target(polly-update-format DEPENDS ${update_format_depends})
Michael Kruse6362f5a2015-07-21 12:40:01189set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")
Sebastian Popa8fb7242014-03-13 20:24:48190