[FunctionPropertiesAnalysis] Add CFG and call properties
[llvm-project.git] / polly / CMakeLists.txt
blob5d0f2cd7f00ece134e3764f143df2cd34901fb10
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()
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(default_llvm_src "${LLVM_BUILD_MAIN_SRC_DIR}")
24   else()
25     set(default_llvm_src "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
26   endif()
27   set(LLVM_SOURCE_ROOT ${default_llvm_src} CACHE PATH "Path to LLVM source tree")
29   # Enable unit tests if available.
30   set(POLLY_GTEST_AVAIL 0)
31   set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
32   if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
33     if (NOT TARGET gtest)
34       add_subdirectory(${UNITTEST_DIR} third-party/unittest)
35     endif()
36     set(POLLY_GTEST_AVAIL 1)
37   endif()
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 ()
44   # Set directory for polly-isl-test.
45   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
46 else ()
47   set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
48   set(POLLY_GTEST_AVAIL 1)
49 endif ()
51 set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
52 set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
54 if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
55   set(LLVM_COMMON_CMAKE_UTILS ${POLLY_SOURCE_DIR}/../cmake)
56 endif()
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"
63   )
65 include("polly_macros")
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")
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")
77 endif ()
79 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
81 option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
82 if (NOT POLLY_BUNDLED_ISL)
83   find_package(ISL MODULE REQUIRED)
84   message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}")
85   set(ISL_TARGET ISL)
86 else()
87   set(ISL_INCLUDE_DIRS
88     ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
89     ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
90   )
91   set(ISL_TARGET PollyISL)
92 endif()
94 include_directories(
95   BEFORE
96   ${CMAKE_CURRENT_SOURCE_DIR}/include
97   ${ISL_INCLUDE_DIRS}
98   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
99   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
100   ${CMAKE_CURRENT_BINARY_DIR}/include
101   )
103 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
104   install(DIRECTORY include/
105     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
106     FILES_MATCHING
107     PATTERN "*.h"
108     )
110   install(DIRECTORY ${POLLY_BINARY_DIR}/include/
111     DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
112     FILES_MATCHING
113     PATTERN "*.h"
114     PATTERN "CMakeFiles" EXCLUDE
115     )
116 endif()
118 add_definitions( -D_GNU_SOURCE )
120 add_subdirectory(docs)
121 add_subdirectory(lib)
122 add_subdirectory(test)
123 if (POLLY_GTEST_AVAIL)
124   add_subdirectory(unittests)
125 endif ()
126 add_subdirectory(cmake)
127 # TODO: docs.
130 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
131                 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
133 # Add target to check formatting of polly files
134 file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
135 file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h)
136 list( REMOVE_ITEM files ${external})
138 set(check_format_depends)
139 set(update_format_depends)
140 set(i 0)
141 foreach (file IN LISTS files)
142   add_custom_command(OUTPUT polly-check-format${i}
143     COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
144     VERBATIM
145     COMMENT "Checking format of ${file}..."
146   )
147   list(APPEND check_format_depends "polly-check-format${i}")
149   add_custom_command(OUTPUT polly-update-format${i}
150     COMMAND clang-format -sort-includes -i -style=llvm ${file}
151     VERBATIM
152     COMMENT "Updating format of ${file}..."
153   )
154   list(APPEND update_format_depends "polly-update-format${i}")
156   math(EXPR i ${i}+1)
157 endforeach ()
159 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
160 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
162 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
163 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")