]> git.saurik.com Git - apple/libdispatch.git/blob - cmake/modules/SwiftSupport.cmake
libdispatch-913.30.4.tar.gz
[apple/libdispatch.git] / cmake / modules / SwiftSupport.cmake
1
2 include(CMakeParseArguments)
3
4 function(add_swift_library library)
5 set(options)
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)
8
9 cmake_parse_arguments(ASL "${options}" "${single_value_options}" "${multiple_value_options}" ${ARGN})
10
11 set(flags ${CMAKE_SWIFT_FLAGS})
12
13 list(APPEND flags -emit-library)
14
15 if(ASL_MODULE_NAME)
16 list(APPEND flags -module-name;${ASL_MODULE_NAME})
17 endif()
18 if(ASL_MODULE_LINK_NAME)
19 list(APPEND flags -module-link-name;${ASL_MODULE_LINK_NAME})
20 endif()
21 if(ASL_MODULE_PATH)
22 list(APPEND flags -emit-module-path;${ASL_MODULE_PATH})
23 endif()
24 if(ASL_MODULE_CACHE_PATH)
25 list(APPEND flags -module-cache-path;${ASL_MODULE_CACHE_PATH})
26 endif()
27 if(ASL_SWIFT_FLAGS)
28 foreach(flag ${ASL_SWIFT_FLAGS})
29 list(APPEND flags ${flag})
30 endforeach()
31 endif()
32 if(ASL_CFLAGS)
33 foreach(flag ${ASL_CFLAGS})
34 list(APPEND flags -Xcc;${flag})
35 endforeach()
36 endif()
37
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)
41
42 set(sources)
43 foreach(source ${ASL_SOURCES})
44 get_filename_component(location ${source} PATH)
45 if(IS_ABSOLUTE ${location})
46 list(APPEND sources ${source})
47 else()
48 list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/${source})
49 endif()
50 endforeach()
51
52 get_filename_component(module_directory ${ASL_MODULE_PATH} DIRECTORY)
53
54 add_custom_command(OUTPUT
55 ${ASL_OUTPUT}
56 ${ASL_MODULE_PATH}
57 ${module_directory}/${ASL_MODULE_NAME}.swiftdoc
58 DEPENDS
59 ${ASL_SOURCES}
60 COMMAND
61 ${CMAKE_COMMAND} -E make_directory ${module_directory}
62 COMMAND
63 ${CMAKE_SWIFT_COMPILER} ${flags} -c ${sources} -o ${ASL_OUTPUT})
64 add_custom_target(${library}
65 DEPENDS
66 ${ASL_OUTPUT}
67 ${ASL_MODULE_PATH}
68 ${module_directory}/${ASL_MODULE_NAME}.swiftdoc)
69 endfunction()