2 include(CMakeParseArguments)
4 macro(add_polly_library name)
5 cmake_parse_arguments(ARG "FORCE_STATIC" "" "" ${ARGN})
6 set(srcs ${ARG_UNPARSED_ARGUMENTS})
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)
18 elseif (ARG_FORCE_STATIC)
20 elseif (SHARED_LIBRARY)
25 add_library( ${name} ${libkind} ${srcs} )
26 set_target_properties(${name} PROPERTIES FOLDER "Polly")
28 if( LLVM_COMMON_DEPENDS )
29 add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
30 endif( LLVM_COMMON_DEPENDS )
32 foreach(lib ${LLVM_USED_LIBS})
33 target_link_libraries( ${name} ${lib} )
35 endif( LLVM_USED_LIBS )
38 foreach(lib ${POLLY_LINK_LIBS})
39 target_link_libraries(${name} ${lib})
41 endif(POLLY_LINK_LIBS)
43 if( LLVM_LINK_COMPONENTS )
44 llvm_config(${name} ${LLVM_LINK_COMPONENTS})
45 endif( LLVM_LINK_COMPONENTS )
46 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly")
47 install(TARGETS ${name}
49 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
50 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
52 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
53 endmacro(add_polly_library)
55 macro(add_polly_loadable_module name)
57 # klduge: pass different values for MODULE with multiple targets in same dir
58 # this allows building shared-lib and module in same dir
59 # there must be a cleaner way to achieve this....
62 set(GLOBAL_NOT_MODULE TRUE)
65 add_polly_library(${name} ${srcs})
66 set_target_properties(${name} PROPERTIES FOLDER "Polly")
67 if (GLOBAL_NOT_MODULE)
71 # Darwin-specific linker flags for loadable modules.
72 set_target_properties(${name} PROPERTIES
73 LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
75 endmacro(add_polly_loadable_module)
77 # Use C99-compatible compile mode for all C source files of a target.
78 function(target_enable_c99 _target)
79 if(CMAKE_VERSION VERSION_GREATER "3.1")
80 set_target_properties("${_target}" PROPERTIES C_STANDARD 99)
81 elseif(CMAKE_COMPILER_IS_GNUCC)
82 get_target_property(_sources "${_target}" SOURCES)
83 foreach(_file IN LISTS _sources)
84 get_source_file_property(_lang "${_file}" LANGUAGE)
85 if(_lang STREQUAL "C")
86 set_source_files_properties(${_file} COMPILE_FLAGS "-std=gnu99")