Oscar Fuentes | 1bbdd46 | 2008-11-14 22:06:14 +0000 | [diff] [blame] | 1 | include(LLVMProcessSources) |
Michael J. Spencer | 3a210e2 | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 2 | include(LLVMConfig) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 3 | |
| 4 | macro(add_llvm_library name) |
Oscar Fuentes | 50925fb | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 5 | llvm_process_sources( ALL_FILES ${ARGN} ) |
| 6 | add_library( ${name} ${ALL_FILES} ) |
Oscar Fuentes | 6d857ca | 2011-02-18 22:06:14 +0000 | [diff] [blame] | 7 | set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} ) |
Oscar Fuentes | 1d8e4cf | 2008-09-22 18:21:51 +0000 | [diff] [blame] | 8 | if( LLVM_COMMON_DEPENDS ) |
| 9 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 10 | endif( LLVM_COMMON_DEPENDS ) |
Oscar Fuentes | 00a9618 | 2010-10-14 15:54:41 +0000 | [diff] [blame] | 11 | |
| 12 | if( BUILD_SHARED_LIBS ) |
| 13 | get_system_libs(sl) |
| 14 | target_link_libraries( ${name} ${sl} ) |
| 15 | endif() |
| 16 | |
Oscar Fuentes | 1dc9716 | 2008-10-22 02:56:07 +0000 | [diff] [blame] | 17 | install(TARGETS ${name} |
Oscar Fuentes | af0f65f | 2009-06-12 02:49:53 +0000 | [diff] [blame] | 18 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 19 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
Oscar Fuentes | b78829e | 2009-08-16 05:16:43 +0000 | [diff] [blame] | 20 | # The LLVM Target library shall be built before its sublibraries |
| 21 | # (asmprinter, etc) because those may use tablegenned files which |
| 22 | # generation is triggered by the main LLVM target library. Necessary |
| 23 | # for parallel builds: |
| 24 | if( CURRENT_LLVM_TARGET ) |
Benjamin Kramer | 0bbbf7e | 2009-08-16 09:44:27 +0000 | [diff] [blame] | 25 | add_dependencies(${name} ${CURRENT_LLVM_TARGET}) |
Oscar Fuentes | b78829e | 2009-08-16 05:16:43 +0000 | [diff] [blame] | 26 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 27 | set_target_properties(${name} PROPERTIES FOLDER "Libraries") |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 28 | endmacro(add_llvm_library name) |
| 29 | |
| 30 | |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 31 | macro(add_llvm_loadable_module name) |
Oscar Fuentes | 01a575e | 2010-10-22 19:03:24 +0000 | [diff] [blame] | 32 | if( NOT LLVM_ON_UNIX OR CYGWIN ) |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 33 | message(STATUS "Loadable modules not supported on this platform. |
| 34 | ${name} ignored.") |
NAKAMURA Takumi | 51c06bf | 2010-12-10 02:15:36 +0000 | [diff] [blame] | 35 | # Add empty "phony" target |
| 36 | add_custom_target(${name}) |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 37 | else() |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 38 | llvm_process_sources( ALL_FILES ${ARGN} ) |
Oscar Fuentes | 7110428 | 2010-12-22 08:30:17 +0000 | [diff] [blame] | 39 | if (MODULE) |
| 40 | set(libkind MODULE) |
| 41 | else() |
| 42 | set(libkind SHARED) |
| 43 | endif() |
| 44 | |
| 45 | add_library( ${name} ${libkind} ${ALL_FILES} ) |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 46 | set_target_properties( ${name} PROPERTIES PREFIX "" ) |
Douglas Gregor | 8781416 | 2009-11-10 15:30:33 +0000 | [diff] [blame] | 47 | |
| 48 | if (APPLE) |
| 49 | # Darwin-specific linker flags for loadable modules. |
| 50 | set_target_properties(${name} PROPERTIES |
| 51 | LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress") |
| 52 | endif() |
| 53 | |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 54 | install(TARGETS ${name} |
| 55 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 56 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
| 57 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 58 | |
| 59 | set_target_properties(${name} PROPERTIES FOLDER "Loadable modules") |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 60 | endmacro(add_llvm_loadable_module name) |
| 61 | |
| 62 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 63 | macro(add_llvm_executable name) |
Oscar Fuentes | 50925fb | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 64 | llvm_process_sources( ALL_FILES ${ARGN} ) |
Oscar Fuentes | b8352de | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 65 | if( EXCLUDE_FROM_ALL ) |
| 66 | add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES}) |
| 67 | else() |
| 68 | add_executable(${name} ${ALL_FILES}) |
| 69 | endif() |
| 70 | set(EXCLUDE_FROM_ALL OFF) |
Oscar Fuentes | bcc1db5 | 2008-10-26 00:51:05 +0000 | [diff] [blame] | 71 | if( LLVM_USED_LIBS ) |
| 72 | foreach(lib ${LLVM_USED_LIBS}) |
| 73 | target_link_libraries( ${name} ${lib} ) |
| 74 | endforeach(lib) |
| 75 | endif( LLVM_USED_LIBS ) |
Michael J. Spencer | 3a210e2 | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 76 | if( LLVM_LINK_COMPONENTS ) |
| 77 | llvm_config(${name} ${LLVM_LINK_COMPONENTS}) |
| 78 | endif( LLVM_LINK_COMPONENTS ) |
Oscar Fuentes | d8b1b9a | 2009-08-14 04:38:57 +0000 | [diff] [blame] | 79 | if( LLVM_COMMON_DEPENDS ) |
| 80 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 81 | endif( LLVM_COMMON_DEPENDS ) |
Michael J. Spencer | 1c4e934 | 2010-09-11 02:13:39 +0000 | [diff] [blame] | 82 | if( NOT MINGW ) |
| 83 | get_system_libs(llvm_system_libs) |
| 84 | if( llvm_system_libs ) |
| 85 | target_link_libraries(${name} ${llvm_system_libs}) |
| 86 | endif() |
| 87 | endif() |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 88 | endmacro(add_llvm_executable name) |
| 89 | |
| 90 | |
| 91 | macro(add_llvm_tool name) |
| 92 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 93 | if( NOT LLVM_BUILD_TOOLS ) |
Oscar Fuentes | b8352de | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 94 | set(EXCLUDE_FROM_ALL ON) |
| 95 | endif() |
Oscar Fuentes | 066de85 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 96 | add_llvm_executable(${name} ${ARGN}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 97 | if( LLVM_BUILD_TOOLS ) |
| 98 | install(TARGETS ${name} RUNTIME DESTINATION bin) |
| 99 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 100 | set_target_properties(${name} PROPERTIES FOLDER "Tools") |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 101 | endmacro(add_llvm_tool name) |
| 102 | |
| 103 | |
| 104 | macro(add_llvm_example name) |
| 105 | # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 106 | if( NOT LLVM_BUILD_EXAMPLES ) |
Oscar Fuentes | b8352de | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 107 | set(EXCLUDE_FROM_ALL ON) |
| 108 | endif() |
Oscar Fuentes | 066de85 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 109 | add_llvm_executable(${name} ${ARGN}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 110 | if( LLVM_BUILD_EXAMPLES ) |
| 111 | install(TARGETS ${name} RUNTIME DESTINATION examples) |
| 112 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 113 | set_target_properties(${name} PROPERTIES FOLDER "Examples") |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 114 | endmacro(add_llvm_example name) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 115 | |
| 116 | |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 117 | macro(add_llvm_utility name) |
| 118 | add_llvm_executable(${name} ${ARGN}) |
| 119 | set_target_properties(${name} PROPERTIES FOLDER "Utils") |
| 120 | endmacro(add_llvm_utility name) |
| 121 | |
| 122 | |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 123 | macro(add_llvm_target target_name) |
| 124 | if( TABLEGEN_OUTPUT ) |
| 125 | add_custom_target(${target_name}Table_gen |
| 126 | DEPENDS ${TABLEGEN_OUTPUT}) |
| 127 | add_dependencies(${target_name}Table_gen ${LLVM_COMMON_DEPENDS}) |
| 128 | endif( TABLEGEN_OUTPUT ) |
| 129 | include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) |
Douglas Gregor | 7e9e36a | 2009-06-23 17:57:35 +0000 | [diff] [blame] | 130 | add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT}) |
Douglas Gregor | 343beeb | 2009-06-23 21:05:21 +0000 | [diff] [blame] | 131 | if ( TABLEGEN_OUTPUT ) |
| 132 | add_dependencies(LLVM${target_name} ${target_name}Table_gen) |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 133 | set_target_properties(${target_name}Table_gen PROPERTIES FOLDER "Tablegenning") |
Douglas Gregor | 343beeb | 2009-06-23 21:05:21 +0000 | [diff] [blame] | 134 | endif (TABLEGEN_OUTPUT) |
Oscar Fuentes | 00d78f1 | 2011-02-20 02:55:27 +0000 | [diff] [blame] | 135 | set( CURRENT_LLVM_TARGET LLVM${target_name} ) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 136 | endmacro(add_llvm_target) |