1 2include(CMakeParseArguments) 3 4macro(add_polly_library name) 5 cmake_parse_arguments(ARG "" "" "" ${ARGN}) 6 set(srcs ${ARG_UNPARSED_ARGUMENTS}) 7 if(MSVC_IDE OR XCODE) 8 file( GLOB_RECURSE headers *.h *.td *.def) 9 set(srcs ${srcs} ${headers}) 10 string( REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR}) 11 list( GET split_path -1 dir) 12 file( GLOB_RECURSE headers 13 ../../include/polly${dir}/*.h) 14 set(srcs ${srcs} ${headers}) 15 endif(MSVC_IDE OR XCODE) 16 if (MODULE) 17 set(libkind MODULE) 18 elseif (SHARED_LIBRARY) 19 set(libkind SHARED) 20 else() 21 set(libkind) 22 endif() 23 add_library( ${name} ${libkind} ${srcs} ) 24 set_target_properties(${name} PROPERTIES FOLDER "Polly") 25 26 if( LLVM_COMMON_DEPENDS ) 27 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) 28 endif( LLVM_COMMON_DEPENDS ) 29 if( LLVM_USED_LIBS ) 30 foreach(lib ${LLVM_USED_LIBS}) 31 target_link_libraries( ${name} PUBLIC ${lib} ) 32 endforeach(lib) 33 endif( LLVM_USED_LIBS ) 34 35 if(POLLY_LINK_LIBS) 36 foreach(lib ${POLLY_LINK_LIBS}) 37 target_link_libraries(${name} PUBLIC ${lib}) 38 endforeach(lib) 39 endif(POLLY_LINK_LIBS) 40 41 if( LLVM_LINK_COMPONENTS ) 42 llvm_config(${name} ${LLVM_LINK_COMPONENTS}) 43 endif( LLVM_LINK_COMPONENTS ) 44 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") 45 install(TARGETS ${name} 46 EXPORT LLVMExports 47 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} 48 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) 49 endif() 50 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) 51endmacro(add_polly_library) 52 53macro(add_polly_loadable_module name) 54 set(srcs ${ARGN}) 55 # klduge: pass different values for MODULE with multiple targets in same dir 56 # this allows building shared-lib and module in same dir 57 # there must be a cleaner way to achieve this.... 58 if (MODULE) 59 else() 60 set(GLOBAL_NOT_MODULE TRUE) 61 endif() 62 set(MODULE TRUE) 63 add_polly_library(${name} ${srcs}) 64 set_target_properties(${name} PROPERTIES FOLDER "Polly") 65 if (GLOBAL_NOT_MODULE) 66 unset (MODULE) 67 endif() 68 if (APPLE) 69 # Darwin-specific linker flags for loadable modules. 70 set_target_properties(${name} PROPERTIES 71 LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress") 72 endif() 73endmacro(add_polly_loadable_module) 74 75# Recursive helper for setup_source_group. Traverse the file system and add 76# source files matching the glob_expr to the prefix, recursing into 77# subdirectories as they are encountered 78function(setup_polly_source_groups_helper pwd prefix glob_expr) 79 file(GLOB children RELATIVE ${pwd} ${pwd}/*) 80 foreach(child ${children}) 81 if (IS_DIRECTORY ${pwd}/${child}) 82 setup_polly_source_groups_helper(${pwd}/${child} 83 "${prefix}\\${child}" ${glob_expr}) 84 endif() 85 endforeach() 86 87 file(GLOB to_add ${pwd}/${glob_expr}) 88 source_group(${prefix} FILES ${to_add}) 89endfunction(setup_polly_source_groups_helper) 90 91# Set up source groups in order to nicely organize source files in IDEs 92macro(setup_polly_source_groups src_root hdr_root) 93 # FIXME: The helper can be eliminated if the CMake version is increased 94 # to 3.8 or higher. If this is done, the TREE version of source_group can 95 # be used 96 setup_polly_source_groups_helper(${src_root} "Source Files" "*.cpp") 97 setup_polly_source_groups_helper(${hdr_root} "Header Files" "*.h") 98endmacro(setup_polly_source_groups) 99