1 # Check if this is a in tree build.
2 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
4 cmake_minimum_required(VERSION 3.13.4)
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(LLVM_SOURCE_ROOT ${LLVM_BUILD_MAIN_SRC_DIR} CACHE PATH
24 "Path to LLVM source tree")
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")
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)
37 add_subdirectory(${UNITTEST_DIR} utils/unittest)
39 set(POLLY_GTEST_AVAIL 1)
43 # Make sure the isl c files are built as fPIC if possible
44 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
47 # Set directory for polly-isl-test.
48 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
50 set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
51 set(POLLY_GTEST_AVAIL 1)
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)
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"
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")
76 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
77 add_definitions("-D_HAS_EXCEPTIONS=0")
79 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
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)
94 message(WARNING "The LLVM NVPTX target is required for GPU code generation")
96 endif(POLLY_ENABLE_GPGPU_CODEGEN)
99 # Support GPGPU code generation if the library is available.
101 add_definitions(-DHAS_LIBCUDART)
102 INCLUDE_DIRECTORIES( ${CUDA_INCLUDE_DIRS} )
105 add_definitions(-DHAS_LIBOPENCL)
106 INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} )
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}")
116 ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
117 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
119 set(ISL_TARGET PollyISL)
124 ${CMAKE_CURRENT_SOURCE_DIR}/include
126 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
127 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
128 ${CMAKE_CURRENT_BINARY_DIR}/include
131 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
132 install(DIRECTORY include/
133 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
138 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
139 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
142 PATTERN "CMakeFiles" EXCLUDE
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)
154 add_subdirectory(tools)
155 add_subdirectory(cmake)
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)
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} -
174 COMMENT "Checking format of ${file}..."
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}
181 COMMENT "Updating format of ${file}..."
183 list(APPEND update_format_depends "polly-update-format${i}")
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")