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 set(LLVM_INSTALL_ROOT "" CACHE PATH "Root of LLVM install.")
8 # Check if the LLVM_INSTALL_ROOT valid.
9 if( NOT EXISTS ${LLVM_INSTALL_ROOT}/include/llvm )
10 message(FATAL_ERROR "LLVM_INSTALL_ROOT (${LLVM_INSTALL_ROOT}) is not a valid LLVM installation.")
11 endif(NOT EXISTS ${LLVM_INSTALL_ROOT}/include/llvm)
12 # FileCheck, not and llvm-lit are not install by default, warn the user to copy them.
13 if( NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/FileCheck
14 OR NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/not
15 OR NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/llvm-lit )
16 message(WARNING "'FileCheck', 'not' and 'llvm-lit' are required by running regress tests, "
17 "but they are not installed! Please copy them to "
18 "${LLVM_INSTALL_ROOT}/bin.")
20 # Add the llvm header path.
21 include_directories(${LLVM_INSTALL_ROOT}/include/)
23 # Get LLVM's own libraries.
24 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --libs
25 OUTPUT_VARIABLE LLVM_LIBS
26 OUTPUT_STRIP_TRAILING_WHITESPACE)
28 # Get the system librarys that will link into LLVM.
29 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --system-libs
30 OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
31 OUTPUT_STRIP_TRAILING_WHITESPACE)
32 message(STATUS "System libs required by LLVM: ${LLVM_SYSTEM_LIBS}")
34 # Determine where LLVM stores its libraries.
35 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --libdir
36 OUTPUT_VARIABLE LLVM_LIBRARY_DIR
37 OUTPUT_STRIP_TRAILING_WHITESPACE)
38 link_directories("${LLVM_LIBRARY_DIR}")
40 # Now set the header paths.
41 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --includedir
42 OUTPUT_VARIABLE LLVM_INCLUDE_DIR
43 OUTPUT_STRIP_TRAILING_WHITESPACE)
44 include_directories( ${LLVM_INCLUDE_DIR} )
46 # Get the TARGET_TRIPLE
47 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --host-target
48 OUTPUT_VARIABLE TARGET_TRIPLE
49 OUTPUT_STRIP_TRAILING_WHITESPACE)
51 # And then set the cxx flags.
52 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --cxxflags
53 OUTPUT_VARIABLE LLVM_CXX_FLAGS
54 OUTPUT_STRIP_TRAILING_WHITESPACE)
55 set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS})
57 # Check LLVM_ENABLE_ASSERTIONS
58 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --assertion-mode
59 OUTPUT_VARIABLE LLVM_ENABLE_ASSERTIONS
60 OUTPUT_STRIP_TRAILING_WHITESPACE)
61 # Copied from LLVM's HandleLLVMOptions.cmake
62 if( LLVM_ENABLE_ASSERTIONS )
63 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
65 add_definitions( -D_DEBUG )
67 # On non-Debug builds cmake automatically defines NDEBUG, so we
68 # explicitly undefine it:
69 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
70 add_definitions( -UNDEBUG )
71 # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
72 foreach (flags_var_to_scrub
73 CMAKE_CXX_FLAGS_RELEASE
74 CMAKE_CXX_FLAGS_RELWITHDEBINFO
75 CMAKE_CXX_FLAGS_MINSIZEREL
77 CMAKE_C_FLAGS_RELWITHDEBINFO
78 CMAKE_C_FLAGS_MINSIZEREL)
79 string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
80 "${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
85 # Sources available, too?
86 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --src-root
87 OUTPUT_VARIABLE MAIN_SRC_DIR
88 OUTPUT_STRIP_TRAILING_WHITESPACE)
89 set(LLVM_SOURCE_ROOT ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
91 # Enable unit tests if available.
92 set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest)
93 if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
95 ${UNITTEST_DIR}/googletest/src/gtest-all.cc
96 ${UNITTEST_DIR}/googlemock/src/gmock-all.cc
98 target_include_directories(gtest
100 "${UNITTEST_DIR}/googletest/include"
101 "${UNITTEST_DIR}/googlemock/include"
104 "${UNITTEST_DIR}/googletest"
105 "${UNITTEST_DIR}/googlemock"
107 target_link_libraries(gtest -lpthread)
109 add_library(gtest_main ${UNITTEST_DIR}/UnitTestMain/TestMain.cpp)
110 target_link_libraries(gtest_main gtest)
112 set(POLLY_GTEST_AVAIL 1)
115 # Make sure the isl c files are built as fPIC
116 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
118 # Set directory for polly-isl-test.
119 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
121 set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
122 set(POLLY_GTEST_AVAIL 1)
125 set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
126 set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
128 # Add path for custom modules
129 set(CMAKE_MODULE_PATH
131 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
134 include("polly_macros")
136 # Add appropriate flags for GCC
137 if (CMAKE_COMPILER_IS_GNUCXX)
138 # FIXME: Turn off exceptions, RTTI:
139 # -fno-exceptions -fno-rtti
140 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")
142 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
143 add_definitions("-D_HAS_EXCEPTIONS=0")
145 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
148 # Add path for custom modules
149 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
151 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
153 option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
154 if (POLLY_ENABLE_GPGPU_CODEGEN)
155 # Do not require CUDA/OpenCL, as GPU code generation test cases can be run
156 # without a CUDA/OpenCL library.
159 set(GPU_CODEGEN TRUE)
160 else(POLLY_ENABLE_GPGPU_CODEGEN)
161 set(GPU_CODEGEN FALSE)
162 endif(POLLY_ENABLE_GPGPU_CODEGEN)
165 # Support GPGPU code generation if the library is available.
167 add_definitions(-DHAS_LIBCUDART)
168 INCLUDE_DIRECTORIES( ${CUDALIB_INCLUDE_DIR} )
171 add_definitions(-DHAS_LIBOPENCL)
172 INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} )
175 option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
176 if (NOT POLLY_BUNDLED_ISL)
177 find_package(ISL MODULE REQUIRED)
178 message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}")
182 ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
183 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
185 set(ISL_TARGET PollyISL)
188 option(POLLY_BUNDLED_JSONCPP "Use the bundled version of jsoncpp included in Polly" ON)
189 if (POLLY_BUNDLED_JSONCPP)
190 set(JSONCPP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/lib/External/JSON/include")
191 set(JSONCPP_LIBRARIES)
193 External/JSON/json_reader.cpp
194 External/JSON/json_value.cpp
195 External/JSON/json_writer.cpp
198 find_package(Jsoncpp REQUIRED)
199 set(POLLY_JSON_FILES)
204 ${CMAKE_CURRENT_SOURCE_DIR}/include
206 ${JSONCPP_INCLUDE_DIRS}
207 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
208 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
209 ${CMAKE_CURRENT_BINARY_DIR}/include
212 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
213 install(DIRECTORY include/
217 PATTERN ".svn" EXCLUDE
220 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
224 PATTERN "CMakeFiles" EXCLUDE
225 PATTERN ".svn" EXCLUDE
229 add_definitions( -D_GNU_SOURCE )
231 add_subdirectory(docs)
232 add_subdirectory(lib)
233 add_subdirectory(test)
234 if (POLLY_GTEST_AVAIL)
235 add_subdirectory(unittests)
237 add_subdirectory(tools)
238 add_subdirectory(cmake)
242 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
243 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
245 # Add target to check formatting of polly files
246 file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
247 file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp)
248 list( REMOVE_ITEM files ${external})
250 set(check_format_depends)
251 set(update_format_depends)
253 foreach (file IN LISTS files)
254 add_custom_command(OUTPUT polly-check-format${i}
255 COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
257 COMMENT "Checking format of ${file}..."
259 list(APPEND check_format_depends "polly-check-format${i}")
261 add_custom_command(OUTPUT polly-update-format${i}
262 COMMAND clang-format -sort-includes -i -style=llvm ${file}
264 COMMENT "Updating format of ${file}..."
266 list(APPEND update_format_depends "polly-update-format${i}")
271 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
272 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
274 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
275 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")