Oscar Fuentes | 751ea9d | 2008-11-14 22:06:14 +0000 | [diff] [blame] | 1 | include(LLVMProcessSources) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 2 | include(LLVMConfig) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 3 | |
| 4 | macro(add_llvm_library name) |
Oscar Fuentes | 2c10b22 | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 5 | llvm_process_sources( ALL_FILES ${ARGN} ) |
| 6 | add_library( ${name} ${ALL_FILES} ) |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 7 | set( llvm_libs ${llvm_libs} ${name} PARENT_SCOPE) |
Oscar Fuentes | 8807bdd | 2008-09-22 18:21:51 +0000 | [diff] [blame] | 8 | set( llvm_lib_targets ${llvm_lib_targets} ${name} PARENT_SCOPE ) |
| 9 | if( LLVM_COMMON_DEPENDS ) |
| 10 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 11 | endif( LLVM_COMMON_DEPENDS ) |
Oscar Fuentes | ffe32e1 | 2010-10-14 15:54:41 +0000 | [diff] [blame] | 12 | |
| 13 | if( BUILD_SHARED_LIBS ) |
| 14 | get_system_libs(sl) |
| 15 | target_link_libraries( ${name} ${sl} ) |
| 16 | endif() |
| 17 | |
Oscar Fuentes | 64c9962 | 2008-10-22 02:56:07 +0000 | [diff] [blame] | 18 | install(TARGETS ${name} |
Oscar Fuentes | 46fed3b | 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 | 8160d28 | 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 | 171a7d6 | 2009-08-16 09:44:27 +0000 | [diff] [blame] | 26 | add_dependencies(${name} ${CURRENT_LLVM_TARGET}) |
Oscar Fuentes | 8160d28 | 2009-08-16 05:16:43 +0000 | [diff] [blame] | 27 | endif() |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 28 | endmacro(add_llvm_library name) |
| 29 | |
| 30 | |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 31 | macro(add_llvm_loadable_module name) |
Oscar Fuentes | ff11a23 | 2010-10-22 19:03:24 +0000 | [diff] [blame] | 32 | if( NOT LLVM_ON_UNIX OR CYGWIN ) |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 33 | message(STATUS "Loadable modules not supported on this platform. |
| 34 | ${name} ignored.") |
NAKAMURA Takumi | a8c1c3f | 2010-12-10 02:15:36 +0000 | [diff] [blame^] | 35 | # Add empty "phony" target |
| 36 | add_custom_target(${name}) |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 37 | else() |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 38 | llvm_process_sources( ALL_FILES ${ARGN} ) |
| 39 | add_library( ${name} MODULE ${ALL_FILES} ) |
| 40 | set_target_properties( ${name} PROPERTIES PREFIX "" ) |
Douglas Gregor | 66df54f | 2009-11-10 15:30:33 +0000 | [diff] [blame] | 41 | |
| 42 | if (APPLE) |
| 43 | # Darwin-specific linker flags for loadable modules. |
| 44 | set_target_properties(${name} PROPERTIES |
| 45 | LINK_FLAGS "-Wl,-flat_namespace -Wl,-undefined -Wl,suppress") |
| 46 | endif() |
| 47 | |
Oscar Fuentes | bbc1067 | 2009-11-10 02:45:37 +0000 | [diff] [blame] | 48 | install(TARGETS ${name} |
| 49 | LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} |
| 50 | ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) |
| 51 | endif() |
| 52 | endmacro(add_llvm_loadable_module name) |
| 53 | |
| 54 | |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 55 | macro(add_llvm_executable name) |
Oscar Fuentes | 2c10b22 | 2008-11-15 02:08:08 +0000 | [diff] [blame] | 56 | llvm_process_sources( ALL_FILES ${ARGN} ) |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 57 | if( EXCLUDE_FROM_ALL ) |
| 58 | add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES}) |
| 59 | else() |
| 60 | add_executable(${name} ${ALL_FILES}) |
| 61 | endif() |
| 62 | set(EXCLUDE_FROM_ALL OFF) |
Oscar Fuentes | 20baf2f | 2008-10-26 00:51:05 +0000 | [diff] [blame] | 63 | if( LLVM_USED_LIBS ) |
| 64 | foreach(lib ${LLVM_USED_LIBS}) |
| 65 | target_link_libraries( ${name} ${lib} ) |
| 66 | endforeach(lib) |
| 67 | endif( LLVM_USED_LIBS ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 68 | if( LLVM_LINK_COMPONENTS ) |
| 69 | llvm_config(${name} ${LLVM_LINK_COMPONENTS}) |
| 70 | endif( LLVM_LINK_COMPONENTS ) |
Oscar Fuentes | 3fca0e8 | 2009-08-14 04:38:57 +0000 | [diff] [blame] | 71 | if( LLVM_COMMON_DEPENDS ) |
| 72 | add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) |
| 73 | endif( LLVM_COMMON_DEPENDS ) |
Michael J. Spencer | 7c3a5ee | 2010-09-11 02:13:39 +0000 | [diff] [blame] | 74 | if( NOT MINGW ) |
| 75 | get_system_libs(llvm_system_libs) |
| 76 | if( llvm_system_libs ) |
| 77 | target_link_libraries(${name} ${llvm_system_libs}) |
| 78 | endif() |
| 79 | endif() |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 80 | endmacro(add_llvm_executable name) |
| 81 | |
| 82 | |
| 83 | macro(add_llvm_tool name) |
| 84 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR}) |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 85 | if( NOT LLVM_BUILD_TOOLS ) |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 86 | set(EXCLUDE_FROM_ALL ON) |
| 87 | endif() |
Oscar Fuentes | 46d8a93 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 88 | add_llvm_executable(${name} ${ARGN}) |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 89 | if( LLVM_BUILD_TOOLS ) |
| 90 | install(TARGETS ${name} RUNTIME DESTINATION bin) |
| 91 | endif() |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 92 | endmacro(add_llvm_tool name) |
| 93 | |
| 94 | |
| 95 | macro(add_llvm_example name) |
| 96 | # set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_EXAMPLES_BINARY_DIR}) |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 97 | if( NOT LLVM_BUILD_EXAMPLES ) |
Oscar Fuentes | 0c2443a | 2009-11-23 00:21:43 +0000 | [diff] [blame] | 98 | set(EXCLUDE_FROM_ALL ON) |
| 99 | endif() |
Oscar Fuentes | 46d8a93 | 2010-09-25 20:25:25 +0000 | [diff] [blame] | 100 | add_llvm_executable(${name} ${ARGN}) |
Oscar Fuentes | dea579f | 2009-11-23 00:32:42 +0000 | [diff] [blame] | 101 | if( LLVM_BUILD_EXAMPLES ) |
| 102 | install(TARGETS ${name} RUNTIME DESTINATION examples) |
| 103 | endif() |
Oscar Fuentes | a229b3c | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 104 | endmacro(add_llvm_example name) |
Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 105 | |
| 106 | |
| 107 | macro(add_llvm_target target_name) |
| 108 | if( TABLEGEN_OUTPUT ) |
| 109 | add_custom_target(${target_name}Table_gen |
| 110 | DEPENDS ${TABLEGEN_OUTPUT}) |
| 111 | add_dependencies(${target_name}Table_gen ${LLVM_COMMON_DEPENDS}) |
| 112 | endif( TABLEGEN_OUTPUT ) |
| 113 | include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) |
Douglas Gregor | 85fedbe | 2009-06-23 17:57:35 +0000 | [diff] [blame] | 114 | add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT}) |
Douglas Gregor | f42a6ab | 2009-06-23 21:05:21 +0000 | [diff] [blame] | 115 | if ( TABLEGEN_OUTPUT ) |
| 116 | add_dependencies(LLVM${target_name} ${target_name}Table_gen) |
| 117 | endif (TABLEGEN_OUTPUT) |
Oscar Fuentes | 9496a6d | 2009-08-16 07:44:02 +0000 | [diff] [blame] | 118 | set(CURRENT_LLVM_TARGET LLVM${target_name} PARENT_SCOPE) |
Oscar Fuentes | cdc9549 | 2008-09-26 04:40:32 +0000 | [diff] [blame] | 119 | endmacro(add_llvm_target) |