[clang-repl] [codegen] Reduce the state in TBAA. NFC for static compilation. (#98138)
[llvm-project.git] / polly / CMakeLists.txt
blobb4cfc77d0f213cd515c18f9b3c5bf0bf1015c5a1
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.20.0)
5   set(POLLY_STANDALONE_BUILD TRUE)
6 endif()
7 set(LLVM_SUBPROJECT_TITLE "Polly")
9 # Must go below project(..)
10 include(GNUInstallDirs)
12 if(POLLY_STANDALONE_BUILD)
13   # Where is LLVM installed?
14   find_package(LLVM CONFIG REQUIRED)
15   set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
16   include(HandleLLVMOptions)
17   include(AddLLVM)
19   # Add the llvm header path.
20   include_directories(${LLVM_INCLUDE_DIRS})
22   # Sources available, too?
23   if (LLVM_BUILD_MAIN_SRC_DIR)
24     set(default_llvm_src "${LLVM_BUILD_MAIN_SRC_DIR}")
25   else()
26     set(default_llvm_src "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
27   endif()
28   set(LLVM_SOURCE_ROOT ${default_llvm_src} CACHE PATH "Path to LLVM source tree")
30   # Enable unit tests if available.
31   set(POLLY_GTEST_AVAIL 0)
32   set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
33   if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
34     if (NOT TARGET gtest)
35       add_subdirectory(${UNITTEST_DIR} third-party/unittest)
36     endif()
37     set(POLLY_GTEST_AVAIL 1)
38   endif()
40   if (LLVM_ENABLE_PIC)
41     # Make sure the isl c files are built as fPIC if possible
42     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
43   endif ()
45   # Set directory for polly-isl-test.
46   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
47 else ()
48   set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
49   set(POLLY_GTEST_AVAIL 1)
50 endif ()
52 set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
53 set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
55 if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
56   set(LLVM_COMMON_CMAKE_UTILS ${POLLY_SOURCE_DIR}/../cmake)
57 endif()
59 # Make sure that our source directory is on the current cmake module path so that
60 # we can include cmake files from this directory.
61 list(INSERT CMAKE_MODULE_PATH 0
62   "${POLLY_SOURCE_DIR}/cmake"
63   "${LLVM_COMMON_CMAKE_UTILS}/Modules"
64   )
66 include("polly_macros")
68 # Add appropriate flags for GCC
69 if (CMAKE_COMPILER_IS_GNUCXX)
70   # FIXME: Turn off exceptions, RTTI:
71   # -fno-exceptions -fno-rtti
72   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")
73 elseif (MSVC)
74   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
75   add_definitions("-D_HAS_EXCEPTIONS=0")
76 else ()
77   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
78 endif ()
80 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
82 option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
83 if (NOT POLLY_BUNDLED_ISL)
84   find_package(ISL MODULE REQUIRED)
85   message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}")
86   set(ISL_TARGET ISL)
87 else()
88   set(ISL_INCLUDE_DIRS
89     ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
90     ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
91   )
92   set(ISL_TARGET PollyISL)
93 endif()
95 include_directories(
96   BEFORE
97   ${CMAKE_CURRENT_SOURCE_DIR}/include
98   ${ISL_INCLUDE_DIRS}
99   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
100   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
101   ${CMAKE_CURRENT_BINARY_DIR}/include
102   )
104 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
105   install(DIRECTORY include/
106     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
107     FILES_MATCHING
108     PATTERN "*.h"
109     )
111   install(DIRECTORY ${POLLY_BINARY_DIR}/include/
112     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
113     FILES_MATCHING
114     PATTERN "*.h"
115     PATTERN "CMakeFiles" EXCLUDE
116     )
117 endif()
119 add_definitions( -D_GNU_SOURCE )
121 add_subdirectory(docs)
122 add_subdirectory(lib)
123 add_subdirectory(test)
124 if (POLLY_GTEST_AVAIL)
125   add_subdirectory(unittests)
126 endif ()
127 add_subdirectory(cmake)
128 # TODO: docs.
131 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
132                 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
134 # Add target to check formatting of polly files
135 file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
136 file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h)
137 list( REMOVE_ITEM files ${external})
139 set(check_format_depends)
140 set(update_format_depends)
141 set(i 0)
142 foreach (file IN LISTS files)
143   add_custom_command(OUTPUT polly-check-format${i}
144     COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
145     VERBATIM
146     COMMENT "Checking format of ${file}..."
147   )
148   list(APPEND check_format_depends "polly-check-format${i}")
150   add_custom_command(OUTPUT polly-update-format${i}
151     COMMAND clang-format -sort-includes -i -style=llvm ${file}
152     VERBATIM
153     COMMENT "Updating format of ${file}..."
154   )
155   list(APPEND update_format_depends "polly-update-format${i}")
157   math(EXPR i ${i}+1)
158 endforeach ()
160 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
161 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly/Metatargets")
163 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
164 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly/Metatargets")