Clang] Fix expansion of response files in -Wp after integrated-cc1 change
[llvm-project.git] / polly / lib / External / CMakeLists.txt
blob8ffd984e542b2a14ae879bf4ab2e709bef690977
1 # External: Integer Set Library
2 if (POLLY_BUNDLED_ISL)
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}")
15   elseif ()
16     # Unknown revision
17     # TODO: We could look for a .git and get the revision from HEAD
18     set(ISL_GIT_HEAD_ID "UNKNOWN")
19   endif ()
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}")
36     if ("${${_var}}")
37       set("${_var}" 1 PARENT_SCOPE)
38     else ()
39       set("${_var}" 0 PARENT_SCOPE)
40     endif ()
41   endfunction ()
43   # Check for the existance of a type
44   function (check_c_type_exists _type _files _variable)
45     set(_includes "")
46     foreach (file_name ${_files})
47       set(_includes "${_includes}#include<${file_name}>\n")
48     endforeach()
49     check_c_source_compiles("
50     ${_includes}
51     ${_type} typeVar;
52     int main() {
53     return 0;
54     }
55     " ${_variable})
56   endfunction ()
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__))")
66   endif ()
68   check_c_source_compiles("
69   __attribute__ ((unused)) static void foo(void);
70   int main() { return 0; }
71   " HAVE___ATTRIBUTE__)
74   check_c_source_compiles_numeric("
75   #include <strings.h>
76   int main() { (void)ffs(0); return 0; }
77   " HAVE_DECL_FFS)
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("
84   #include <intrin.h>
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")
92   endif ()
95   check_c_source_compiles_numeric("
96   #include <strings.h>
97   int main() { (void)strcasecmp(\"\", \"\"); return 0; }
98   " HAVE_DECL_STRCASECMP)
100   check_c_source_compiles_numeric("
101   #include <string.h>
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")
107   endif ()
110   check_c_source_compiles_numeric("
111   #include <strings.h>
112   int main() { (void)strncasecmp(\"\", \"\", 0); return 0; }
113   " HAVE_DECL_STRNCASECMP)
115   check_c_source_compiles_numeric("
116   #include <string.h>
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")
122   endif ()
125   check_c_source_compiles_numeric("
126   #include <stdio.h>
127   int main() { snprintf((void*)0, 0, \" \"); return 0; }
128   " HAVE_DECL_SNPRINTF)
130   check_c_source_compiles_numeric("
131   #include <stdio.h>
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")
137   endif ()
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)
144   if (HAVE_UINT8T)
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>")
152   else ()
153     message(FATAL_ERROR "No stdint.h or compatible found")
154   endif ()
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
172     ${ISL_BINARY_DIR}
173     ${ISL_SOURCE_DIR}/imath
174     ${ISL_SOURCE_DIR}/include
175     ${ISL_SOURCE_DIR}
176     )
178   # ISL files to compile
179   set (ISL_FILES
180     isl/basis_reduction_tab.c
181     isl/isl_aff.c
182     isl/isl_aff_map.c
183     isl/isl_affine_hull.c
184     isl/isl_arg.c
185     isl/isl_ast_build.c
186     isl/isl_ast_build_expr.c
187     isl/isl_ast.c
188     isl/isl_ast_codegen.c
189     isl/isl_ast_graft.c
190     isl/isl_bernstein.c
191     isl/isl_blk.c
192     isl/isl_bound.c
193     isl/isl_box.c
194     isl/isl_coalesce.c
195     isl/isl_constraint.c
196     isl/isl_convex_hull.c
197     isl/isl_ctx.c
198     isl/isl_deprecated.c
199     isl/isl_dim_map.c
200     isl/isl_equalities.c
201     isl/isl_factorization.c
202     isl/isl_farkas.c
203     isl/isl_ffs.c
204     isl/isl_flow.c
205     isl/isl_fold.c
206     isl/isl_hash.c
207     isl/isl_id.c
208     isl/isl_id_to_ast_expr.c
209     isl/isl_id_to_id.c
210     isl/isl_id_to_pw_aff.c
211     isl/isl_ilp.c
212     isl/isl_imath.c
213     isl/isl_input.c
214     isl/isl_int_sioimath.c
215     isl/isl_local.c
216     isl/isl_local_space.c
217     isl/isl_lp.c
218     isl/isl_map.c
219     isl/isl_map_list.c
220     isl/isl_map_simplify.c
221     isl/isl_map_subtract.c
222     isl/isl_map_to_basic_set.c
223     isl/isl_mat.c
224     isl/isl_morph.c
225     isl/isl_obj.c
226     isl/isl_options.c
227     isl/isl_output.c
228     isl/isl_point.c
229     isl/isl_polynomial.c
230     isl/isl_printer.c
231     isl/isl_range.c
232     isl/isl_reordering.c
233     isl/isl_sample.c
234     isl/isl_scan.c
235     isl/isl_schedule.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
241     isl/isl_scheduler.c
242     isl/isl_seq.c
243     isl/isl_set_list.c
244     isl/isl_sort.c
245     isl/isl_space.c
246     isl/isl_stride.c
247     isl/isl_stream.c
248     isl/isl_tab.c
249     isl/isl_tab_pip.c
250     isl/isl_tarjan.c
251     isl/isl_transitive_closure.c
252     isl/isl_union_map.c
253     isl/isl_val.c
254     isl/isl_val_sioimath.c
255     isl/isl_vec.c
256     isl/isl_version.c
257     isl/isl_vertices.c
258     isl/print.c
259     isl/set_to_map.c
260     isl/set_from_map.c
261     isl/uset_to_umap.c
262     isl/uset_from_umap.c
263     isl/imath/gmp_compat.c
264     isl/imath/imath.c
265     isl/imath/imrat.c
266     )
268   add_polly_library(PollyISL
269     ${ISL_FILES}
270     )
273   if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
274     install(DIRECTORY
275       ${ISL_SOURCE_DIR}/include/
276       ${ISL_BINARY_DIR}/include/
277       DESTINATION include/polly
278       FILES_MATCHING
279       PATTERN "*.h"
280       PATTERN "CMakeFiles" EXCLUDE
281       PATTERN ".svn" EXCLUDE
282       )
283   endif()
285   add_executable(polly-isl-test
286     isl/isl_test.c
287     )
288   set_target_properties(polly-isl-test PROPERTIES FOLDER "Polly")
290   target_link_libraries(polly-isl-test PRIVATE
291     PollyISL
292     )
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}")
312 elseif ()
313   # Unknown revision
314   # TODO: We could look for a .git and get the revision from HEAD
315   set(PPCG_GIT_HEAD_ID "UNKNOWN")
316 endif ()
318 message(STATUS "PPCG version: ${PPCG_GIT_HEAD_ID}")
320 set (PPCG_FILES
321      ppcg/cuda.c
322      ppcg/cuda_common.c
323      ppcg/external.c
324      ppcg/gpu_array_tile.c
325      ppcg/gpu.c
326      ppcg/gpu_array_tile.c
327      ppcg/gpu_group.c
328      ppcg/gpu_hybrid.c
329      ppcg/gpu_print.c
330      ppcg/gpu_tree.c
331      ppcg/grouping.c
332      ppcg/hybrid.c
333      ppcg/ppcg.c
334      ppcg/ppcg_options.c
335      ppcg/print.c
336      ppcg/schedule.c
337      ppcg/util.c
338      )
340 include_directories(BEFORE
341   ${PPCG_BINARY_DIR}
342   ${PPCG_SOURCE_DIR}/imath
343   ${PPCG_SOURCE_DIR}/include
344   ${PET_SOURCE_DIR}/include
347 add_polly_library(PollyPPCG
348   ${PPCG_FILES}
351 target_link_libraries(PollyPPCG PUBLIC ${ISL_TARGET})
353 # Disable warnings for upstream projects.
354 if (MSVC)
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
362   )
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})
368 else ()
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")
373 endif ()
375 if(MSVC)
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")
379 endif ()