Fixed the build of Clang's unit tests on MinGW. Also removed some
[oota-llvm.git] / cmake / modules / AddLLVM.cmake
1 include(LLVMProcessSources)
2 include(LLVMConfig)
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   install(TARGETS ${name}
21     LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
22     ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
23   # The LLVM Target library shall be built before its sublibraries
24   # (asmprinter, etc) because those may use tablegenned files which
25   # generation is triggered by the main LLVM target library. Necessary
26   # for parallel builds:
27   if( CURRENT_LLVM_TARGET )
28     add_dependencies(${name} ${CURRENT_LLVM_TARGET})
29   endif()
30   set_target_properties(${name} PROPERTIES FOLDER "Libraries")
31 endmacro(add_llvm_library name)
32
33
34 macro(add_llvm_loadable_module name)
35   if( NOT LLVM_ON_UNIX OR CYGWIN )
36     message(STATUS "Loadable modules not supported on this platform.
37 ${name} ignored.")
38     # Add empty "phony" target
39     add_custom_target(${name})
40   else()
41     llvm_process_sources( ALL_FILES ${ARGN} )
42     if (MODULE)
43       set(libkind MODULE)
44     else()
45       set(libkind SHARED)
46     endif()
47
48     add_library( ${name} ${libkind} ${ALL_FILES} )
49     set_target_properties( ${name} PROPERTIES PREFIX "" )
50
51     llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
52     link_system_libs( ${name} )
53
54     if (APPLE)
55       # Darwin-specific linker flags for loadable modules.
56       set_target_properties(${name} PROPERTIES
57         LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
58     endif()
59
60     install(TARGETS ${name}
61       LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
62       ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
63   endif()
64
65   set_target_properties(${name} PROPERTIES FOLDER "Loadable modules")
66 endmacro(add_llvm_loadable_module name)
67
68
69 macro(add_llvm_executable name)
70   llvm_process_sources( ALL_FILES ${ARGN} )
71   if( EXCLUDE_FROM_ALL )
72     add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
73   else()
74     add_executable(${name} ${ALL_FILES})
75   endif()
76   set(EXCLUDE_FROM_ALL OFF)
77   target_link_libraries( ${name} ${LLVM_USED_LIBS} )
78   llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
79   if( LLVM_COMMON_DEPENDS )
80     add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
81   endif( LLVM_COMMON_DEPENDS )
82   link_system_libs( ${name} )
83 endmacro(add_llvm_executable name)
84
85
86 macro(add_llvm_tool name)
87   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR})
88   if( NOT LLVM_BUILD_TOOLS )
89     set(EXCLUDE_FROM_ALL ON)
90   endif()
91   add_llvm_executable(${name} ${ARGN})
92   if( LLVM_BUILD_TOOLS )
93     install(TARGETS ${name} RUNTIME DESTINATION bin)
94   endif()
95   set_target_properties(${name} PROPERTIES FOLDER "Tools")
96 endmacro(add_llvm_tool name)
97
98
99 macro(add_llvm_example name)
100 #  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR})
101   if( NOT LLVM_BUILD_EXAMPLES )
102     set(EXCLUDE_FROM_ALL ON)
103   endif()
104   add_llvm_executable(${name} ${ARGN})
105   if( LLVM_BUILD_EXAMPLES )
106     install(TARGETS ${name} RUNTIME DESTINATION examples)
107   endif()
108   set_target_properties(${name} PROPERTIES FOLDER "Examples")
109 endmacro(add_llvm_example name)
110
111
112 macro(add_llvm_utility name)
113   add_llvm_executable(${name} ${ARGN})
114   set_target_properties(${name} PROPERTIES FOLDER "Utils")
115 endmacro(add_llvm_utility name)
116
117
118 macro(add_llvm_target target_name)
119   if( TABLEGEN_OUTPUT )
120     add_custom_target(${target_name}Table_gen
121       DEPENDS ${TABLEGEN_OUTPUT})
122     add_dependencies(${target_name}Table_gen ${LLVM_COMMON_DEPENDS})
123   endif( TABLEGEN_OUTPUT )
124   include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
125   add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT})
126   if ( TABLEGEN_OUTPUT )
127     add_dependencies(LLVM${target_name} ${target_name}Table_gen)
128     set_target_properties(${target_name}Table_gen PROPERTIES FOLDER "Tablegenning")
129   endif (TABLEGEN_OUTPUT)
130   set( CURRENT_LLVM_TARGET LLVM${target_name} )
131 endmacro(add_llvm_target)