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