Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 1 | # Check if this is a in tree build. |
| 2 | if (NOT DEFINED LLVM_MAIN_SRC_DIR) |
| 3 | project(Polly) |
Louis Dionne | afa1afd | 2020-04-22 15:15:05 | [diff] [blame] | 4 | cmake_minimum_required(VERSION 3.13.4) |
John Ericson | df31ff1 | 2022-01-19 06:45:07 | [diff] [blame] | 5 | set(POLLY_STANDALONE_BUILD TRUE) |
| 6 | endif() |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 7 | |
John Ericson | df31ff1 | 2022-01-19 06:45:07 | [diff] [blame] | 8 | # Must go below project(..) |
| 9 | include(GNUInstallDirs) |
| 10 | |
| 11 | if(POLLY_STANDALONE_BUILD) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 12 | # Where is LLVM installed? |
Philip Pfaffe | d99c406 | 2017-07-11 11:24:25 | [diff] [blame] | 13 | find_package(LLVM CONFIG REQUIRED) |
| 14 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) |
| 15 | include(HandleLLVMOptions) |
| 16 | include(AddLLVM) |
| 17 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 18 | # Add the llvm header path. |
Philip Pfaffe | d99c406 | 2017-07-11 11:24:25 | [diff] [blame] | 19 | include_directories(${LLVM_INCLUDE_DIRS}) |
Michael Kruse | 84bf8a3 | 2015-09-11 20:47:14 | [diff] [blame] | 20 | |
Michael Kruse | 05cf9c2 | 2016-08-25 12:36:15 | [diff] [blame] | 21 | # Sources available, too? |
Philip Pfaffe | d99c406 | 2017-07-11 11:24:25 | [diff] [blame] | 22 | if (LLVM_BUILD_MAIN_SRC_DIR) |
John Ericson | 4c51142 | 2022-08-20 21:38:05 | [diff] [blame] | 23 | set(default_llvm_src "${LLVM_BUILD_MAIN_SRC_DIR}") |
Philip Pfaffe | d99c406 | 2017-07-11 11:24:25 | [diff] [blame] | 24 | else() |
John Ericson | 4c51142 | 2022-08-20 21:38:05 | [diff] [blame] | 25 | set(default_llvm_src "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") |
Philip Pfaffe | d99c406 | 2017-07-11 11:24:25 | [diff] [blame] | 26 | endif() |
John Ericson | 4c51142 | 2022-08-20 21:38:05 | [diff] [blame] | 27 | set(LLVM_SOURCE_ROOT ${default_llvm_src} CACHE PATH "Path to LLVM source tree") |
Michael Kruse | 05cf9c2 | 2016-08-25 12:36:15 | [diff] [blame] | 28 | |
| 29 | # Enable unit tests if available. |
Philip Pfaffe | 54df93d | 2017-07-11 11:37:35 | [diff] [blame] | 30 | set(POLLY_GTEST_AVAIL 0) |
Michael Kruse | 05cf9c2 | 2016-08-25 12:36:15 | [diff] [blame] | 31 | set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest) |
| 32 | if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h) |
Michał Górny | c8b629a | 2020-08-05 08:15:41 | [diff] [blame] | 33 | if (NOT TARGET gtest) |
| 34 | add_subdirectory(${UNITTEST_DIR} utils/unittest) |
Philip Pfaffe | d99c406 | 2017-07-11 11:24:25 | [diff] [blame] | 35 | endif() |
Michał Górny | c8b629a | 2020-08-05 08:15:41 | [diff] [blame] | 36 | set(POLLY_GTEST_AVAIL 1) |
Michael Kruse | 05cf9c2 | 2016-08-25 12:36:15 | [diff] [blame] | 37 | endif() |
| 38 | |
Rainer Orth | 26d659b | 2020-08-27 08:59:51 | [diff] [blame] | 39 | 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 Kruse | abf05b1 | 2017-04-22 23:02:53 | [diff] [blame] | 43 | |
| 44 | # Set directory for polly-isl-test. |
| 45 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") |
Michael Kruse | 05cf9c2 | 2016-08-25 12:36:15 | [diff] [blame] | 46 | else () |
| 47 | set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}") |
| 48 | set(POLLY_GTEST_AVAIL 1) |
| 49 | endif () |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 50 | |
| 51 | set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 52 | set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) |
| 53 | |
John Ericson | e68215c | 2022-01-03 21:09:33 | [diff] [blame] | 54 | if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS) |
| 55 | set(LLVM_COMMON_CMAKE_UTILS ${POLLY_SOURCE_DIR}/../cmake) |
| 56 | endif() |
| 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. |
| 60 | list(INSERT CMAKE_MODULE_PATH 0 |
| 61 | "${POLLY_SOURCE_DIR}/cmake" |
| 62 | "${LLVM_COMMON_CMAKE_UTILS}/Modules" |
Tobias Grosser | bc822eb | 2012-10-21 15:51:49 | [diff] [blame] | 63 | ) |
| 64 | |
| 65 | include("polly_macros") |
| 66 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 67 | # Add appropriate flags for GCC |
| 68 | if (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 Kruse | 441357d | 2015-07-21 12:22:36 | [diff] [blame] | 72 | elseif (MSVC) |
| 73 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-") |
| 74 | add_definitions("-D_HAS_EXCEPTIONS=0") |
| 75 | else () |
| 76 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti") |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 77 | endif () |
| 78 | |
Rafael Espindola | fa0841c | 2014-02-22 13:28:31 | [diff] [blame] | 79 | SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) |
| 80 | |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 | [diff] [blame] | 81 | option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF) |
Philip Pfaffe | 4d24093 | 2018-06-07 21:10:49 | [diff] [blame] | 82 | set(GPU_CODEGEN FALSE) |
Tobias Grosser | 6217e18 | 2012-08-03 12:50:07 | [diff] [blame] | 83 | if (POLLY_ENABLE_GPGPU_CODEGEN) |
Siddharth Bhat | 17f0196 | 2017-05-07 21:03:46 | [diff] [blame] | 84 | # Do not require CUDA/OpenCL, as GPU code generation test cases can be run |
| 85 | # without a CUDA/OpenCL library. |
Philip Pfaffe | 4d24093 | 2018-06-07 21:10:49 | [diff] [blame] | 86 | 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 Grosser | 6217e18 | 2012-08-03 12:50:07 | [diff] [blame] | 93 | endif(POLLY_ENABLE_GPGPU_CODEGEN) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 94 | |
Tobias Grosser | e938517 | 2016-07-14 10:22:19 | [diff] [blame] | 95 | |
Tobias Grosser | 88aeaf6 | 2012-06-06 12:16:10 | [diff] [blame] | 96 | # Support GPGPU code generation if the library is available. |
Philip Pfaffe | 182807a | 2017-06-06 19:20:48 | [diff] [blame] | 97 | if (CUDA_FOUND) |
Siddharth Bhat | 17f0196 | 2017-05-07 21:03:46 | [diff] [blame] | 98 | add_definitions(-DHAS_LIBCUDART) |
Philip Pfaffe | 182807a | 2017-06-06 19:20:48 | [diff] [blame] | 99 | INCLUDE_DIRECTORIES( ${CUDA_INCLUDE_DIRS} ) |
| 100 | endif(CUDA_FOUND) |
Siddharth Bhat | 17f0196 | 2017-05-07 21:03:46 | [diff] [blame] | 101 | if (OpenCL_FOUND) |
| 102 | add_definitions(-DHAS_LIBOPENCL) |
| 103 | INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} ) |
| 104 | endif(OpenCL_FOUND) |
Tobias Grosser | 88aeaf6 | 2012-06-06 12:16:10 | [diff] [blame] | 105 | |
Michael Kruse | 6469380 | 2017-02-27 17:54:25 | [diff] [blame] | 106 | option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON) |
| 107 | if (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) |
| 111 | else() |
| 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) |
| 117 | endif() |
| 118 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 119 | include_directories( |
Johannes Doerfert | 3455818 | 2014-05-28 16:54:42 | [diff] [blame] | 120 | BEFORE |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 121 | ${CMAKE_CURRENT_SOURCE_DIR}/include |
Michael Kruse | 6469380 | 2017-02-27 17:54:25 | [diff] [blame] | 122 | ${ISL_INCLUDE_DIRS} |
Tobias Grosser | e938517 | 2016-07-14 10:22:19 | [diff] [blame] | 123 | ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include |
Tobias Grosser | a56f8f8 | 2016-07-15 07:50:36 | [diff] [blame] | 124 | ${CMAKE_CURRENT_SOURCE_DIR}/lib/External |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 125 | ${CMAKE_CURRENT_BINARY_DIR}/include |
| 126 | ) |
| 127 | |
Eugene Zelenko | 2487cb2 | 2016-06-21 18:14:01 | [diff] [blame] | 128 | if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) |
| 129 | install(DIRECTORY include/ |
John Ericson | d3b756c | 2022-01-18 07:05:47 | [diff] [blame] | 130 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
Eugene Zelenko | 2487cb2 | 2016-06-21 18:14:01 | [diff] [blame] | 131 | FILES_MATCHING |
| 132 | PATTERN "*.h" |
Eugene Zelenko | 2487cb2 | 2016-06-21 18:14:01 | [diff] [blame] | 133 | ) |
Tobias Grosser | 7103688 | 2013-01-19 14:17:52 | [diff] [blame] | 134 | |
Eugene Zelenko | 2487cb2 | 2016-06-21 18:14:01 | [diff] [blame] | 135 | install(DIRECTORY ${POLLY_BINARY_DIR}/include/ |
John Ericson | d3b756c | 2022-01-18 07:05:47 | [diff] [blame] | 136 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" |
Eugene Zelenko | 2487cb2 | 2016-06-21 18:14:01 | [diff] [blame] | 137 | FILES_MATCHING |
| 138 | PATTERN "*.h" |
| 139 | PATTERN "CMakeFiles" EXCLUDE |
Eugene Zelenko | 2487cb2 | 2016-06-21 18:14:01 | [diff] [blame] | 140 | ) |
| 141 | endif() |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 142 | |
| 143 | add_definitions( -D_GNU_SOURCE ) |
| 144 | |
Tobias Grosser | b6948c1 | 2016-02-04 07:16:36 | [diff] [blame] | 145 | add_subdirectory(docs) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 146 | add_subdirectory(lib) |
| 147 | add_subdirectory(test) |
Michael Kruse | 05cf9c2 | 2016-08-25 12:36:15 | [diff] [blame] | 148 | if (POLLY_GTEST_AVAIL) |
| 149 | add_subdirectory(unittests) |
| 150 | endif () |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 151 | add_subdirectory(tools) |
Michael Kruse | a9520b9 | 2017-03-09 17:58:20 | [diff] [blame] | 152 | add_subdirectory(cmake) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 | [diff] [blame] | 153 | # TODO: docs. |
| 154 | |
| 155 | |
| 156 | configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake |
| 157 | ${POLLY_BINARY_DIR}/include/polly/Config/config.h ) |
| 158 | |
Tobias Grosser | c38af88 | 2013-02-14 16:19:16 | [diff] [blame] | 159 | # Add target to check formatting of polly files |
Michael Kruse | 05cf9c2 | 2016-08-25 12:36:15 | [diff] [blame] | 160 | file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp) |
Philip Pfaffe | bbb8671 | 2017-05-15 13:20:26 | [diff] [blame] | 161 | file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h) |
Michael Kruse | 49c2122 | 2017-02-05 15:26:56 | [diff] [blame] | 162 | list( REMOVE_ITEM files ${external}) |
Michael Kruse | 69f3788 | 2015-09-14 16:59:50 | [diff] [blame] | 163 | |
| 164 | set(check_format_depends) |
| 165 | set(update_format_depends) |
| 166 | set(i 0) |
| 167 | foreach (file IN LISTS files) |
| 168 | add_custom_command(OUTPUT polly-check-format${i} |
Tobias Grosser | 5da48f3 | 2015-10-15 12:18:37 | [diff] [blame] | 169 | COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} - |
Michael Kruse | 69f3788 | 2015-09-14 16:59:50 | [diff] [blame] | 170 | 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 Grosser | 5da48f3 | 2015-10-15 12:18:37 | [diff] [blame] | 176 | COMMAND clang-format -sort-includes -i -style=llvm ${file} |
Michael Kruse | 69f3788 | 2015-09-14 16:59:50 | [diff] [blame] | 177 | 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) |
| 183 | endforeach () |
| 184 | |
| 185 | add_custom_target(polly-check-format DEPENDS ${check_format_depends}) |
Michael Kruse | 6362f5a | 2015-07-21 12:40:01 | [diff] [blame] | 186 | set_target_properties(polly-check-format PROPERTIES FOLDER "Polly") |
Michael Kruse | 69f3788 | 2015-09-14 16:59:50 | [diff] [blame] | 187 | |
| 188 | add_custom_target(polly-update-format DEPENDS ${update_format_depends}) |
Michael Kruse | 6362f5a | 2015-07-21 12:40:01 | [diff] [blame] | 189 | set_target_properties(polly-update-format PROPERTIES FOLDER "Polly") |
Sebastian Pop | a8fb724 | 2014-03-13 20:24:48 | [diff] [blame] | 190 | |