• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1include(LLVMProcessSources)
2include(LLVM-Config)
3
4macro(add_llvm_library name)
5  llvm_process_sources( ALL_FILES ${ARGN} )
6  add_library( ${name} ${ALL_FILES} )
7  set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
8  if( LLVM_COMMON_DEPENDS )
9    add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
10  endif( LLVM_COMMON_DEPENDS )
11
12  if( BUILD_SHARED_LIBS )
13    llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
14  endif()
15
16  # Ensure that the system libraries always comes last on the
17  # list. Without this, linking the unit tests on MinGW fails.
18  link_system_libs( ${name} )
19
20  if( EXCLUDE_FROM_ALL )
21    set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
22  else()
23    install(TARGETS ${name}
24      LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
25      ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
26  endif()
27  # The LLVM Target library shall be built before its sublibraries
28  # (asmprinter, etc) because those may use tablegenned files which
29  # generation is triggered by the main LLVM target library. Necessary
30  # for parallel builds:
31  if( CURRENT_LLVM_TARGET )
32    add_dependencies(${name} ${CURRENT_LLVM_TARGET})
33  endif()
34  set_target_properties(${name} PROPERTIES FOLDER "Libraries")
35endmacro(add_llvm_library name)
36
37
38macro(add_llvm_loadable_module name)
39  if( NOT LLVM_ON_UNIX OR CYGWIN )
40    message(STATUS "Loadable modules not supported on this platform.
41${name} ignored.")
42    # Add empty "phony" target
43    add_custom_target(${name})
44  else()
45    llvm_process_sources( ALL_FILES ${ARGN} )
46    if (MODULE)
47      set(libkind MODULE)
48    else()
49      set(libkind SHARED)
50    endif()
51
52    add_library( ${name} ${libkind} ${ALL_FILES} )
53    set_target_properties( ${name} PROPERTIES PREFIX "" )
54
55    llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
56    link_system_libs( ${name} )
57
58    if (APPLE)
59      # Darwin-specific linker flags for loadable modules.
60      set_target_properties(${name} PROPERTIES
61        LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
62    endif()
63
64    if( EXCLUDE_FROM_ALL )
65      set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
66    else()
67      install(TARGETS ${name}
68	LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
69	ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
70    endif()
71  endif()
72
73  set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
74endmacro(add_llvm_loadable_module name)
75
76
77macro(add_llvm_executable name)
78  llvm_process_sources( ALL_FILES ${ARGN} )
79  if( EXCLUDE_FROM_ALL )
80    add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
81  else()
82    add_executable(${name} ${ALL_FILES})
83  endif()
84  set(EXCLUDE_FROM_ALL OFF)
85  target_link_libraries( ${name} ${LLVM_USED_LIBS} )
86  llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
87  if( LLVM_COMMON_DEPENDS )
88    add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
89  endif( LLVM_COMMON_DEPENDS )
90  link_system_libs( ${name} )
91endmacro(add_llvm_executable name)
92
93
94macro(add_llvm_tool name)
95  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
96  if( NOT LLVM_BUILD_TOOLS )
97    set(EXCLUDE_FROM_ALL ON)
98  endif()
99  add_llvm_executable(${name} ${ARGN})
100  if( LLVM_BUILD_TOOLS )
101    install(TARGETS ${name} RUNTIME DESTINATION bin)
102  endif()
103  set_target_properties(${name} PROPERTIES FOLDER "Tools")
104endmacro(add_llvm_tool name)
105
106
107macro(add_llvm_example name)
108#  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR})
109  if( NOT LLVM_BUILD_EXAMPLES )
110    set(EXCLUDE_FROM_ALL ON)
111  endif()
112  add_llvm_executable(${name} ${ARGN})
113  if( LLVM_BUILD_EXAMPLES )
114    install(TARGETS ${name} RUNTIME DESTINATION examples)
115  endif()
116  set_target_properties(${name} PROPERTIES FOLDER "Examples")
117endmacro(add_llvm_example name)
118
119
120macro(add_llvm_utility name)
121  add_llvm_executable(${name} ${ARGN})
122  set_target_properties(${name} PROPERTIES FOLDER "Utils")
123endmacro(add_llvm_utility name)
124
125
126macro(add_llvm_target target_name)
127  if( TABLEGEN_OUTPUT )
128    add_custom_target(${target_name}Table_gen
129      DEPENDS ${TABLEGEN_OUTPUT})
130    add_dependencies(${target_name}Table_gen ${LLVM_COMMON_DEPENDS})
131  endif( TABLEGEN_OUTPUT )
132  include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
133  add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT})
134  if ( TABLEGEN_OUTPUT )
135    add_dependencies(LLVM${target_name} ${target_name}Table_gen)
136    set_target_properties(${target_name}Table_gen PROPERTIES FOLDER "Tablegenning")
137  endif (TABLEGEN_OUTPUT)
138  set( CURRENT_LLVM_TARGET LLVM${target_name} )
139endmacro(add_llvm_target)
140