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 | |
Nick Lewycky | bcffb1f | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 20 | if( EXCLUDE_FROM_ALL ) |
| 21 | set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) |
| 22 | else() |
| 23 | install(TARGETS ${name} |
| 24 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 25 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
| 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 | |
Chandler Carruth | ac03e73 | 2011-07-29 00:14:25 +0000 | [diff] [blame] | 30 | macro(add_llvm_library_dependencies name) |
| 31 | # Save the dependencies of the LLVM library in a variable so that we can |
| 32 | # query it when resolve llvm-config-style component -> library mappings. |
Chandler Carruth | 2e1513d | 2011-07-29 23:52:01 +0000 | [diff] [blame] | 33 | set_property(GLOBAL PROPERTY LLVM_LIB_DEPS_${name} ${ARGN}) |
Chandler Carruth | ac03e73 | 2011-07-29 00:14:25 +0000 | [diff] [blame] | 34 | |
| 35 | # Then add the actual dependencies to the library target. |
| 36 | target_link_libraries(${name} ${ARGN}) |
| 37 | endmacro(add_llvm_library_dependencies name) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 38 | |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 39 | macro(add_llvm_loadable_module name) |
Oscar Fuentes | 01a575e | 2010-10-22 19:03:24 +0000 | [diff] [blame] | 40 | if( NOT LLVM_ON_UNIX OR CYGWIN ) |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 41 | message(STATUS "Loadable modules not supported on this platform. |
| 42 | ${name} ignored.") |
NAKAMURA Takumi | 51c06bf | 2010-12-10 02:15:36 +0000 | [diff] [blame] | 43 | # Add empty "phony" target |
| 44 | add_custom_target(${name}) |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 45 | else() |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 46 | llvm_process_sources( ALL_FILES ${ARGN} ) |
Oscar Fuentes | 7110428 | 2010-12-22 08:30:17 +0000 | [diff] [blame] | 47 | if (MODULE) |
| 48 | set(libkind MODULE) |
| 49 | else() |
| 50 | set(libkind SHARED) |
| 51 | endif() |
| 52 | |
| 53 | add_library( ${name} ${libkind} ${ALL_FILES} ) |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 54 | set_target_properties( ${name} PROPERTIES PREFIX "" ) |
Douglas Gregor | 8781416 | 2009-11-10 15:30:33 +0000 | [diff] [blame] | 55 | |
Oscar Fuentes | 879d3a9 | 2011-03-12 16:48:54 +0000 | [diff] [blame] | 56 | llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) |
Oscar Fuentes | 23f0bfe | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 57 | link_system_libs( ${name} ) |
Oscar Fuentes | 879d3a9 | 2011-03-12 16:48:54 +0000 | [diff] [blame] | 58 | |
Douglas Gregor | 8781416 | 2009-11-10 15:30:33 +0000 | [diff] [blame] | 59 | if (APPLE) |
| 60 | # Darwin-specific linker flags for loadable modules. |
| 61 | set_target_properties(${name} PROPERTIES |
| 62 | LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress") |
| 63 | endif() |
| 64 | |
Oscar Fuentes | ab92d1e | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 65 | if( EXCLUDE_FROM_ALL ) |
Nick Lewycky | bcffb1f | 2011-04-29 02:12:06 +0000 | [diff] [blame] | 66 | set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) |
Oscar Fuentes | ab92d1e | 2011-04-26 14:55:27 +0000 | [diff] [blame] | 67 | else() |
| 68 | install(TARGETS ${name} |
| 69 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 70 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
| 71 | endif() |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 72 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 73 | |
| 74 | set_target_properties(${name} PROPERTIES FOLDER "Loadable modules") |
Oscar Fuentes | c5e1ae1 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 75 | endmacro(add_llvm_loadable_module name) |
| 76 | |
| 77 | |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 78 | macro(add_llvm_executable name) |
Oscar Fuentes | 50925fb | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 79 | llvm_process_sources( ALL_FILES ${ARGN} ) |
Oscar Fuentes | b8352de | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 80 | if( EXCLUDE_FROM_ALL ) |
| 81 | add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES}) |
| 82 | else() |
| 83 | add_executable(${name} ${ALL_FILES}) |
| 84 | endif() |
| 85 | set(EXCLUDE_FROM_ALL OFF) |
Oscar Fuentes | 23f0bfe | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 86 | target_link_libraries( ${name} ${LLVM_USED_LIBS} ) |
| 87 | llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) |
Oscar Fuentes | d8b1b9a | 2009-08-14 04:38:57 +0000 | [diff] [blame] | 88 | if( LLVM_COMMON_DEPENDS ) |
| 89 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 90 | endif( LLVM_COMMON_DEPENDS ) |
Oscar Fuentes | 23f0bfe | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 91 | link_system_libs( ${name} ) |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 92 | endmacro(add_llvm_executable name) |
| 93 | |
| 94 | |
| 95 | macro(add_llvm_tool name) |
| 96 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 97 | if( NOT LLVM_BUILD_TOOLS ) |
Oscar Fuentes | b8352de | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 98 | set(EXCLUDE_FROM_ALL ON) |
| 99 | endif() |
Oscar Fuentes | 066de85 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 100 | add_llvm_executable(${name} ${ARGN}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 101 | if( LLVM_BUILD_TOOLS ) |
| 102 | install(TARGETS ${name} RUNTIME DESTINATION bin) |
| 103 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 104 | set_target_properties(${name} PROPERTIES FOLDER "Tools") |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 105 | endmacro(add_llvm_tool name) |
| 106 | |
| 107 | |
| 108 | macro(add_llvm_example name) |
| 109 | # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 110 | if( NOT LLVM_BUILD_EXAMPLES ) |
Oscar Fuentes | b8352de | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 111 | set(EXCLUDE_FROM_ALL ON) |
| 112 | endif() |
Oscar Fuentes | 066de85 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 113 | add_llvm_executable(${name} ${ARGN}) |
Oscar Fuentes | 7be498e | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 114 | if( LLVM_BUILD_EXAMPLES ) |
| 115 | install(TARGETS ${name} RUNTIME DESTINATION examples) |
| 116 | endif() |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 117 | set_target_properties(${name} PROPERTIES FOLDER "Examples") |
Oscar Fuentes | 3d01fc7 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 118 | endmacro(add_llvm_example name) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 119 | |
| 120 | |
Oscar Fuentes | 0b85d07 | 2011-02-20 22:06:10 +0000 | [diff] [blame] | 121 | macro(add_llvm_utility name) |
| 122 | add_llvm_executable(${name} ${ARGN}) |
| 123 | set_target_properties(${name} PROPERTIES FOLDER "Utils") |
| 124 | endmacro(add_llvm_utility name) |
| 125 | |
| 126 | |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 127 | macro(add_llvm_target target_name) |
Oscar Fuentes | d7808d2 | 2011-07-25 20:17:01 +0000 | [diff] [blame] | 128 | include_directories(BEFORE |
| 129 | ${CMAKE_CURRENT_BINARY_DIR} |
| 130 | ${CMAKE_CURRENT_SOURCE_DIR}) |
Douglas Gregor | 7e9e36a | 2009-06-23 17:57:35 +0000 | [diff] [blame] | 131 | add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT}) |
Oscar Fuentes | 00d78f1 | 2011-02-20 02:55:27 +0000 | [diff] [blame] | 132 | set( CURRENT_LLVM_TARGET LLVM${target_name} ) |
Oscar Fuentes | e1ad087 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 133 | endmacro(add_llvm_target) |