From f8347f1b2d376b5bf19eed03e18e11ecc889e966 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Thu, 25 Apr 2024 22:05:10 -0700 Subject: [PATCH] Add option to install targets even when not top level Also add namespaced targets for any exported target to facilitate find_package and FetchContent both using the same target names. --- cmake/modules/AddSwiftHostLibrary.cmake | 3 ++- cmake/modules/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/modules/AddSwiftHostLibrary.cmake b/cmake/modules/AddSwiftHostLibrary.cmake index f3858efb584..459d0f3cb4f 100644 --- a/cmake/modules/AddSwiftHostLibrary.cmake +++ b/cmake/modules/AddSwiftHostLibrary.cmake @@ -130,7 +130,7 @@ function(add_swift_syntax_library name) endif() endif() - if(PROJECT_IS_TOP_LEVEL) + if(PROJECT_IS_TOP_LEVEL OR SWIFT_SYNTAX_INSTALL_TARGETS) # Install this target install(TARGETS ${name} EXPORT SwiftSyntaxTargets @@ -148,4 +148,5 @@ function(add_swift_syntax_library name) else() set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name}) endif() + add_library(SwiftSyntax::${name} ALIAS ${name}) endfunction() diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt index bb98e4ba873..e29130c8b4e 100644 --- a/cmake/modules/CMakeLists.txt +++ b/cmake/modules/CMakeLists.txt @@ -1,4 +1,4 @@ -if(PROJECT_IS_TOP_LEVEL) +if(PROJECT_IS_TOP_LEVEL OR SWIFT_SYNTAX_INSTALL_TARGETS) export(EXPORT SwiftSyntaxTargets FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftSyntaxConfig.cmake NAMESPACE SwiftSyntax::)