1 # Check if this is a in tree build.
2 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
4 cmake_minimum_required(VERSION 3.4.3)
6 # Where is LLVM installed?
7 find_package(LLVM CONFIG REQUIRED)
8 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
9 include(HandleLLVMOptions)
12 # Add the llvm header path.
13 include_directories(${LLVM_INCLUDE_DIRS})
15 # Sources available, too?
16 if (LLVM_BUILD_MAIN_SRC_DIR)
17 set(LLVM_SOURCE_ROOT ${LLVM_BUILD_MAIN_SRC_DIR} CACHE PATH
18 "Path to LLVM source tree")
20 execute_process(COMMAND "${LLVM_TOOLS_BINARY_DIR}/llvm-config" --src-root
21 OUTPUT_VARIABLE MAIN_SRC_DIR
22 OUTPUT_STRIP_TRAILING_WHITESPACE)
23 set(LLVM_SOURCE_ROOT ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
26 # Enable unit tests if available.
27 set(POLLY_GTEST_AVAIL 0)
28 set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest)
29 if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
30 # The build tree already exports the gtest target, which we can reuse
32 # LLVM Doesn't export gtest's include directorys, so do that here
33 set_target_properties(gtest
34 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
35 "${UNITTEST_DIR}/googletest/include;${UNITTEST_DIR}/googlemock/include"
37 set(POLLY_GTEST_AVAIL 1)
40 ${UNITTEST_DIR}/googletest/src/gtest-all.cc
41 ${UNITTEST_DIR}/googlemock/src/gmock-all.cc
43 target_include_directories(gtest
45 "${UNITTEST_DIR}/googletest/include"
46 "${UNITTEST_DIR}/googlemock/include"
49 "${UNITTEST_DIR}/googletest"
50 "${UNITTEST_DIR}/googlemock"
52 target_link_libraries(gtest PUBLIC -lpthread)
54 add_library(gtest_main ${UNITTEST_DIR}/UnitTestMain/TestMain.cpp)
55 target_link_libraries(gtest_main PUBLIC gtest)
57 set(POLLY_GTEST_AVAIL 1)
61 # Make sure the isl c files are built as fPIC
62 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
64 # Set directory for polly-isl-test.
65 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
67 set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
68 set(POLLY_GTEST_AVAIL 1)
71 set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
72 set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
74 # Add path for custom modules
77 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
80 include("polly_macros")
82 # Add appropriate flags for GCC
83 if (CMAKE_COMPILER_IS_GNUCXX)
84 # FIXME: Turn off exceptions, RTTI:
85 # -fno-exceptions -fno-rtti
86 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")
88 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
89 add_definitions("-D_HAS_EXCEPTIONS=0")
91 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
94 # Add path for custom modules
95 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
97 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
99 option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
100 set(GPU_CODEGEN FALSE)
101 if (POLLY_ENABLE_GPGPU_CODEGEN)
102 # Do not require CUDA/OpenCL, as GPU code generation test cases can be run
103 # without a CUDA/OpenCL library.
104 if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
107 set(GPU_CODEGEN TRUE)
109 message(WARNING "The LLVM NVPTX target is required for GPU code generation")
111 endif(POLLY_ENABLE_GPGPU_CODEGEN)
114 # Support GPGPU code generation if the library is available.
116 add_definitions(-DHAS_LIBCUDART)
117 INCLUDE_DIRECTORIES( ${CUDA_INCLUDE_DIRS} )
120 add_definitions(-DHAS_LIBOPENCL)
121 INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} )
124 option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
125 if (NOT POLLY_BUNDLED_ISL)
126 find_package(ISL MODULE REQUIRED)
127 message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}")
131 ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
132 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
134 set(ISL_TARGET PollyISL)
139 ${CMAKE_CURRENT_SOURCE_DIR}/include
141 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
142 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
143 ${CMAKE_CURRENT_BINARY_DIR}/include
146 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
147 install(DIRECTORY include/
151 PATTERN ".svn" EXCLUDE
154 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
158 PATTERN "CMakeFiles" EXCLUDE
159 PATTERN ".svn" EXCLUDE
163 add_definitions( -D_GNU_SOURCE )
165 add_subdirectory(docs)
166 add_subdirectory(lib)
167 add_subdirectory(test)
168 if (POLLY_GTEST_AVAIL)
169 add_subdirectory(unittests)
171 add_subdirectory(tools)
172 add_subdirectory(cmake)
176 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
177 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
179 # Add target to check formatting of polly files
180 file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
181 file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h)
182 list( REMOVE_ITEM files ${external})
184 set(check_format_depends)
185 set(update_format_depends)
187 foreach (file IN LISTS files)
188 add_custom_command(OUTPUT polly-check-format${i}
189 COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
191 COMMENT "Checking format of ${file}..."
193 list(APPEND check_format_depends "polly-check-format${i}")
195 add_custom_command(OUTPUT polly-update-format${i}
196 COMMAND clang-format -sort-includes -i -style=llvm ${file}
198 COMMENT "Updating format of ${file}..."
200 list(APPEND update_format_depends "polly-update-format${i}")
205 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
206 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
208 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
209 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")