build: add exports targets

Now that we can build the Swift content as a library, we can do export
targets.  This enables us to have CMake determine more information about
the target, track dependencies across projects, and manage the flags
across the trees without the special variables to specify the source and
build trees.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 10a0e46..75c419c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -276,3 +276,5 @@
 if(BUILD_TESTING)
   add_subdirectory(tests)
 endif()
+
+add_subdirectory(cmake/modules)
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
new file mode 100644
index 0000000..10cc0e1
--- /dev/null
+++ b/cmake/modules/CMakeLists.txt
@@ -0,0 +1,7 @@
+
+set(DISPATCH_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/dispatchExports.cmake)
+configure_file(dispatchConfig.cmake.in
+  ${CMAKE_CURRENT_BINARY_DIR}/dispatchConfig.cmake)
+
+get_property(DISPATCH_EXPORTS GLOBAL PROPERTY DISPATCH_EXPORTS)
+export(TARGETS ${DISPATCH_EXPORTS} FILE ${DISPATCH_EXPORTS_FILE})
diff --git a/cmake/modules/dispatchConfig.cmake.in b/cmake/modules/dispatchConfig.cmake.in
new file mode 100644
index 0000000..81228f2
--- /dev/null
+++ b/cmake/modules/dispatchConfig.cmake.in
@@ -0,0 +1,7 @@
+
+set(DISPATCH_HAS_SWIFT_SDK_OVERLAY @ENABLE_SWIFT@)
+
+if(NOT TARGET dispatch)
+  include(@DISPATCH_EXPORTS_FILE@)
+endif()
+
diff --git a/src/BlocksRuntime/CMakeLists.txt b/src/BlocksRuntime/CMakeLists.txt
index a5388d6..4c8fa99 100644
--- a/src/BlocksRuntime/CMakeLists.txt
+++ b/src/BlocksRuntime/CMakeLists.txt
@@ -28,7 +28,9 @@
   install(FILES Block_private.h
           DESTINATION ${INSTALL_BLOCK_HEADERS_DIR})
 endif()
+set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS BlocksRuntime)
 install(TARGETS BlocksRuntime
+        EXPORT dispatchExports
         ARCHIVE DESTINATION ${INSTALL_TARGET_DIR}
         LIBRARY DESTINATION ${INSTALL_TARGET_DIR}
         RUNTIME DESTINATION bin)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a81e7dc..c401758 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -159,7 +159,9 @@
   add_subdirectory(swift)
 endif()
 
+set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS dispatch)
 install(TARGETS dispatch
+        EXPORT dispatchExports
         ARCHIVE DESTINATION ${INSTALL_TARGET_DIR}
         LIBRARY DESTINATION ${INSTALL_TARGET_DIR}
         RUNTIME DESTINATION bin)
diff --git a/src/swift/CMakeLists.txt b/src/swift/CMakeLists.txt
index a10d969..18a297f 100644
--- a/src/swift/CMakeLists.txt
+++ b/src/swift/CMakeLists.txt
@@ -46,11 +46,15 @@
   ${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule
   ${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc
   DESTINATION ${INSTALL_TARGET_DIR}/${swift_arch})
+set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch)
 install(TARGETS swiftDispatch
+  EXPORT dispatchExports
   ARCHIVE DESTINATION ${INSTALL_TARGET_DIR}
   LIBRARY DESTINATION ${INSTALL_TARGET_DIR}
   RUNTIME DESTINATION bin)
 if(NOT BUILD_SHARED_LIBS)
+  set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS DispatchStubs)
   install(TARGETS DispatchStubs
+    EXPORT dispatchExports
     DESTINATION ${INSTALL_TARGET_DIR})
 endif()