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)
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)
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}")
25 set(default_llvm_src "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
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)
34 add_subdirectory(${UNITTEST_DIR} third-party/unittest)
36 set(POLLY_GTEST_AVAIL 1)
40 # Make sure the isl c files are built as fPIC if possible
41 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
44 # Set directory for polly-isl-test.
45 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
47 set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
48 set(POLLY_GTEST_AVAIL 1)
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)
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"
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")
73 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
74 add_definitions("-D_HAS_EXCEPTIONS=0")
76 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
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}")
88 ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
89 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
91 set(ISL_TARGET PollyISL)
96 ${CMAKE_CURRENT_SOURCE_DIR}/include
98 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
99 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
100 ${CMAKE_CURRENT_BINARY_DIR}/include
103 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
104 install(DIRECTORY include/
105 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
110 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
111 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
114 PATTERN "CMakeFiles" EXCLUDE
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)
126 add_subdirectory(cmake)
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)
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} -
145 COMMENT "Checking format of ${file}..."
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}
152 COMMENT "Updating format of ${file}..."
154 list(APPEND update_format_depends "polly-update-format${i}")
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")