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