annotate polly/cmake/polly_macros.cmake @ 240:ca573705d418

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