From af7726eb9cb3d3da2428e35dbd3a3f38262fa3ed Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 May 2020 15:48:21 -0700 Subject: [PATCH] [CMake] Export SwiftDriver so other CMake projects can link against it --- CMakeLists.txt | 1 + Sources/SwiftDriver/CMakeLists.txt | 7 +++++++ Sources/SwiftOptions/CMakeLists.txt | 3 +++ cmake/modules/CMakeLists.txt | 8 ++++++++ cmake/modules/SwiftDriverConfig.cmake.in | 3 +++ 5 files changed, 22 insertions(+) create mode 100644 cmake/modules/CMakeLists.txt create mode 100644 cmake/modules/SwiftDriverConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index b054a2a0a..6ee87a2fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,3 +44,4 @@ find_package(Foundation QUIET) find_package(Yams CONFIG REQUIRED) add_subdirectory(Sources) +add_subdirectory(cmake/modules) diff --git a/Sources/SwiftDriver/CMakeLists.txt b/Sources/SwiftDriver/CMakeLists.txt index a3802b4a2..d1944e833 100644 --- a/Sources/SwiftDriver/CMakeLists.txt +++ b/Sources/SwiftDriver/CMakeLists.txt @@ -68,3 +68,10 @@ target_link_libraries(SwiftDriver PUBLIC llbuildSwift CYaml Yams) + +set_property(GLOBAL APPEND PROPERTY SWIFTDRIVER_EXPORTS SwiftDriver) + +# NOTE: workaround for CMake not setting up include flags yet +set_target_properties(SwiftDriver PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + diff --git a/Sources/SwiftOptions/CMakeLists.txt b/Sources/SwiftOptions/CMakeLists.txt index 34bd1cd8f..577ad832b 100644 --- a/Sources/SwiftOptions/CMakeLists.txt +++ b/Sources/SwiftOptions/CMakeLists.txt @@ -15,9 +15,12 @@ add_library(SwiftOptions OptionParsing.swift Options.swift PrefixTrie.swift) + target_link_libraries(SwiftOptions PUBLIC TSCBasic) +set_property(GLOBAL APPEND PROPERTY SWIFTDRIVER_EXPORTS SwiftOptions) + # NOTE: workaround for CMake not setting up include flags yet set_target_properties(SwiftOptions PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt new file mode 100644 index 000000000..0c7f7ade2 --- /dev/null +++ b/cmake/modules/CMakeLists.txt @@ -0,0 +1,8 @@ +set(SWIFTDRIVER_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftDriverExports.cmake) + +configure_file(SwiftDriverConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/SwiftDriverConfig.cmake) + +get_property(SWIFTDRIVER_EXPORTS GLOBAL PROPERTY SWIFTDRIVER_EXPORTS) +export(TARGETS ${SWIFTDRIVER_EXPORTS} + FILE ${SWIFTDRIVER_EXPORTS_FILE}) diff --git a/cmake/modules/SwiftDriverConfig.cmake.in b/cmake/modules/SwiftDriverConfig.cmake.in new file mode 100644 index 000000000..78e3070cb --- /dev/null +++ b/cmake/modules/SwiftDriverConfig.cmake.in @@ -0,0 +1,3 @@ +if(NOT TARGET SwiftDriver) + include(@SWIFTDRIVER_EXPORTS_FILE@) +endif()