Remove yet another buried and hidden implicit dependency: every single
[oota-llvm.git] / cmake / modules / AddLLVM.cmake
1 include(LLVMProcessSources)
2 include(LLVM-Config)
3
4 macro(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   set_target_properties(${name} PROPERTIES FOLDER "Libraries")
28 endmacro(add_llvm_library name)
29
30 macro(add_llvm_library_dependencies name)
31   # Save the dependencies of the LLVM library in a variable so that we can
32   # query it when resolve llvm-config-style component -> library mappings.
33   set_property(GLOBAL PROPERTY LLVM_LIB_DEPS_${name} ${ARGN})
34
35   # Then add the actual dependencies to the library target.
36   target_link_libraries(${name} ${ARGN})
37 endmacro(add_llvm_library_dependencies name)
38
39 macro(add_llvm_loadable_module name)
40   if( NOT LLVM_ON_UNIX OR CYGWIN )
41     message(STATUS "Loadable modules not supported on this platform.
42 ${name} ignored.")
43     # Add empty "phony" target
44     add_custom_target(${name})
45   else()
46     llvm_process_sources( ALL_FILES ${ARGN} )
47     if (MODULE)
48       set(libkind MODULE)
49     else()
50       set(libkind SHARED)
51     endif()
52
53     add_library( ${name} ${libkind} ${ALL_FILES} )
54     set_target_properties( ${name} PROPERTIES PREFIX "" )
55
56     llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
57     link_system_libs( ${name} )
58
59     if (APPLE)
60       # Darwin-specific linker flags for loadable modules.
61       set_target_properties(${name} PROPERTIES
62         LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
63     endif()
64
65     if( EXCLUDE_FROM_ALL )
66       set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
67     else()
68       install(TARGETS ${name}
69         LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
70         ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
71     endif()
72   endif()
73
74   set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
75 endmacro(add_llvm_loadable_module name)
76
77
78 macro(add_llvm_executable name)
79   llvm_process_sources( ALL_FILES ${ARGN} )
80   if( EXCLUDE_FROM_ALL )
81     add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
82   else()
83     add_executable(${name} ${ALL_FILES})
84   endif()
85   set(EXCLUDE_FROM_ALL OFF)
86   target_link_libraries( ${name} ${LLVM_USED_LIBS} )
87   llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
88   if( LLVM_COMMON_DEPENDS )
89     add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
90   endif( LLVM_COMMON_DEPENDS )
91   link_system_libs( ${name} )
92 endmacro(add_llvm_executable name)
93
94
95 macro(add_llvm_tool name)
96   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
97   if( NOT LLVM_BUILD_TOOLS )
98     set(EXCLUDE_FROM_ALL ON)
99   endif()
100   add_llvm_executable(${name} ${ARGN})
101   if( LLVM_BUILD_TOOLS )
102     install(TARGETS ${name} RUNTIME DESTINATION bin)
103   endif()
104   set_target_properties(${name} PROPERTIES FOLDER "Tools")
105 endmacro(add_llvm_tool name)
106
107
108 macro(add_llvm_example name)
109 #  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR})
110   if( NOT LLVM_BUILD_EXAMPLES )
111     set(EXCLUDE_FROM_ALL ON)
112   endif()
113   add_llvm_executable(${name} ${ARGN})
114   if( LLVM_BUILD_EXAMPLES )
115     install(TARGETS ${name} RUNTIME DESTINATION examples)
116   endif()
117   set_target_properties(${name} PROPERTIES FOLDER "Examples")
118 endmacro(add_llvm_example name)
119
120
121 macro(add_llvm_utility name)
122   add_llvm_executable(${name} ${ARGN})
123   set_target_properties(${name} PROPERTIES FOLDER "Utils")
124 endmacro(add_llvm_utility name)
125
126
127 macro(add_llvm_target target_name)
128   include_directories(BEFORE
129     ${CMAKE_CURRENT_BINARY_DIR}
130     ${CMAKE_CURRENT_SOURCE_DIR})
131   add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT})
132   set( CURRENT_LLVM_TARGET LLVM${target_name} )
133 endmacro(add_llvm_target)