[RISCV] Refactor RVV Policy by structure
[llvm-project.git] / polly / CMakeLists.txt
blobb81ce165b62fdc724c7f4937031419c2f24f56c4
1 # Check if this is a in tree build.
2 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
3   project(Polly)
4   cmake_minimum_required(VERSION 3.13.4)
5   if ("${CMAKE_VERSION}" VERSION_LESS "3.20.0")
6     message(WARNING
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!")
11   endif()
12   set(POLLY_STANDALONE_BUILD TRUE)
13 endif()
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)
23   include(AddLLVM)
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}")
31   else()
32     set(default_llvm_src "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
33   endif()
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)
40     if (NOT TARGET gtest)
41       add_subdirectory(${UNITTEST_DIR} third-party/unittest)
42     endif()
43     set(POLLY_GTEST_AVAIL 1)
44   endif()
46   if (LLVM_ENABLE_PIC)
47     # Make sure the isl c files are built as fPIC if possible
48     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
49   endif ()
51   # Set directory for polly-isl-test.
52   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
53 else ()
54   set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
55   set(POLLY_GTEST_AVAIL 1)
56 endif ()
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)
63 endif()
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"
70   )
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")
79 elseif (MSVC)
80   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
81   add_definitions("-D_HAS_EXCEPTIONS=0")
82 else ()
83   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
84 endif ()
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)
94     FIND_PACKAGE(CUDA)
95     FIND_PACKAGE(OpenCL)
96     set(GPU_CODEGEN TRUE)
97   else()
98     message(WARNING "The LLVM NVPTX target is required for GPU code generation")
99   endif()
100 endif(POLLY_ENABLE_GPGPU_CODEGEN)
103 # Support GPGPU code generation if the library is available.
104 if (CUDA_FOUND)
105   add_definitions(-DHAS_LIBCUDART)
106   INCLUDE_DIRECTORIES( ${CUDA_INCLUDE_DIRS} )
107 endif(CUDA_FOUND)
108 if (OpenCL_FOUND)
109   add_definitions(-DHAS_LIBOPENCL)
110   INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} )
111 endif(OpenCL_FOUND)
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}")
117   set(ISL_TARGET ISL)
118 else()
119   set(ISL_INCLUDE_DIRS
120     ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
121     ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
122   )
123   set(ISL_TARGET PollyISL)
124 endif()
126 include_directories(
127   BEFORE
128   ${CMAKE_CURRENT_SOURCE_DIR}/include
129   ${ISL_INCLUDE_DIRS}
130   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
131   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
132   ${CMAKE_CURRENT_BINARY_DIR}/include
133   )
135 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
136   install(DIRECTORY include/
137     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
138     FILES_MATCHING
139     PATTERN "*.h"
140     )
142   install(DIRECTORY ${POLLY_BINARY_DIR}/include/
143     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
144     FILES_MATCHING
145     PATTERN "*.h"
146     PATTERN "CMakeFiles" EXCLUDE
147     )
148 endif()
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)
157 endif ()
158 add_subdirectory(tools)
159 add_subdirectory(cmake)
160 # TODO: docs.
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)
173 set(i 0)
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} -
177     VERBATIM
178     COMMENT "Checking format of ${file}..."
179   )
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}
184     VERBATIM
185     COMMENT "Updating format of ${file}..."
186   )
187   list(APPEND update_format_depends "polly-update-format${i}")
189   math(EXPR i ${i}+1)
190 endforeach ()
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")