1 # Check if this is a in tree build.
2 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
4 cmake_minimum_required(VERSION 3.20.0)
5 set(POLLY_STANDALONE_BUILD TRUE)
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)
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}")
26 set(default_llvm_src "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
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)
35 add_subdirectory(${UNITTEST_DIR} third-party/unittest)
37 set(POLLY_GTEST_AVAIL 1)
41 # Make sure the isl c files are built as fPIC if possible
42 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
45 # Set directory for polly-isl-test.
46 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
48 set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
49 set(POLLY_GTEST_AVAIL 1)
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)
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"
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")
74 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
75 add_definitions("-D_HAS_EXCEPTIONS=0")
77 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
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}")
89 ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
90 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
92 set(ISL_TARGET PollyISL)
97 ${CMAKE_CURRENT_SOURCE_DIR}/include
99 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
100 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
101 ${CMAKE_CURRENT_BINARY_DIR}/include
104 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
105 install(DIRECTORY include/
106 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
111 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
112 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
115 PATTERN "CMakeFiles" EXCLUDE
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)
127 add_subdirectory(cmake)
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)
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} -
146 COMMENT "Checking format of ${file}..."
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}
153 COMMENT "Updating format of ${file}..."
155 list(APPEND update_format_depends "polly-update-format${i}")
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")