Tobias Grosser | bc822eb | 2012-10-21 15:51:49 | [diff] [blame] | 1 | |
Michael Kruse | 519b3cf | 2015-09-24 11:30:22 | [diff] [blame] | 2 | include(CMakeParseArguments) |
| 3 | |
Tobias Grosser | bc822eb | 2012-10-21 15:51:49 | [diff] [blame] | 4 | macro(add_polly_library name) |
Michael Kruse | e5e752a | 2016-09-12 18:25:00 | [diff] [blame] | 5 | cmake_parse_arguments(ARG "" "" "" ${ARGN}) |
Michael Kruse | 519b3cf | 2015-09-24 11:30:22 | [diff] [blame] | 6 | set(srcs ${ARG_UNPARSED_ARGUMENTS}) |
Tobias Grosser | bc822eb | 2012-10-21 15:51:49 | [diff] [blame] | 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} ) |
Michael Kruse | 6362f5a | 2015-07-21 12:40:01 | [diff] [blame] | 24 | set_target_properties(${name} PROPERTIES FOLDER "Polly") |
| 25 | |
Tobias Grosser | bc822eb | 2012-10-21 15:51:49 | [diff] [blame] | 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}) |
Michael Kruse | 21de8ad | 2018-01-12 16:09:18 | [diff] [blame] | 31 | target_link_libraries( ${name} PUBLIC ${lib} ) |
Tobias Grosser | bc822eb | 2012-10-21 15:51:49 | [diff] [blame] | 32 | endforeach(lib) |
| 33 | endif( LLVM_USED_LIBS ) |
| 34 | |
Sebastian Pop | a8fb724 | 2014-03-13 20:24:48 | [diff] [blame] | 35 | if(POLLY_LINK_LIBS) |
| 36 | foreach(lib ${POLLY_LINK_LIBS}) |
Michael Kruse | 21de8ad | 2018-01-12 16:09:18 | [diff] [blame] | 37 | target_link_libraries(${name} PUBLIC ${lib}) |
Sebastian Pop | a8fb724 | 2014-03-13 20:24:48 | [diff] [blame] | 38 | endforeach(lib) |
| 39 | endif(POLLY_LINK_LIBS) |
Tobias Grosser | bc822eb | 2012-10-21 15:51:49 | [diff] [blame] | 40 | |
| 41 | if( LLVM_LINK_COMPONENTS ) |
| 42 | llvm_config(${name} ${LLVM_LINK_COMPONENTS}) |
| 43 | endif( LLVM_LINK_COMPONENTS ) |
Eugene Zelenko | 2487cb2 | 2016-06-21 18:14:01 | [diff] [blame] | 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() |
Tobias Grosser | 65b2b03 | 2014-11-30 12:45:44 | [diff] [blame] | 50 | set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) |
Tobias Grosser | bc822eb | 2012-10-21 15:51:49 | [diff] [blame] | 51 | endmacro(add_polly_library) |
| 52 | |
| 53 | macro(add_polly_loadable_module name) |
| 54 | set(srcs ${ARGN}) |
Tobias Grosser | 23f16b1 | 2014-03-03 19:30:19 | [diff] [blame] | 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) |
Tobias Grosser | bc822eb | 2012-10-21 15:51:49 | [diff] [blame] | 63 | add_polly_library(${name} ${srcs}) |
Michael Kruse | 6362f5a | 2015-07-21 12:40:01 | [diff] [blame] | 64 | set_target_properties(${name} PROPERTIES FOLDER "Polly") |
Tobias Grosser | 23f16b1 | 2014-03-03 19:30:19 | [diff] [blame] | 65 | if (GLOBAL_NOT_MODULE) |
| 66 | unset (MODULE) |
| 67 | endif() |
Tobias Grosser | bc822eb | 2012-10-21 15:51:49 | [diff] [blame] | 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() |
| 73 | endmacro(add_polly_loadable_module) |
Michael Kruse | f228550 | 2015-06-22 20:31:16 | [diff] [blame] | 74 | |
Michael Kruse | acc9ad5 | 2015-06-29 19:57:59 | [diff] [blame] | 75 | # Use C99-compatible compile mode for all C source files of a target. |
Michael Kruse | f228550 | 2015-06-22 20:31:16 | [diff] [blame] | 76 | function(target_enable_c99 _target) |
| 77 | if(CMAKE_VERSION VERSION_GREATER "3.1") |
| 78 | set_target_properties("${_target}" PROPERTIES C_STANDARD 99) |
| 79 | elseif(CMAKE_COMPILER_IS_GNUCC) |
| 80 | get_target_property(_sources "${_target}" SOURCES) |
Michael Kruse | acc9ad5 | 2015-06-29 19:57:59 | [diff] [blame] | 81 | foreach(_file IN LISTS _sources) |
| 82 | get_source_file_property(_lang "${_file}" LANGUAGE) |
| 83 | if(_lang STREQUAL "C") |
| 84 | set_source_files_properties(${_file} COMPILE_FLAGS "-std=gnu99") |
| 85 | endif() |
| 86 | endforeach() |
Michael Kruse | f228550 | 2015-06-22 20:31:16 | [diff] [blame] | 87 | endif() |
| 88 | endfunction() |