1 # Check if this is a in tree build.
2 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
4 cmake_minimum_required(VERSION 3.13.4)
5 if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
7 "Your CMake version is ${CMAKE_VERSION}. Starting with LLVM 17.0.0, the "
8 "minimum version of CMake required to build LLVM will become 3.20.0, and "
9 "using an older CMake will become an error. Please upgrade your CMake to "
10 "at least 3.20.0 now to avoid issues in the future!")
12 set(POLLY_STANDALONE_BUILD TRUE)
15 # Must go below project(..)
16 include(GNUInstallDirs)
18 if(POLLY_STANDALONE_BUILD)
19 # Where is LLVM installed?
20 find_package(LLVM CONFIG REQUIRED)
21 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
22 include(HandleLLVMOptions)
25 # Add the llvm header path.
26 include_directories(${LLVM_INCLUDE_DIRS})
28 # Sources available, too?
29 if (LLVM_BUILD_MAIN_SRC_DIR)
30 set(default_llvm_src "${LLVM_BUILD_MAIN_SRC_DIR}")
32 set(default_llvm_src "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
34 set(LLVM_SOURCE_ROOT ${default_llvm_src} CACHE PATH "Path to LLVM source tree")
36 # Enable unit tests if available.
37 set(POLLY_GTEST_AVAIL 0)
38 set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
39 if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
41 add_subdirectory(${UNITTEST_DIR} third-party/unittest)
43 set(POLLY_GTEST_AVAIL 1)
47 # Make sure the isl c files are built as fPIC if possible
48 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
51 # Set directory for polly-isl-test.
52 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
54 set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
55 set(POLLY_GTEST_AVAIL 1)
58 set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
59 set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
61 if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
62 set(LLVM_COMMON_CMAKE_UTILS ${POLLY_SOURCE_DIR}/../cmake)
65 # Make sure that our source directory is on the current cmake module path so that
66 # we can include cmake files from this directory.
67 list(INSERT CMAKE_MODULE_PATH 0
68 "${POLLY_SOURCE_DIR}/cmake"
69 "${LLVM_COMMON_CMAKE_UTILS}/Modules"
72 include("polly_macros")
74 # Add appropriate flags for GCC
75 if (CMAKE_COMPILER_IS_GNUCXX)
76 # FIXME: Turn off exceptions, RTTI:
77 # -fno-exceptions -fno-rtti
78 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")
80 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
81 add_definitions("-D_HAS_EXCEPTIONS=0")
83 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
86 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
88 option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
89 set(GPU_CODEGEN FALSE)
90 if (POLLY_ENABLE_GPGPU_CODEGEN)
91 # Do not require CUDA/OpenCL, as GPU code generation test cases can be run
92 # without a CUDA/OpenCL library.
93 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
98 message(WARNING "The LLVM NVPTX target is required for GPU code generation")
100 endif(POLLY_ENABLE_GPGPU_CODEGEN)
103 # Support GPGPU code generation if the library is available.
105 add_definitions(-DHAS_LIBCUDART)
106 INCLUDE_DIRECTORIES( ${CUDA_INCLUDE_DIRS} )
109 add_definitions(-DHAS_LIBOPENCL)
110 INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} )
113 option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
114 if (NOT POLLY_BUNDLED_ISL)
115 find_package(ISL MODULE REQUIRED)
116 message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}")
120 ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
121 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
123 set(ISL_TARGET PollyISL)
128 ${CMAKE_CURRENT_SOURCE_DIR}/include
130 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
131 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
132 ${CMAKE_CURRENT_BINARY_DIR}/include
135 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
136 install(DIRECTORY include/
137 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
142 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
143 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
146 PATTERN "CMakeFiles" EXCLUDE
150 add_definitions( -D_GNU_SOURCE )
152 add_subdirectory(docs)
153 add_subdirectory(lib)
154 add_subdirectory(test)
155 if (POLLY_GTEST_AVAIL)
156 add_subdirectory(unittests)
158 add_subdirectory(tools)
159 add_subdirectory(cmake)
163 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
164 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
166 # Add target to check formatting of polly files
167 file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
168 file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h)
169 list( REMOVE_ITEM files ${external})
171 set(check_format_depends)
172 set(update_format_depends)
174 foreach (file IN LISTS files)
175 add_custom_command(OUTPUT polly-check-format${i}
176 COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
178 COMMENT "Checking format of ${file}..."
180 list(APPEND check_format_depends "polly-check-format${i}")
182 add_custom_command(OUTPUT polly-update-format${i}
183 COMMAND clang-format -sort-includes -i -style=llvm ${file}
185 COMMENT "Updating format of ${file}..."
187 list(APPEND update_format_depends "polly-update-format${i}")
192 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
193 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
195 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
196 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")