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 | 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 | endif() |
| 15 | |
Oscar Fuentes | 23f0bfe | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 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 | |
Oscar Fuentes | 1dc9716 | 2008-10-22 02:56:07 +0000 | [diff] [blame] | 20 | install(TARGETS ${name} |
Oscar Fuentes | af0f65f | 2009-06-12 02:49:53 +0000 | [diff] [blame] | 21 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 22 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
Oscar Fuentes | b78829e | 2009-08-16 05:16:43 +0000 | [diff] [blame] | 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 ) |
Benjamin Kramer | 0bbbf7e | 2009-08-16 09:44:27 +0000 | [diff] [blame] | 28 | add_dependencies(${name} ${CURRENT_LLVM_TARGET}) |
Oscar Fuentes | b78829e | 2009-08-16 05:16:43 +0000 | [diff] [blame] | 29 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 30 | set_target_properties(${name} PROPERTIES FOLDER "Libraries") |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 31 | endmacro(add_llvm_library name) |
| 32 | |
| 33 | |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 34 | macro(add_llvm_loadable_module name) |
Oscar Fuentes | 01a575e | 2010-10-22 19:03:24 +0000 | [diff] [blame] | 35 | if( NOT LLVM_ON_UNIX OR CYGWIN ) |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 36 | message(STATUS "Loadable modules not supported on this platform. |
| 37 | ${name} ignored.") |
NAKAMURA Takumi | 51c06bf | 2010-12-10 02:15:36 +0000 | [diff] [blame] | 38 | # Add empty "phony" target |
| 39 | add_custom_target(${name}) |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 40 | else() |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 41 | llvm_process_sources( ALL_FILES ${ARGN} ) |
Oscar Fuentes | 7110428 | 2010-12-22 08:30:17 +0000 | [diff] [blame] | 42 | if (MODULE) |
| 43 | set(libkind MODULE) |
| 44 | else() |
| 45 | set(libkind SHARED) |
| 46 | endif() |
| 47 | |
| 48 | add_library( ${name} ${libkind} ${ALL_FILES} ) |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 49 | set_target_properties( ${name} PROPERTIES PREFIX "" ) |
Douglas Gregor | 8781416 | 2009-11-10 15:30:33 +0000 | [diff] [blame] | 50 | |
Oscar Fuentes | 879d3a9 | 2011-03-12 16:48:54 +0000 | [diff] [blame] | 51 | llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) |
Oscar Fuentes | 23f0bfe | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 52 | link_system_libs( ${name} ) |
Oscar Fuentes | 879d3a9 | 2011-03-12 16:48:54 +0000 | [diff] [blame] | 53 | |
Douglas Gregor | 8781416 | 2009-11-10 15:30:33 +0000 | [diff] [blame] | 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 | |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 60 | install(TARGETS ${name} |
| 61 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 62 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
| 63 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 64 | |
| 65 | set_target_properties(${name} PROPERTIES FOLDER "Loadable modules") |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 66 | endmacro(add_llvm_loadable_module name) |
| 67 | |
| 68 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 69 | macro(add_llvm_executable name) |
Oscar Fuentes | 50925fb | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 70 | llvm_process_sources( ALL_FILES ${ARGN} ) |
Oscar Fuentes | b8352de | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 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) |
Oscar Fuentes | 23f0bfe | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 77 | target_link_libraries( ${name} ${LLVM_USED_LIBS} ) |
| 78 | llvm_config( ${name} ${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 ) |
Oscar Fuentes | 23f0bfe | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 82 | link_system_libs( ${name} ) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 83 | endmacro(add_llvm_executable name) |
| 84 | |
| 85 | |
| 86 | macro(add_llvm_tool name) |
| 87 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 88 | if( NOT LLVM_BUILD_TOOLS ) |
Oscar Fuentes | b8352de | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 89 | set(EXCLUDE_FROM_ALL ON) |
| 90 | endif() |
Oscar Fuentes | 066de85 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 91 | add_llvm_executable(${name} ${ARGN}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 92 | if( LLVM_BUILD_TOOLS ) |
| 93 | install(TARGETS ${name} RUNTIME DESTINATION bin) |
| 94 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 95 | set_target_properties(${name} PROPERTIES FOLDER "Tools") |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 96 | endmacro(add_llvm_tool name) |
| 97 | |
| 98 | |
| 99 | macro(add_llvm_example name) |
| 100 | # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 101 | if( NOT LLVM_BUILD_EXAMPLES ) |
Oscar Fuentes | b8352de | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 102 | set(EXCLUDE_FROM_ALL ON) |
| 103 | endif() |
Oscar Fuentes | 066de85 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 104 | add_llvm_executable(${name} ${ARGN}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 105 | if( LLVM_BUILD_EXAMPLES ) |
| 106 | install(TARGETS ${name} RUNTIME DESTINATION examples) |
| 107 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 108 | set_target_properties(${name} PROPERTIES FOLDER "Examples") |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 109 | endmacro(add_llvm_example name) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 110 | |
| 111 | |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 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 | |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 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}) |
Douglas Gregor | 7e9e36a | 2009-06-23 17:57:35 +0000 | [diff] [blame] | 125 | add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT}) |
Douglas Gregor | 343beeb | 2009-06-23 21:05:21 +0000 | [diff] [blame] | 126 | if ( TABLEGEN_OUTPUT ) |
| 127 | add_dependencies(LLVM${target_name} ${target_name}Table_gen) |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 128 | set_target_properties(${target_name}Table_gen PROPERTIES FOLDER "Tablegenning") |
Douglas Gregor | 343beeb | 2009-06-23 21:05:21 +0000 | [diff] [blame] | 129 | endif (TABLEGEN_OUTPUT) |
Oscar Fuentes | 00d78f1 | 2011-02-20 02:55:27 +0000 | [diff] [blame] | 130 | set( CURRENT_LLVM_TARGET LLVM${target_name} ) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 131 | endmacro(add_llvm_target) |