Skip to content

Commit 8faa9c8

Browse files
compnerdetcwilde
andcommitted
cmake: extract version string and add PrintVersion.cmake
Add a helper to allow us to programatically extract the Swift version string during the build. This is particularly useful for injection into the packaging stages. Co-authored-by: Evan Wilde <[email protected]>
1 parent 175e712 commit 8faa9c8

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,7 @@ endif()
304304
set(SWIFT_ANALYZE_CODE_COVERAGE FALSE CACHE STRING
305305
"Build Swift with code coverage instrumenting enabled [FALSE, NOT-MERGED, MERGED]")
306306

307-
# SWIFT_VERSION is deliberately /not/ cached so that an existing build directory
308-
# can be reused when a new version of Swift comes out (assuming the user hasn't
309-
# manually set it as part of their own CMake configuration).
310-
set(SWIFT_VERSION_MAJOR 5)
311-
set(SWIFT_VERSION_MINOR 9)
312-
set(SWIFT_VERSION "${SWIFT_VERSION_MAJOR}.${SWIFT_VERSION_MINOR}")
307+
include(SwiftVersion)
313308

314309
set(SWIFT_VENDOR "" CACHE STRING
315310
"The vendor name of the Swift compiler")

cmake/PrintVersion.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/SwiftVersion.cmake)
2+
message(${SWIFT_VERSION})

cmake/SwiftVersion.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SWIFT_VERSION is deliberately /not/ cached so that an existing build directory
2+
# can be reused when a new version of Swift comes out (assuming the user hasn't
3+
# manually set it as part of their own CMake configuration).
4+
set(SWIFT_VERSION_MAJOR 5)
5+
set(SWIFT_VERSION_MINOR 9)
6+
set(SWIFT_VERSION "${SWIFT_VERSION_MAJOR}.${SWIFT_VERSION_MINOR}")
7+

lib/Basic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ target_link_libraries(swiftBasic PUBLIC
101101
target_link_libraries(swiftBasic PRIVATE
102102
${UUID_LIBRARIES})
103103

104+
include(${CMAKE_CURRENT_LIST_DIR}/../../cmake/SwiftVersion.cmake)
104105
message(STATUS "Swift version: ${SWIFT_VERSION}")
105106
message(STATUS "Swift vendor: ${SWIFT_VENDOR}")
106107

0 commit comments

Comments
 (0)