16048d1d1SMichael Kruse# Disable warnings for upstream projects. 26048d1d1SMichael Kruseif (MSVC) 36048d1d1SMichael Kruse set(DISABLE_WARNING_FLAGS 46048d1d1SMichael Kruse -wd4018 # 'expression' : signed/unsigned mismatch 56048d1d1SMichael Kruse -wd4090 # 'operation' : different 'modifier' qualifiers 66048d1d1SMichael Kruse -wd4200 # nonstandard extension used: zero-sized array in struct/union 76048d1d1SMichael Kruse -wd4201 # nonstandard extension used: nameless struct/union 86048d1d1SMichael Kruse -wd4334 # 'operator': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) 96048d1d1SMichael Kruse -wd4221 # nonstandard extension used : 'identifier' : cannot be initialized using address of automatic variable 106048d1d1SMichael Kruse ) 116048d1d1SMichael Kruseelse () 126048d1d1SMichael Kruse set(DISABLE_WARNING_FLAGS "-w") 136048d1d1SMichael Kruseendif () 146048d1d1SMichael Kruse 156048d1d1SMichael Kruse 16519b3cfdSMichael Kruse# External: Integer Set Library 176469380dSMichael Kruseif (POLLY_BUNDLED_ISL) 18519b3cfdSMichael Kruse set(ISL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/isl") 19519b3cfdSMichael Kruse set(ISL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/isl") 20519b3cfdSMichael Kruse 21519b3cfdSMichael Kruse # Determine version of isl 22519b3cfdSMichael Kruse if (EXISTS "${ISL_SOURCE_DIR}/GIT_HEAD_ID") 23519b3cfdSMichael Kruse # The source comes from a 'make dist' archive 24a041239bSTobias Grosser file(READ "${ISL_SOURCE_DIR}/GIT_HEAD_ID" ISL_GIT_HEAD_ID) 25a041239bSTobias Grosser string(STRIP "${ISL_GIT_HEAD_ID}" ISL_GIT_HEAD_ID) 26519b3cfdSMichael Kruse elseif (EXISTS "${ISL_SOURCE_DIR}/gitversion.h") 27519b3cfdSMichael Kruse # The source directory is preconfigured 28519b3cfdSMichael Kruse file(READ "${ISL_SOURCE_DIR}/gitversion.h" GITVERSION_H) 29a041239bSTobias Grosser string(REGEX REPLACE ".*\\\"([^\\\"]*)\\\".*" "\\1" ISL_GIT_HEAD_ID "${GITVERSION_H}") 30519b3cfdSMichael Kruse elseif () 31519b3cfdSMichael Kruse # Unknown revision 32519b3cfdSMichael Kruse # TODO: We could look for a .git and get the revision from HEAD 33a041239bSTobias Grosser set(ISL_GIT_HEAD_ID "UNKNOWN") 34519b3cfdSMichael Kruse endif () 35519b3cfdSMichael Kruse 36a041239bSTobias Grosser message(STATUS "ISL version: ${ISL_GIT_HEAD_ID}") 37519b3cfdSMichael Kruse 38519b3cfdSMichael Kruse # Enable small integer optimization and imath 39519b3cfdSMichael Kruse set(USE_GMP_FOR_MP OFF) 40519b3cfdSMichael Kruse set(USE_IMATH_FOR_MP ON) 41519b3cfdSMichael Kruse set(USE_SMALL_INT_OPT ON) 42519b3cfdSMichael Kruse 43519b3cfdSMichael Kruse # Determine compiler characteristics 44519b3cfdSMichael Kruse include(CheckCSourceCompiles) 45519b3cfdSMichael Kruse 46519b3cfdSMichael Kruse # Like check_c_source_compiles, but sets the result to either 47519b3cfdSMichael Kruse # 0 (error while compiling) or 1 (compiled successfully) 48519b3cfdSMichael Kruse # Required for compatibility with autotool's AC_CHECK_DECLS 49519b3cfdSMichael Kruse function (check_c_source_compiles_numeric _prog _var) 50519b3cfdSMichael Kruse check_c_source_compiles("${_prog}" "${_var}") 51519b3cfdSMichael Kruse if ("${${_var}}") 52519b3cfdSMichael Kruse set("${_var}" 1 PARENT_SCOPE) 53519b3cfdSMichael Kruse else () 54519b3cfdSMichael Kruse set("${_var}" 0 PARENT_SCOPE) 55519b3cfdSMichael Kruse endif () 56519b3cfdSMichael Kruse endfunction () 57519b3cfdSMichael Kruse 58519b3cfdSMichael Kruse # Check for the existance of a type 59519b3cfdSMichael Kruse function (check_c_type_exists _type _files _variable) 60519b3cfdSMichael Kruse set(_includes "") 61519b3cfdSMichael Kruse foreach (file_name ${_files}) 62519b3cfdSMichael Kruse set(_includes "${_includes}#include<${file_name}>\n") 63519b3cfdSMichael Kruse endforeach() 64519b3cfdSMichael Kruse check_c_source_compiles(" 65519b3cfdSMichael Kruse ${_includes} 66519b3cfdSMichael Kruse ${_type} typeVar; 6732a2af44SSam James int main(void) { 68519b3cfdSMichael Kruse return 0; 69519b3cfdSMichael Kruse } 70519b3cfdSMichael Kruse " ${_variable}) 71519b3cfdSMichael Kruse endfunction () 72519b3cfdSMichael Kruse 73519b3cfdSMichael Kruse 74519b3cfdSMichael Kruse check_c_source_compiles(" 75519b3cfdSMichael Kruse int func(void) __attribute__((__warn_unused_result__)); 7632a2af44SSam James int main(void) { return 0; } 77519b3cfdSMichael Kruse " HAS_ATTRIBUTE_WARN_UNUSED_RESULT) 78519b3cfdSMichael Kruse set(GCC_WARN_UNUSED_RESULT) 79519b3cfdSMichael Kruse if (HAS_ATTRIBUTE_WARN_UNUSED_RESULT) 80519b3cfdSMichael Kruse set(GCC_WARN_UNUSED_RESULT "__attribute__((__warn_unused_result__))") 81519b3cfdSMichael Kruse endif () 82519b3cfdSMichael Kruse 83519b3cfdSMichael Kruse check_c_source_compiles(" 843d0266b6SMichael Kruse __attribute__ ((unused)) static void foo(void); 8532a2af44SSam James int main(void) { return 0; } 86519b3cfdSMichael Kruse " HAVE___ATTRIBUTE__) 87519b3cfdSMichael Kruse 88519b3cfdSMichael Kruse 89519b3cfdSMichael Kruse check_c_source_compiles_numeric(" 90519b3cfdSMichael Kruse #include <strings.h> 9132a2af44SSam James int main(void) { (void)ffs(0); return 0; } 92519b3cfdSMichael Kruse " HAVE_DECL_FFS) 93519b3cfdSMichael Kruse 94519b3cfdSMichael Kruse check_c_source_compiles_numeric(" 9532a2af44SSam James int main(void) { (void)__builtin_ffs(0); return 0; } 96519b3cfdSMichael Kruse " HAVE_DECL___BUILTIN_FFS) 97519b3cfdSMichael Kruse 98519b3cfdSMichael Kruse check_c_source_compiles_numeric(" 99519b3cfdSMichael Kruse #include <intrin.h> 10032a2af44SSam James int main(void) { (void)_BitScanForward(NULL, 0); return 0; } 101519b3cfdSMichael Kruse " HAVE_DECL__BITSCANFORWARD) 102519b3cfdSMichael Kruse 103519b3cfdSMichael Kruse if (NOT HAVE_DECL_FFS AND 104519b3cfdSMichael Kruse NOT HAVE_DECL___BUILTIN_FFS AND 105519b3cfdSMichael Kruse NOT HAVE_DECL__BITSCANFORWARD) 106519b3cfdSMichael Kruse message(FATAL_ERROR "No ffs implementation found") 107519b3cfdSMichael Kruse endif () 108519b3cfdSMichael Kruse 109519b3cfdSMichael Kruse 110519b3cfdSMichael Kruse check_c_source_compiles_numeric(" 111519b3cfdSMichael Kruse #include <strings.h> 11232a2af44SSam James int main(void) { (void)strcasecmp(\"\", \"\"); return 0; } 113519b3cfdSMichael Kruse " HAVE_DECL_STRCASECMP) 114519b3cfdSMichael Kruse 115519b3cfdSMichael Kruse check_c_source_compiles_numeric(" 116519b3cfdSMichael Kruse #include <string.h> 11732a2af44SSam James int main(void) { (void)_stricmp(\"\", \"\"); return 0; } 118519b3cfdSMichael Kruse " HAVE_DECL__STRICMP) 119519b3cfdSMichael Kruse 120519b3cfdSMichael Kruse if (NOT HAVE_DECL_STRCASECMP AND NOT HAVE_DECL__STRICMP) 121519b3cfdSMichael Kruse message(FATAL_ERROR "No strcasecmp implementation found") 122519b3cfdSMichael Kruse endif () 123519b3cfdSMichael Kruse 124519b3cfdSMichael Kruse 125519b3cfdSMichael Kruse check_c_source_compiles_numeric(" 126519b3cfdSMichael Kruse #include <strings.h> 12732a2af44SSam James int main(void) { (void)strncasecmp(\"\", \"\", 0); return 0; } 128519b3cfdSMichael Kruse " HAVE_DECL_STRNCASECMP) 129519b3cfdSMichael Kruse 130519b3cfdSMichael Kruse check_c_source_compiles_numeric(" 131519b3cfdSMichael Kruse #include <string.h> 13232a2af44SSam James int main(void) { (void)_strnicmp(\"\", \"\", 0); return 0; } 133519b3cfdSMichael Kruse " HAVE_DECL__STRNICMP) 134519b3cfdSMichael Kruse 135519b3cfdSMichael Kruse if (NOT HAVE_DECL_STRNCASECMP AND NOT HAVE_DECL__STRNICMP) 136519b3cfdSMichael Kruse message(FATAL_ERROR "No strncasecmp implementation found") 137519b3cfdSMichael Kruse endif () 138519b3cfdSMichael Kruse 139519b3cfdSMichael Kruse 140519b3cfdSMichael Kruse check_c_source_compiles_numeric(" 141519b3cfdSMichael Kruse #include <stdio.h> 14232a2af44SSam James int main(void) { snprintf((void*)0, 0, \" \"); return 0; } 143519b3cfdSMichael Kruse " HAVE_DECL_SNPRINTF) 144519b3cfdSMichael Kruse 145519b3cfdSMichael Kruse check_c_source_compiles_numeric(" 146519b3cfdSMichael Kruse #include <stdio.h> 14732a2af44SSam James int main(void) { _snprintf((void*)0, 0, \" \"); return 0; } 148519b3cfdSMichael Kruse " HAVE_DECL__SNPRINTF) 149519b3cfdSMichael Kruse 150519b3cfdSMichael Kruse if (NOT HAVE_DECL_SNPRINTF AND NOT HAVE_DECL__SNPRINTF) 151519b3cfdSMichael Kruse message(FATAL_ERROR "No snprintf implementation found") 152519b3cfdSMichael Kruse endif () 153519b3cfdSMichael Kruse 154519b3cfdSMichael Kruse 155519b3cfdSMichael Kruse check_c_type_exists(uint8_t "" HAVE_UINT8T) 156519b3cfdSMichael Kruse check_c_type_exists(uint8_t "stdint.h" HAVE_STDINT_H) 157519b3cfdSMichael Kruse check_c_type_exists(uint8_t "inttypes.h" HAVE_INTTYPES_H) 158519b3cfdSMichael Kruse check_c_type_exists(uint8_t "sys/types.h" HAVE_SYS_INTTYPES_H) 159519b3cfdSMichael Kruse if (HAVE_UINT8T) 160519b3cfdSMichael Kruse set(INCLUDE_STDINT_H "") 161519b3cfdSMichael Kruse elseif (HAVE_STDINT_H) 162519b3cfdSMichael Kruse set(INCLUDE_STDINT_H "#include <stdint.h>") 163519b3cfdSMichael Kruse elseif (HAVE_INTTYPES_H) 164519b3cfdSMichael Kruse set(INCLUDE_STDINT_H "#include <inttypes.h>") 165519b3cfdSMichael Kruse elseif (HAVE_SYS_INTTYPES_H) 166519b3cfdSMichael Kruse set(INCLUDE_STDINT_H "#include <sys/inttypes.h>") 167519b3cfdSMichael Kruse else () 168519b3cfdSMichael Kruse message(FATAL_ERROR "No stdint.h or compatible found") 169519b3cfdSMichael Kruse endif () 170519b3cfdSMichael Kruse 171519b3cfdSMichael Kruse # Write configure result 172519b3cfdSMichael Kruse # configure_file(... COPYONLY) avoids that the time stamp changes if the file is identical 173519b3cfdSMichael Kruse file(WRITE "${ISL_BINARY_DIR}/gitversion.h.tmp" 174a041239bSTobias Grosser "#define GIT_HEAD_ID \"${ISL_GIT_HEAD_ID}\"") 175519b3cfdSMichael Kruse configure_file("${ISL_BINARY_DIR}/gitversion.h.tmp" 176519b3cfdSMichael Kruse "${ISL_BINARY_DIR}/gitversion.h" COPYONLY) 177519b3cfdSMichael Kruse 178519b3cfdSMichael Kruse file(WRITE "${ISL_BINARY_DIR}/include/isl/stdint.h.tmp" 179c90ed44bSTobias Grosser "${INCLUDE_STDINT_H}\n") 180519b3cfdSMichael Kruse configure_file("${ISL_BINARY_DIR}/include/isl/stdint.h.tmp" 181519b3cfdSMichael Kruse "${ISL_BINARY_DIR}/include/isl/stdint.h" COPYONLY) 182519b3cfdSMichael Kruse 183519b3cfdSMichael Kruse configure_file("isl_config.h.cmake" "${ISL_BINARY_DIR}/isl_config.h") 1841b8eb410SMichael Kruse configure_file("isl_srcdir.c.cmake" "${ISL_BINARY_DIR}/isl_srcdir.c") 185519b3cfdSMichael Kruse 186519b3cfdSMichael Kruse include_directories(BEFORE 187519b3cfdSMichael Kruse ${ISL_BINARY_DIR} 188519b3cfdSMichael Kruse ${ISL_SOURCE_DIR}/imath 189519b3cfdSMichael Kruse ${ISL_SOURCE_DIR}/include 190519b3cfdSMichael Kruse ${ISL_SOURCE_DIR} 191519b3cfdSMichael Kruse ) 192519b3cfdSMichael Kruse 193519b3cfdSMichael Kruse # ISL files to compile 194519b3cfdSMichael Kruse set (ISL_FILES 195519b3cfdSMichael Kruse isl/basis_reduction_tab.c 196519b3cfdSMichael Kruse isl/isl_aff.c 197b3706154STobias Grosser isl/isl_aff_map.c 198519b3cfdSMichael Kruse isl/isl_affine_hull.c 199519b3cfdSMichael Kruse isl/isl_arg.c 200519b3cfdSMichael Kruse isl/isl_ast_build.c 201519b3cfdSMichael Kruse isl/isl_ast_build_expr.c 202519b3cfdSMichael Kruse isl/isl_ast.c 203519b3cfdSMichael Kruse isl/isl_ast_codegen.c 204519b3cfdSMichael Kruse isl/isl_ast_graft.c 205519b3cfdSMichael Kruse isl/isl_bernstein.c 206519b3cfdSMichael Kruse isl/isl_blk.c 207519b3cfdSMichael Kruse isl/isl_bound.c 2082c543e77STobias Grosser isl/isl_box.c 209519b3cfdSMichael Kruse isl/isl_coalesce.c 210519b3cfdSMichael Kruse isl/isl_constraint.c 211519b3cfdSMichael Kruse isl/isl_convex_hull.c 212519b3cfdSMichael Kruse isl/isl_ctx.c 213519b3cfdSMichael Kruse isl/isl_deprecated.c 214519b3cfdSMichael Kruse isl/isl_dim_map.c 215519b3cfdSMichael Kruse isl/isl_equalities.c 216519b3cfdSMichael Kruse isl/isl_factorization.c 217519b3cfdSMichael Kruse isl/isl_farkas.c 218519b3cfdSMichael Kruse isl/isl_ffs.c 219519b3cfdSMichael Kruse isl/isl_flow.c 220519b3cfdSMichael Kruse isl/isl_fold.c 221519b3cfdSMichael Kruse isl/isl_hash.c 222519b3cfdSMichael Kruse isl/isl_id.c 223519b3cfdSMichael Kruse isl/isl_id_to_ast_expr.c 224a67ac976STobias Grosser isl/isl_id_to_id.c 225519b3cfdSMichael Kruse isl/isl_id_to_pw_aff.c 226519b3cfdSMichael Kruse isl/isl_ilp.c 227519b3cfdSMichael Kruse isl/isl_imath.c 228519b3cfdSMichael Kruse isl/isl_input.c 229519b3cfdSMichael Kruse isl/isl_int_sioimath.c 23037034db8STobias Grosser isl/isl_local.c 231519b3cfdSMichael Kruse isl/isl_local_space.c 232519b3cfdSMichael Kruse isl/isl_lp.c 233519b3cfdSMichael Kruse isl/isl_map.c 234519b3cfdSMichael Kruse isl/isl_map_list.c 235519b3cfdSMichael Kruse isl/isl_map_simplify.c 236519b3cfdSMichael Kruse isl/isl_map_subtract.c 237519b3cfdSMichael Kruse isl/isl_map_to_basic_set.c 238519b3cfdSMichael Kruse isl/isl_mat.c 239519b3cfdSMichael Kruse isl/isl_morph.c 240519b3cfdSMichael Kruse isl/isl_obj.c 241519b3cfdSMichael Kruse isl/isl_options.c 242519b3cfdSMichael Kruse isl/isl_output.c 243519b3cfdSMichael Kruse isl/isl_point.c 244519b3cfdSMichael Kruse isl/isl_polynomial.c 245519b3cfdSMichael Kruse isl/isl_printer.c 246519b3cfdSMichael Kruse isl/isl_range.c 247519b3cfdSMichael Kruse isl/isl_reordering.c 248519b3cfdSMichael Kruse isl/isl_sample.c 249519b3cfdSMichael Kruse isl/isl_scan.c 250519b3cfdSMichael Kruse isl/isl_schedule.c 251519b3cfdSMichael Kruse isl/isl_schedule_band.c 2525652c9c8STobias Grosser isl/isl_schedule_constraints.c 253519b3cfdSMichael Kruse isl/isl_schedule_node.c 254519b3cfdSMichael Kruse isl/isl_schedule_read.c 255519b3cfdSMichael Kruse isl/isl_schedule_tree.c 256519b3cfdSMichael Kruse isl/isl_scheduler.c 257a749e09eSMichael Kruse isl/isl_scheduler_clustering.c 258a749e09eSMichael Kruse isl/isl_scheduler_scc.c 259519b3cfdSMichael Kruse isl/isl_seq.c 260519b3cfdSMichael Kruse isl/isl_set_list.c 261e8227804SMichael Kruse isl/isl_set_to_ast_graft_list.c 262519b3cfdSMichael Kruse isl/isl_sort.c 263519b3cfdSMichael Kruse isl/isl_space.c 264fa8079d0STobias Grosser isl/isl_stride.c 265519b3cfdSMichael Kruse isl/isl_stream.c 266519b3cfdSMichael Kruse isl/isl_tab.c 267519b3cfdSMichael Kruse isl/isl_tab_pip.c 268519b3cfdSMichael Kruse isl/isl_tarjan.c 269519b3cfdSMichael Kruse isl/isl_transitive_closure.c 270519b3cfdSMichael Kruse isl/isl_union_map.c 271519b3cfdSMichael Kruse isl/isl_val.c 272519b3cfdSMichael Kruse isl/isl_val_sioimath.c 273519b3cfdSMichael Kruse isl/isl_vec.c 274519b3cfdSMichael Kruse isl/isl_version.c 275519b3cfdSMichael Kruse isl/isl_vertices.c 276519b3cfdSMichael Kruse isl/print.c 2776135b0feSTobias Grosser isl/set_to_map.c 2786135b0feSTobias Grosser isl/set_from_map.c 2796135b0feSTobias Grosser isl/uset_to_umap.c 2806135b0feSTobias Grosser isl/uset_from_umap.c 281519b3cfdSMichael Kruse isl/imath/gmp_compat.c 282519b3cfdSMichael Kruse isl/imath/imath.c 283519b3cfdSMichael Kruse isl/imath/imrat.c 284519b3cfdSMichael Kruse ) 285519b3cfdSMichael Kruse 286e5e752a2SMichael Kruse add_polly_library(PollyISL 287519b3cfdSMichael Kruse ${ISL_FILES} 288519b3cfdSMichael Kruse ) 289519b3cfdSMichael Kruse 2905ab24fdbSMichael Kruse 2915ab24fdbSMichael Kruse if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) 2925ab24fdbSMichael Kruse install(DIRECTORY 2935ab24fdbSMichael Kruse ${ISL_SOURCE_DIR}/include/ 2945ab24fdbSMichael Kruse ${ISL_BINARY_DIR}/include/ 295d3b756c5SJohn Ericson DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/polly" 2965ab24fdbSMichael Kruse FILES_MATCHING 2975ab24fdbSMichael Kruse PATTERN "*.h" 2985ab24fdbSMichael Kruse PATTERN "CMakeFiles" EXCLUDE 2995ab24fdbSMichael Kruse ) 3005ab24fdbSMichael Kruse endif() 3015ab24fdbSMichael Kruse 302e84ee850STobias Grosser add_executable(polly-isl-test 303e84ee850STobias Grosser isl/isl_test.c 304e84ee850STobias Grosser ) 305*c16538feSMichael Kruse set_target_properties(polly-isl-test PROPERTIES FOLDER "Polly/Tests") 306e84ee850STobias Grosser 30721de8adcSMichael Kruse target_link_libraries(polly-isl-test PRIVATE 308e84ee850STobias Grosser PollyISL 309b9512399Svient LLVMSupport 310e84ee850STobias Grosser ) 311e84ee850STobias Grosser 312519b3cfdSMichael Kruse # ISL requires at least C99 to compile. gcc < 5.0 use -std=gnu89 as default. 313098130faSRaul Tambre set_property(TARGET PollyISL polly-isl-test PROPERTY C_STANDARD 99) 3146048d1d1SMichael Kruse 3156048d1d1SMichael Kruse target_compile_options(PollyISL PRIVATE ${DISABLE_WARNING_FLAGS}) 3166048d1d1SMichael Kruse target_compile_options(polly-isl-test PRIVATE ${DISABLE_WARNING_FLAGS}) 3176469380dSMichael Kruseendif (POLLY_BUNDLED_ISL) 318