Fix non-synthesizable loop exit values.
[polly-mirror.git] / CMakeLists.txt
bloba6d121aef602b1ccb6acbd9bd055d4c7c6028b62
1 # Check if this is a in tree build.
2 if (NOT DEFINED LLVM_MAIN_SRC_DIR)
3   project(Polly)
4   cmake_minimum_required(VERSION 2.8)
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 is not install by default, warn the user to Copy FileCheck
13   if( NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/FileCheck
14       OR NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/not)
15     message(WARNING "FileCheck or not are required by running regress tests, "
16                     "but they are not installed! Please copy it to "
17                     "${LLVM_INSTALL_ROOT}/bin.")
18   endif(NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/FileCheck
19         OR NOT EXISTS ${LLVM_INSTALL_ROOT}/bin/not)
20   # Add the llvm header path.
21   include_directories(${LLVM_INSTALL_ROOT}/include/)
23   # Get the system librarys that will link into LLVM.
24   function(get_system_libs return_var)
25     # Returns in `return_var' a list of system libraries used by LLVM.
26     if( NOT MSVC )
27       if( MINGW )
28         set(system_libs ${system_libs} imagehlp psapi)
29       elseif( CMAKE_HOST_UNIX )
30         if( HAVE_LIBDL )
31           set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
32         endif()
33         if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
34           set(system_libs ${system_libs} pthread)
35         endif()
36       endif( MINGW )
37     endif( NOT MSVC )
38     set(${return_var} ${system_libs} PARENT_SCOPE)
39   endfunction(get_system_libs)
41   # Now set the header paths.
42   execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --includedir
43                   OUTPUT_VARIABLE LLVM_INCLUDE_DIR
44                   OUTPUT_STRIP_TRAILING_WHITESPACE)
45   include_directories( ${LLVM_INCLUDE_DIR} )
47   # Get the TARGET_TRIPLE
48   execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --host-target
49                   OUTPUT_VARIABLE TARGET_TRIPLE
50                   OUTPUT_STRIP_TRAILING_WHITESPACE)
52   # And then set the cxx flags.
53   execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --cxxflags
54                   OUTPUT_VARIABLE LLVM_CXX_FLAGS
55                   OUTPUT_STRIP_TRAILING_WHITESPACE)
56   set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS})
58   # Check LLVM_ENABLE_ASSERTIONS
59   execute_process(COMMAND "${LLVM_INSTALL_ROOT}/bin/llvm-config" --assertion-mode
60                   OUTPUT_VARIABLE LLVM_ENABLE_ASSERTIONS
61                   OUTPUT_STRIP_TRAILING_WHITESPACE)
62   # Copied from LLVM's HandleLLVMOptions.cmake
63   if( LLVM_ENABLE_ASSERTIONS )
64     # MSVC doesn't like _DEBUG on release builds. See PR 4379.
65     if( NOT MSVC )
66       add_definitions( -D_DEBUG )
67     endif()
68     # On non-Debug builds cmake automatically defines NDEBUG, so we
69     # explicitly undefine it:
70     if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
71       add_definitions( -UNDEBUG )
72       # Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
73       foreach (flags_var_to_scrub
74           CMAKE_CXX_FLAGS_RELEASE
75           CMAKE_CXX_FLAGS_RELWITHDEBINFO
76           CMAKE_CXX_FLAGS_MINSIZEREL
77           CMAKE_C_FLAGS_RELEASE
78           CMAKE_C_FLAGS_RELWITHDEBINFO
79           CMAKE_C_FLAGS_MINSIZEREL)
80         string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " "
81           "${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
82       endforeach()
83     endif()
84   endif()
86   # Make sure the isl c files are built as fPIC
87   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
88 endif(NOT DEFINED LLVM_MAIN_SRC_DIR)
90 set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
91 set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
93 # Add path for custom modules
94 set(CMAKE_MODULE_PATH
95   ${CMAKE_MODULE_PATH}
96   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
97   )
99 include("polly_macros")
101 # Add appropriate flags for GCC
102 if (CMAKE_COMPILER_IS_GNUCXX)
103   # FIXME: Turn off exceptions, RTTI:
104   # -fno-exceptions -fno-rtti
105   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")
106 elseif (MSVC)
107   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
108   add_definitions("-D_HAS_EXCEPTIONS=0")
109 else ()
110   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
111 endif ()
113 # Add path for custom modules
114 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
116 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
118 option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
119 if (POLLY_ENABLE_GPGPU_CODEGEN)
120   # Do not require CUDA, as GPU code generation test cases can be run without
121   # a cuda library.
122   FIND_PACKAGE(CUDA)
123   set(GPU_CODEGEN TRUE)
124 endif(POLLY_ENABLE_GPGPU_CODEGEN)
126 # Support GPGPU code generation if the library is available.
127 if (CUDALIB_FOUND)
128   INCLUDE_DIRECTORIES( ${CUDALIB_INCLUDE_DIR} )
129 endif(CUDALIB_FOUND)
131 include_directories(
132   BEFORE
133   ${CMAKE_CURRENT_SOURCE_DIR}/include
134   ${CMAKE_CURRENT_SOURCE_DIR}/lib/JSON/include
135   ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
136   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
137   ${CMAKE_CURRENT_BINARY_DIR}/include
138   )
140 install(DIRECTORY include/
141   DESTINATION include
142   FILES_MATCHING
143   PATTERN "*.h"
144   PATTERN ".svn" EXCLUDE
145   )
147 install(DIRECTORY ${POLLY_BINARY_DIR}/include/
148   DESTINATION include
149   FILES_MATCHING
150   PATTERN "*.h"
151   PATTERN "CMakeFiles" EXCLUDE
152   PATTERN ".svn" EXCLUDE
153   )
155 add_definitions( -D_GNU_SOURCE )
157 add_subdirectory(docs)
158 add_subdirectory(lib)
159 add_subdirectory(test)
160 add_subdirectory(tools)
161 # TODO: docs.
164 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
165                 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
167 # Add target to check formatting of polly files
168 file( GLOB_RECURSE files *.h *.cpp)
169 file( GLOB_RECURSE jsonfiles lib/JSON/*.h lib/JSON/*.cpp)
170 file( GLOB_RECURSE islfiles lib/External/isl/*.h lib/External/isl/*.c
171                    lib/External/isl/include/isl/*.h lib/External/isl/imath/*.h
172                    lib/External/isl/imath/*.c)
173 list( REMOVE_ITEM files ${jsonfiles} ${islfiles})
175 set(check_format_depends)
176 set(update_format_depends)
177 set(i 0)
178 foreach (file IN LISTS files)
179   add_custom_command(OUTPUT polly-check-format${i}
180     COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
181     VERBATIM
182     COMMENT "Checking format of ${file}..."
183   )
184   list(APPEND check_format_depends "polly-check-format${i}")
186   add_custom_command(OUTPUT polly-update-format${i}
187     COMMAND clang-format -sort-includes -i -style=llvm ${file}
188     VERBATIM
189     COMMENT "Updating format of ${file}..."
190   )
191   list(APPEND update_format_depends "polly-update-format${i}")
193   math(EXPR i ${i}+1)
194 endforeach ()
196 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
197 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
199 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
200 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")
202 # Set the variable POLLY_LINK_LIBS in the llvm/tools/ dir.
203 set(POLLY_LINK_LIBS ${POLLY_LINK_LIBS} PARENT_SCOPE)