Skip to content

Commit 7fc05c0

Browse files
authored
[build] CMake updates to support use in SwiftPM bootstrap (#139)
1 parent 809b2f9 commit 7fc05c0

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
cmake_minimum_required(VERSION 3.16.0)
22

3+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
4+
35
project(swift-argument-parser
46
LANGUAGES Swift)
57

68
option(BUILD_EXAMPLES "Build Example Programs" TRUE)
9+
option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)
710

811
include(CTest)
912

13+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
14+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
15+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
1016
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
1117

1218
find_package(Foundation QUIET)
@@ -20,5 +26,4 @@ if(BUILD_TESTING)
2026
add_subdirectory(Tests)
2127
endif()
2228

23-
export(TARGETS ArgumentParser
24-
FILE swift-argument-parser-config.cmake)
29+
add_subdirectory(cmake/modules)

Sources/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ add_subdirectory(ArgumentParser)
22
if(BUILD_TESTING)
33
add_subdirectory(ArgumentParserTestHelpers)
44
endif()
5+
6+
set_property(GLOBAL APPEND PROPERTY ArgumentParser_EXPORTS ArgumentParser)
7+
8+
# NOTE: workaround for CMake not setting up include flags yet
9+
set_target_properties(ArgumentParser PROPERTIES
10+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if(NOT TARGET ArgumentParser)
2+
include(@ArgumentParser_EXPORTS_FILE@)
3+
endif()

cmake/modules/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(ArgumentParser_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/ArgumentParserExports.cmake)
2+
3+
configure_file(ArgumentParserConfig.cmake.in
4+
${CMAKE_CURRENT_BINARY_DIR}/ArgumentParserConfig.cmake)
5+
6+
get_property(ArgumentParser_EXPORTS GLOBAL PROPERTY ArgumentParser_EXPORTS)
7+
export(TARGETS ${ArgumentParser_EXPORTS}
8+
FILE ${ArgumentParser_EXPORTS_FILE})

0 commit comments

Comments
 (0)