GPGPU: add scop parameters to kernel arguments
[polly-mirror.git] / CMakeLists.txt
blobb39af41e259ce35437e32c6de8852bc4e6c0f39b
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 else(POLLY_ENABLE_GPGPU_CODEGEN)
125   set(GPU_CODEGEN FALSE)
126 endif(POLLY_ENABLE_GPGPU_CODEGEN)
129 # Support GPGPU code generation if the library is available.
130 if (CUDALIB_FOUND)
131   INCLUDE_DIRECTORIES( ${CUDALIB_INCLUDE_DIR} )
132 endif(CUDALIB_FOUND)
134 include_directories(
135   BEFORE
136   ${CMAKE_CURRENT_SOURCE_DIR}/include
137   ${CMAKE_CURRENT_SOURCE_DIR}/lib/JSON/include
138   ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include
139   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include
140   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
141   ${CMAKE_CURRENT_SOURCE_DIR}/lib/External
142   ${CMAKE_CURRENT_BINARY_DIR}/include
143   )
145 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
146   install(DIRECTORY include/
147     DESTINATION include
148     FILES_MATCHING
149     PATTERN "*.h"
150     PATTERN ".svn" EXCLUDE
151     )
153   install(DIRECTORY ${POLLY_BINARY_DIR}/include/
154     DESTINATION include
155     FILES_MATCHING
156     PATTERN "*.h"
157     PATTERN "CMakeFiles" EXCLUDE
158     PATTERN ".svn" EXCLUDE
159     )
160 endif()
162 add_definitions( -D_GNU_SOURCE )
164 add_subdirectory(docs)
165 add_subdirectory(lib)
166 add_subdirectory(test)
167 add_subdirectory(tools)
168 # TODO: docs.
171 configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
172                 ${POLLY_BINARY_DIR}/include/polly/Config/config.h )
174 # Add target to check formatting of polly files
175 file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h)
176 file( GLOB_RECURSE jsonfiles lib/JSON/*.h lib/JSON/*.cpp)
177 file( GLOB_RECURSE external lib/External/*.h lib/External/*.c)
178 list( REMOVE_ITEM files ${jsonfiles} ${external})
180 set(check_format_depends)
181 set(update_format_depends)
182 set(i 0)
183 foreach (file IN LISTS files)
184   add_custom_command(OUTPUT polly-check-format${i}
185     COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
186     VERBATIM
187     COMMENT "Checking format of ${file}..."
188   )
189   list(APPEND check_format_depends "polly-check-format${i}")
191   add_custom_command(OUTPUT polly-update-format${i}
192     COMMAND clang-format -sort-includes -i -style=llvm ${file}
193     VERBATIM
194     COMMENT "Updating format of ${file}..."
195   )
196   list(APPEND update_format_depends "polly-update-format${i}")
198   math(EXPR i ${i}+1)
199 endforeach ()
201 add_custom_target(polly-check-format DEPENDS ${check_format_depends})
202 set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
204 add_custom_target(polly-update-format DEPENDS ${update_format_depends})
205 set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")
207 # Set the variable POLLY_LINK_LIBS in the llvm/tools/ dir.
208 set(POLLY_LINK_LIBS ${POLLY_LINK_LIBS} PARENT_SCOPE)