Revert rGe6ccb57bb3f6b761f2310e97fd6ca99eff42f73e "[SLP] Add cost model for `llvm...
[llvm-project.git] / polly / CMakeLists.txt
blob6a6e78b06bb2dd1ac41bf3b04644b4d3246db614
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   set(POLLY_STANDALONE_BUILD TRUE)
6 endif()
8 # Must go below project(..)
9 include(GNUInstallDirs)
11 if(POLLY_STANDALONE_BUILD)
12   # Where is LLVM installed?
13   find_package(LLVM CONFIG REQUIRED)
14   set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
15   include(HandleLLVMOptions)
16   include(AddLLVM)
18   # Add the llvm header path.
19   include_directories(${LLVM_INCLUDE_DIRS})
21   # Sources available, too?
22   if (LLVM_BUILD_MAIN_SRC_DIR)
23     set(LLVM_SOURCE_ROOT ${LLVM_BUILD_MAIN_SRC_DIR} CACHE PATH
24       "Path to LLVM source tree")
25   else()
26     execute_process(COMMAND "${LLVM_TOOLS_BINARY_DIR}/llvm-config" --src-root
27       OUTPUT_VARIABLE MAIN_SRC_DIR
28       OUTPUT_STRIP_TRAILING_WHITESPACE)
29     set(LLVM_SOURCE_ROOT ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
30   endif()
32   # Enable unit tests if available.
33   set(POLLY_GTEST_AVAIL 0)
34   set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest)
35   if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
36     if (NOT TARGET gtest)
37       add_subdirectory(${UNITTEST_DIR} utils/unittest)
38     endif()
39     set(POLLY_GTEST_AVAIL 1)
40   endif()
42   if (LLVM_ENABLE_PIC)
43     # Make sure the isl c files are built as fPIC if possible
44     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
45   endif ()
47   # Set directory for polly-isl-test.
48   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
49 else ()
50   set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
51   set(POLLY_GTEST_AVAIL 1)
52 endif ()
54 set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
55 set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
57 if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
58   set(LLVM_COMMON_CMAKE_UTILS ${POLLY_SOURCE_DIR}/../cmake)
59 endif()
61 # Make sure that our source directory is on the current cmake module path so that
62 # we can include cmake files from this directory.
63 list(INSERT CMAKE_MODULE_PATH 0
64   "${POLLY_SOURCE_DIR}/cmake"
65   "${LLVM_COMMON_CMAKE_UTILS}/Modules"
66   )
68 include("polly_macros")
70 # Add appropriate flags for GCC
71 if (CMAKE_COMPILER_IS_GNUCXX)
72   # FIXME: Turn off exceptions, RTTI:
73   # -fno-exceptions -fno-rtti
74   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")
75 elseif (MSVC)
76   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
77   add_definitions("-D_HAS_EXCEPTIONS=0")
78 else ()
79   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
80 endif ()
82 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
84 option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
85 set(GPU_CODEGEN FALSE)
86 if (POLLY_ENABLE_GPGPU_CODEGEN)
87   # Do not require CUDA/OpenCL, as GPU code generation test cases can be run
88   # without a CUDA/OpenCL library.
89   if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
90     FIND_PACKAGE(CUDA)
91     FIND_PACKAGE(OpenCL)
92     set(GPU_CODEGEN TRUE)
93   else()
94     message(WARNING "The LLVM NVPTX target is required for GPU code generation")
95   endif()
96 endif(POLLY_ENABLE_GPGPU_CODEGEN)
99 # Support GPGPU code generation if the library is available.
100 if (CUDA_FOUND)
101   add_definitions(-DHAS_LIBCUDART)
102   INCLUDE_DIRECTORIES( ${CUDA_INCLUDE_DIRS} )
103 endif(CUDA_FOUND)
104 if (OpenCL_FOUND)
105   add_definitions(-DHAS_LIBOPENCL)
106   INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} )
107 endif(OpenCL_FOUND)
109 option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
110 if (NOT POLLY_BUNDLED_ISL)
111   find_package(ISL MODULE REQUIRED)
112   message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}")
113   set(ISL_TARGET ISL)
114 else()
115   set(ISL_INCLUDE_DIRS
116     ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
117     ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
118   )
119   set(ISL_TARGET PollyISL)
120 endif()
122 include_directories(
123   BEFORE
124   ${CMAKE_CURRENT_SOURCE_DIR}/include
125   ${ISL_INCLUDE_DIRS}
126   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
127   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
128   ${CMAKE_CURRENT_BINARY_DIR}/include
129   )
131 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
132   install(DIRECTORY include/
133     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
134     FILES_MATCHING
135     PATTERN "*.h"
136     )
138   install(DIRECTORY ${POLLY_BINARY_DIR}/include/
139     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
140     FILES_MATCHING
141     PATTERN "*.h"
142     PATTERN "CMakeFiles" EXCLUDE
143     )
144 endif()
146 add_definitions( -D_GNU_SOURCE )
148 add_subdirectory(docs)
149 add_subdirectory(lib)
150 add_subdirectory(test)
151 if (POLLY_GTEST_AVAIL)
152   add_subdirectory(unittests)
153 endif ()
154 add_subdirectory(tools)
155 add_subdirectory(cmake)
156 # TODO: docs.
159 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
160                 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
162 # Add target to check formatting of polly files
163 file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
164 file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h)
165 list( REMOVE_ITEM files ${external})
167 set(check_format_depends)
168 set(update_format_depends)
169 set(i 0)
170 foreach (file IN LISTS files)
171   add_custom_command(OUTPUT polly-check-format${i}
172     COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
173     VERBATIM
174     COMMENT "Checking format of ${file}..."
175   )
176   list(APPEND check_format_depends "polly-check-format${i}")
178   add_custom_command(OUTPUT polly-update-format${i}
179     COMMAND clang-format -sort-includes -i -style=llvm ${file}
180     VERBATIM
181     COMMENT "Updating format of ${file}..."
182   )
183   list(APPEND update_format_depends "polly-update-format${i}")
185   math(EXPR i ${i}+1)
186 endforeach ()
188 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
189 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
191 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
192 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")