2 include(CMakeParseArguments)
4 function(add_swift_library library)
6 set(single_value_options MODULE_NAME;MODULE_LINK_NAME;MODULE_PATH;MODULE_CACHE_PATH;OUTPUT)
7 set(multiple_value_options SOURCES;SWIFT_FLAGS;CFLAGS)
9 cmake_parse_arguments(ASL "${options}" "${single_value_options}" "${multiple_value_options}" ${ARGN})
11 set(flags ${CMAKE_SWIFT_FLAGS})
13 list(APPEND flags -emit-library)
16 list(APPEND flags -module-name;${ASL_MODULE_NAME})
18 if(ASL_MODULE_LINK_NAME)
19 list(APPEND flags -module-link-name;${ASL_MODULE_LINK_NAME})
22 list(APPEND flags -emit-module-path;${ASL_MODULE_PATH})
24 if(ASL_MODULE_CACHE_PATH)
25 list(APPEND flags -module-cache-path;${ASL_MODULE_CACHE_PATH})
28 foreach(flag ${ASL_SWIFT_FLAGS})
29 list(APPEND flags ${flag})
33 foreach(flag ${ASL_CFLAGS})
34 list(APPEND flags -Xcc;${flag})
38 # FIXME: We shouldn't /have/ to build things in a single process.
39 # <rdar://problem/15972329>
40 list(APPEND flags -force-single-frontend-invocation)
43 foreach(source ${ASL_SOURCES})
44 get_filename_component(location ${source} PATH)
45 if(IS_ABSOLUTE ${location})
46 list(APPEND sources ${source})
48 list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/${source})
52 get_filename_component(module_directory ${ASL_MODULE_PATH} DIRECTORY)
54 add_custom_command(OUTPUT
57 ${module_directory}/${ASL_MODULE_NAME}.swiftdoc
61 ${CMAKE_COMMAND} -E make_directory ${module_directory}
63 ${CMAKE_SWIFT_COMPILER} ${flags} -c ${sources} -o ${ASL_OUTPUT})
64 add_custom_target(${library}
68 ${module_directory}/${ASL_MODULE_NAME}.swiftdoc)