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 the system librarys that will link into LLVM.
24 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --system-libs
25 OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
26 OUTPUT_STRIP_TRAILING_WHITESPACE)
27 message(STATUS "System libs required by LLVM: ${LLVM_SYSTEM_LIBS}")
29 # Determine where LLVM stores its libraries.
30 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --libdir
31 OUTPUT_VARIABLE LLVM_LIBRARY_DIR
32 OUTPUT_STRIP_TRAILING_WHITESPACE)
33 link_directories("${LLVM_LIBRARY_DIR}")
35 # Now set the header paths.
36 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --includedir
37 OUTPUT_VARIABLE LLVM_INCLUDE_DIR
38 OUTPUT_STRIP_TRAILING_WHITESPACE)
39 include_directories( ${LLVM_INCLUDE_DIR} )
41 # Get the TARGET_TRIPLE
42 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --host-target
43 OUTPUT_VARIABLE TARGET_TRIPLE
44 OUTPUT_STRIP_TRAILING_WHITESPACE)
46 # And then set the cxx flags.
47 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --cxxflags
48 OUTPUT_VARIABLE LLVM_CXX_FLAGS
49 OUTPUT_STRIP_TRAILING_WHITESPACE)
50 set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS})
52 # Check LLVM_ENABLE_ASSERTIONS
53 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --assertion-mode
54 OUTPUT_VARIABLE LLVM_ENABLE_ASSERTIONS
55 OUTPUT_STRIP_TRAILING_WHITESPACE)
56 # Copied from LLVM's HandleLLVMOptions.cmake
57 if( LLVM_ENABLE_ASSERTIONS )
58 # MSVC doesn't like _DEBUG on release builds. See PR 4379.
60 add_definitions( -D_DEBUG )
62 # On non-Debug builds cmake automatically defines NDEBUG, so we
63 # explicitly undefine it:
64 if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
65 add_definitions( -UNDEBUG )
66 # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
67 foreach (flags_var_to_scrub
68 CMAKE_CXX_FLAGS_RELEASE
69 CMAKE_CXX_FLAGS_RELWITHDEBINFO
70 CMAKE_CXX_FLAGS_MINSIZEREL
72 CMAKE_C_FLAGS_RELWITHDEBINFO
73 CMAKE_C_FLAGS_MINSIZEREL)
74 string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
75 "${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
80 # Sources available, too?
81 execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --src-root
82 OUTPUT_VARIABLE MAIN_SRC_DIR
83 OUTPUT_STRIP_TRAILING_WHITESPACE)
84 set(LLVM_SOURCE_ROOT ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
86 # Enable unit tests if available.
87 set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest)
88 if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
90 ${UNITTEST_DIR}/googletest/src/gtest-all.cc
91 ${UNITTEST_DIR}/googlemock/src/gmock-all.cc
93 target_include_directories(gtest
95 "${UNITTEST_DIR}/googletest/include"
96 "${UNITTEST_DIR}/googlemock/include"
99 "${UNITTEST_DIR}/googletest"
100 "${UNITTEST_DIR}/googlemock"
102 target_link_libraries(gtest ${LLVM_SYSTEM_LIBS})
104 add_library(gtest_main ${UNITTEST_DIR}/UnitTestMain/TestMain.cpp)
105 target_link_libraries(gtest_main gtest)
107 set(POLLY_GTEST_AVAIL 1)
110 # Make sure the isl c files are built as fPIC
111 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
113 set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
114 set(POLLY_GTEST_AVAIL 1)
117 set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
118 set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
120 # Add path for custom modules
121 set(CMAKE_MODULE_PATH
123 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
126 include("polly_macros")
128 # Add appropriate flags for GCC
129 if (CMAKE_COMPILER_IS_GNUCXX)
130 # FIXME: Turn off exceptions, RTTI:
131 # -fno-exceptions -fno-rtti
132 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")
134 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
135 add_definitions("-D_HAS_EXCEPTIONS=0")
137 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
140 # Add path for custom modules
141 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
143 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
145 option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
146 if (POLLY_ENABLE_GPGPU_CODEGEN)
147 # Do not require CUDA, as GPU code generation test cases can be run without
150 set(GPU_CODEGEN TRUE)
151 else(POLLY_ENABLE_GPGPU_CODEGEN)
152 set(GPU_CODEGEN FALSE)
153 endif(POLLY_ENABLE_GPGPU_CODEGEN)
156 # Support GPGPU code generation if the library is available.
158 INCLUDE_DIRECTORIES( ${CUDALIB_INCLUDE_DIR} )
163 ${CMAKE_CURRENT_SOURCE_DIR}/include
164 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/JSON/include
165 ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
166 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
167 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
168 ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
169 ${CMAKE_CURRENT_BINARY_DIR}/include
172 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
173 install(DIRECTORY include/
177 PATTERN ".svn" EXCLUDE
180 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
184 PATTERN "CMakeFiles" EXCLUDE
185 PATTERN ".svn" EXCLUDE
189 add_definitions( -D_GNU_SOURCE )
191 add_subdirectory(docs)
192 add_subdirectory(lib)
193 add_subdirectory(test)
194 if (POLLY_GTEST_AVAIL)
195 add_subdirectory(unittests)
197 add_subdirectory(tools)
201 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
202 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
204 # Add target to check formatting of polly files
205 file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
206 file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp)
207 list( REMOVE_ITEM files ${external})
209 set(check_format_depends)
210 set(update_format_depends)
212 foreach (file IN LISTS files)
213 add_custom_command(OUTPUT polly-check-format${i}
214 COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
216 COMMENT "Checking format of ${file}..."
218 list(APPEND check_format_depends "polly-check-format${i}")
220 add_custom_command(OUTPUT polly-update-format${i}
221 COMMAND clang-format -sort-includes -i -style=llvm ${file}
223 COMMENT "Updating format of ${file}..."
225 list(APPEND update_format_depends "polly-update-format${i}")
230 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
231 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
233 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
234 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")