|
2 | 2 | include(CMakeParseArguments)
|
3 | 3 |
|
4 | 4 | function(add_swift_target target)
|
5 |
| - set(options LIBRARY) |
| 5 | + set(options LIBRARY;SHARED;STATIC) |
6 | 6 | set(single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH;MODULE_CACHE_PATH;OUTPUT;TARGET)
|
7 | 7 | set(multiple_value_options CFLAGS;DEPENDS;LINK_FLAGS;SOURCES;SWIFT_FLAGS)
|
8 | 8 |
|
@@ -40,9 +40,28 @@ function(add_swift_target target)
|
40 | 40 | list(APPEND link_flags ${flag})
|
41 | 41 | endforeach()
|
42 | 42 | endif()
|
| 43 | + if(AST_LIBRARY) |
| 44 | + if(AST_STATIC AND AST_SHARED) |
| 45 | + message(SEND_ERROR "add_swift_target asked to create library as STATIC and SHARED") |
| 46 | + elseif(AST_STATIC OR NOT BUILD_SHARED_LIBS) |
| 47 | + set(library_kind STATIC) |
| 48 | + elseif(AST_SHARED OR BUILD_SHARED_LIBS) |
| 49 | + set(library_kind SHARED) |
| 50 | + endif() |
| 51 | + else() |
| 52 | + if(AST_STATIC OR AST_SHARED) |
| 53 | + message(SEND_ERROR "add_swift_target asked to create executable as STATIC or SHARED") |
| 54 | + endif() |
| 55 | + endif() |
43 | 56 | if(NOT AST_OUTPUT)
|
44 | 57 | if(AST_LIBRARY)
|
45 |
| - set(AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${CMAKE_SHARED_LIBRARY_PREFIX}${target}${CMAKE_SHARED_LIBRARY_SUFFIX}) |
| 58 | + if(AST_SHARED OR BUILD_SHARED_LIBS) |
| 59 | + set(AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${CMAKE_SHARED_LIBRARY_PREFIX}${target}${CMAKE_SHARED_LIBRARY_SUFFIX}) |
| 60 | + else() |
| 61 | + # NOTE(compnerd) this is a hack for the computation of the |
| 62 | + # basename/dirname below for the static path. |
| 63 | + set(AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${target}) |
| 64 | + endif() |
46 | 65 | else()
|
47 | 66 | set(AST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${target}.dir/${target}${CMAKE_EXECUTABLE_SUFFIX})
|
48 | 67 | endif()
|
@@ -107,20 +126,37 @@ function(add_swift_target target)
|
107 | 126 | if(AST_LIBRARY)
|
108 | 127 | set(emit_library -emit-library)
|
109 | 128 | endif()
|
110 |
| - add_custom_command(OUTPUT |
111 |
| - ${AST_OUTPUT} |
112 |
| - DEPENDS |
113 |
| - ${objs} |
114 |
| - COMMAND |
115 |
| - ${CMAKE_SWIFT_COMPILER} ${emit_library} ${link_flags} -o ${AST_OUTPUT} ${objs} |
116 |
| - COMMAND |
117 |
| - ${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}) |
118 |
| - add_custom_target(${target} |
119 |
| - ALL |
120 |
| - DEPENDS |
121 |
| - ${AST_OUTPUT} |
122 |
| - ${module} |
123 |
| - ${documentation}) |
| 129 | + if(library_kind STREQUAL SHARED) |
| 130 | + add_custom_command(OUTPUT |
| 131 | + ${AST_OUTPUT} |
| 132 | + DEPENDS |
| 133 | + ${objs} |
| 134 | + COMMAND |
| 135 | + ${CMAKE_SWIFT_COMPILER} ${emit_library} ${link_flags} -o ${AST_OUTPUT} ${objs} |
| 136 | + COMMAND |
| 137 | + ${CMAKE_COMMAND} -E copy ${AST_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}) |
| 138 | + add_custom_target(${target} |
| 139 | + ALL |
| 140 | + DEPENDS |
| 141 | + ${AST_OUTPUT} |
| 142 | + ${module} |
| 143 | + ${documentation}) |
| 144 | + else() |
| 145 | + add_library(${target}-static STATIC ${objs}) |
| 146 | + get_filename_component(ast_output_bn ${AST_OUTPUT} NAME) |
| 147 | + get_filename_component(ast_output_dn ${AST_OUTPUT} DIRECTORY) |
| 148 | + set_target_properties(${target}-static |
| 149 | + PROPERTIES |
| 150 | + LINKER_LANGUAGE C |
| 151 | + OUTPUT_DIRECTORY ${ast_output_dn} |
| 152 | + OUTPUT_NAME ${ast_output_bn}) |
| 153 | + add_custom_target(${target} |
| 154 | + ALL |
| 155 | + DEPENDS |
| 156 | + ${target}-static |
| 157 | + ${module} |
| 158 | + ${documentation}) |
| 159 | + endif() |
124 | 160 | endfunction()
|
125 | 161 |
|
126 | 162 | function(add_swift_library library)
|
|
0 commit comments