1 # External: Integer Set Library
3 set(ISL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/isl")
4 set(ISL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/isl")
6 # Determine version of isl
7 if (EXISTS "${ISL_SOURCE_DIR}/GIT_HEAD_ID")
8 # The source comes from a 'make dist' archive
9 file(READ "${ISL_SOURCE_DIR}/GIT_HEAD_ID" ISL_GIT_HEAD_ID)
10 string(STRIP "${ISL_GIT_HEAD_ID}" ISL_GIT_HEAD_ID)
11 elseif (EXISTS "${ISL_SOURCE_DIR}/gitversion.h")
12 # The source directory is preconfigured
13 file(READ "${ISL_SOURCE_DIR}/gitversion.h" GITVERSION_H)
14 string(REGEX REPLACE ".*\\\"([^\\\"]*)\\\".*" "\\1" ISL_GIT_HEAD_ID "${GITVERSION_H}")
17 # TODO: We could look for a .git and get the revision from HEAD
18 set(ISL_GIT_HEAD_ID "UNKNOWN")
21 message(STATUS "ISL version: ${ISL_GIT_HEAD_ID}")
23 # Enable small integer optimization and imath
24 set(USE_GMP_FOR_MP OFF)
25 set(USE_IMATH_FOR_MP ON)
26 set(USE_SMALL_INT_OPT ON)
28 # Determine compiler characteristics
29 include(CheckCSourceCompiles)
31 # Like check_c_source_compiles, but sets the result to either
32 # 0 (error while compiling) or 1 (compiled successfully)
33 # Required for compatibility with autotool's AC_CHECK_DECLS
34 function (check_c_source_compiles_numeric _prog _var)
35 check_c_source_compiles("${_prog}" "${_var}")
37 set("${_var}" 1 PARENT_SCOPE)
39 set("${_var}" 0 PARENT_SCOPE)
43 # Check for the existance of a type
44 function (check_c_type_exists _type _files _variable)
46 foreach (file_name ${_files})
47 set(_includes "${_includes}#include<${file_name}>\n")
49 check_c_source_compiles("
59 check_c_source_compiles("
60 int func(void) __attribute__((__warn_unused_result__));
61 int main() { return 0; }
62 " HAS_ATTRIBUTE_WARN_UNUSED_RESULT)
63 set(GCC_WARN_UNUSED_RESULT)
64 if (HAS_ATTRIBUTE_WARN_UNUSED_RESULT)
65 set(GCC_WARN_UNUSED_RESULT "__attribute__((__warn_unused_result__))")
68 check_c_source_compiles("
69 __attribute__ ((unused)) static void foo(void);
70 int main() { return 0; }
74 check_c_source_compiles_numeric("
76 int main() { (void)ffs(0); return 0; }
79 check_c_source_compiles_numeric("
80 int main() { (void)__builtin_ffs(0); return 0; }
81 " HAVE_DECL___BUILTIN_FFS)
83 check_c_source_compiles_numeric("
85 int main() { (void)_BitScanForward(NULL, 0); return 0; }
86 " HAVE_DECL__BITSCANFORWARD)
88 if (NOT HAVE_DECL_FFS AND
89 NOT HAVE_DECL___BUILTIN_FFS AND
90 NOT HAVE_DECL__BITSCANFORWARD)
91 message(FATAL_ERROR "No ffs implementation found")
95 check_c_source_compiles_numeric("
97 int main() { (void)strcasecmp(\"\", \"\"); return 0; }
98 " HAVE_DECL_STRCASECMP)
100 check_c_source_compiles_numeric("
102 int main() { (void)_stricmp(\"\", \"\"); return 0; }
103 " HAVE_DECL__STRICMP)
105 if (NOT HAVE_DECL_STRCASECMP AND NOT HAVE_DECL__STRICMP)
106 message(FATAL_ERROR "No strcasecmp implementation found")
110 check_c_source_compiles_numeric("
112 int main() { (void)strncasecmp(\"\", \"\", 0); return 0; }
113 " HAVE_DECL_STRNCASECMP)
115 check_c_source_compiles_numeric("
117 int main() { (void)_strnicmp(\"\", \"\", 0); return 0; }
118 " HAVE_DECL__STRNICMP)
120 if (NOT HAVE_DECL_STRNCASECMP AND NOT HAVE_DECL__STRNICMP)
121 message(FATAL_ERROR "No strncasecmp implementation found")
125 check_c_source_compiles_numeric("
127 int main() { snprintf((void*)0, 0, \" \"); return 0; }
128 " HAVE_DECL_SNPRINTF)
130 check_c_source_compiles_numeric("
132 int main() { _snprintf((void*)0, 0, \" \"); return 0; }
133 " HAVE_DECL__SNPRINTF)
135 if (NOT HAVE_DECL_SNPRINTF AND NOT HAVE_DECL__SNPRINTF)
136 message(FATAL_ERROR "No snprintf implementation found")
140 check_c_type_exists(uint8_t "" HAVE_UINT8T)
141 check_c_type_exists(uint8_t "stdint.h" HAVE_STDINT_H)
142 check_c_type_exists(uint8_t "inttypes.h" HAVE_INTTYPES_H)
143 check_c_type_exists(uint8_t "sys/types.h" HAVE_SYS_INTTYPES_H)
145 set(INCLUDE_STDINT_H "")
146 elseif (HAVE_STDINT_H)
147 set(INCLUDE_STDINT_H "#include <stdint.h>")
148 elseif (HAVE_INTTYPES_H)
149 set(INCLUDE_STDINT_H "#include <inttypes.h>")
150 elseif (HAVE_SYS_INTTYPES_H)
151 set(INCLUDE_STDINT_H "#include <sys/inttypes.h>")
153 message(FATAL_ERROR "No stdint.h or compatible found")
156 # Write configure result
157 # configure_file(... COPYONLY) avoids that the time stamp changes if the file is identical
158 file(WRITE "${ISL_BINARY_DIR}/gitversion.h.tmp"
159 "#define GIT_HEAD_ID \"${ISL_GIT_HEAD_ID}\"")
160 configure_file("${ISL_BINARY_DIR}/gitversion.h.tmp"
161 "${ISL_BINARY_DIR}/gitversion.h" COPYONLY)
163 file(WRITE "${ISL_BINARY_DIR}/include/isl/stdint.h.tmp"
164 "${INCLUDE_STDINT_H}\n")
165 configure_file("${ISL_BINARY_DIR}/include/isl/stdint.h.tmp"
166 "${ISL_BINARY_DIR}/include/isl/stdint.h" COPYONLY)
168 configure_file("isl_config.h.cmake" "${ISL_BINARY_DIR}/isl_config.h")
169 configure_file("isl_srcdir.c.cmake" "${ISL_BINARY_DIR}/isl_srcdir.c")
171 include_directories(BEFORE
173 ${ISL_SOURCE_DIR}/imath
174 ${ISL_SOURCE_DIR}/include
178 # ISL files to compile
180 isl/basis_reduction_tab.c
183 isl/isl_affine_hull.c
186 isl/isl_ast_build_expr.c
188 isl/isl_ast_codegen.c
196 isl/isl_convex_hull.c
201 isl/isl_factorization.c
208 isl/isl_id_to_ast_expr.c
210 isl/isl_id_to_pw_aff.c
214 isl/isl_int_sioimath.c
216 isl/isl_local_space.c
220 isl/isl_map_simplify.c
221 isl/isl_map_subtract.c
222 isl/isl_map_to_basic_set.c
236 isl/isl_schedule_band.c
237 isl/isl_schedule_constraints.c
238 isl/isl_schedule_node.c
239 isl/isl_schedule_read.c
240 isl/isl_schedule_tree.c
251 isl/isl_transitive_closure.c
254 isl/isl_val_sioimath.c
263 isl/imath/gmp_compat.c
268 add_polly_library(PollyISL
273 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
275 ${ISL_SOURCE_DIR}/include/
276 ${ISL_BINARY_DIR}/include/
277 DESTINATION include/polly
280 PATTERN "CMakeFiles" EXCLUDE
281 PATTERN ".svn" EXCLUDE
285 add_executable(polly-isl-test
288 set_target_properties(polly-isl-test PROPERTIES FOLDER "Polly")
290 target_link_libraries(polly-isl-test PRIVATE
294 # ISL requires at least C99 to compile. gcc < 5.0 use -std=gnu89 as default.
295 target_enable_c99(PollyISL)
296 target_enable_c99(polly-isl-test)
297 endif (POLLY_BUNDLED_ISL)
299 set(PET_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/pet")
300 set(PPCG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ppcg")
301 set(PPCG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ppcg")
303 # Determine version of ppcg
304 if (EXISTS "${PPCG_SOURCE_DIR}/GIT_HEAD_ID")
305 # The source comes from a 'make dist' archive
306 file(READ "${PPCG_SOURCE_DIR}/GIT_HEAD_ID" PPCG_GIT_HEAD_ID)
307 string(STRIP "${PPCG_GIT_HEAD_ID}" PPCG_GIT_HEAD_ID)
308 elseif (EXISTS "${PPCG_SOURCE_DIR}/gitversion.h")
309 # The source directory is preconfigured
310 file(READ "${PPCG_SOURCE_DIR}/gitversion.h" GITVERSION_H)
311 string(REGEX REPLACE ".*\\\"([^\\\"]*)\\\".*" "\\1" PPCG_GIT_HEAD_ID "${GITVERSION_H}")
314 # TODO: We could look for a .git and get the revision from HEAD
315 set(PPCG_GIT_HEAD_ID "UNKNOWN")
318 message(STATUS "PPCG version: ${PPCG_GIT_HEAD_ID}")
324 ppcg/gpu_array_tile.c
326 ppcg/gpu_array_tile.c
340 include_directories(BEFORE
342 ${PPCG_SOURCE_DIR}/imath
343 ${PPCG_SOURCE_DIR}/include
344 ${PET_SOURCE_DIR}/include
347 add_polly_library(PollyPPCG
351 target_link_libraries(PollyPPCG PUBLIC ${ISL_TARGET})
353 # Disable warnings for upstream projects.
355 set(DISABLE_WARNING_FLAGS
356 -wd4018 # 'expression' : signed/unsigned mismatch
357 -wd4090 # 'operation' : different 'modifier' qualifiers
358 -wd4200 # nonstandard extension used: zero-sized array in struct/union
359 -wd4201 # nonstandard extension used: nameless struct/union
360 -wd4334 # 'operator': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
361 -wd4221 # nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable
363 if (POLLY_BUNDLED_ISL)
364 target_compile_options(PollyISL PRIVATE ${DISABLE_WARNING_FLAGS})
365 target_compile_options(polly-isl-test PRIVATE ${DISABLE_WARNING_FLAGS})
366 endif (POLLY_BUNDLED_ISL)
367 target_compile_options(PollyPPCG PRIVATE ${DISABLE_WARNING_FLAGS})
369 if (POLLY_BUNDLED_ISL)
370 set_target_properties(PollyISL polly-isl-test PROPERTIES COMPILE_FLAGS "-w")
371 endif (POLLY_BUNDLED_ISL)
372 set_target_properties(PollyPPCG PROPERTIES COMPILE_FLAGS "-w")
376 # In the Windows API (with some exceptions), the maximum length for a path is
377 # MAX_PATH, which is defined as 260 characters.
378 target_compile_definitions(PollyPPCG PRIVATE "-DPATH_MAX=260")