Skip to content

Commit 54a0b60

Browse files
authored
Merge pull request #7 from apple/cmake
Setup proper CMake for TSC
2 parents cabfb9b + 89ddcea commit 54a0b60

File tree

10 files changed

+77
-6
lines changed

10 files changed

+77
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/*.xcodeproj
55
xcuserdata/
66
.swiftpm
7+
build

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
cmake_minimum_required(VERSION 3.15.1)
2+
3+
project(SwiftTSC LANGUAGES C Swift)
4+
5+
set(SWIFT_VERSION 5)
6+
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})
7+
if(CMAKE_VERSION VERSION_LESS 3.16)
8+
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-swift-version$<SEMICOLON>${SWIFT_VERSION}>)
9+
endif()
10+
11+
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
12+
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)
16+
17+
option(BUILD_SHARED_LIBS "Build shared libraryes by default" YES)
18+
19+
add_subdirectory(Sources)
20+
add_subdirectory(cmake/modules)

Sources/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_subdirectory(TSCclibc)
2+
add_subdirectory(TSCLibc)
3+
add_subdirectory(TSCBasic)
4+
add_subdirectory(TSCUtility)

Sources/TSCBasic/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ target_link_libraries(TSCBasic PUBLIC
5555
set_target_properties(TSCBasic PROPERTIES
5656
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
5757

58+
set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCBasic)
59+
5860
install(TARGETS TSCBasic
5961
ARCHIVE DESTINATION lib
6062
LIBRARY DESTINATION lib

Sources/TSCLibc/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@
88

99
add_library(TSCLibc
1010
libc.swift)
11-
target_compile_options(TSCLibc PRIVATE
12-
-autolink-force-load)
11+
12+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
13+
target_compile_options(TSCLibc PRIVATE
14+
-autolink-force-load)
15+
endif()
1316
target_link_libraries(TSCLibc PUBLIC
14-
clibc)
17+
TSCclibc)
1518
# NOTE(compnerd) workaround for CMake not setting up include flags yet
1619
set_target_properties(TSCLibc PROPERTIES
1720
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
1821

22+
set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCLibc)
23+
1924
install(TARGETS TSCLibc
2025
ARCHIVE DESTINATION lib
2126
LIBRARY DESTINATION lib

Sources/TSCUtility/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ target_link_libraries(TSCUtility PUBLIC
3434
# NOTE(compnerd) workaround for CMake not setting up include flags yet
3535
set_target_properties(TSCUtility PROPERTIES
3636
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
37+
38+
set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCUtility)

Sources/TSCclibc/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(clibc STATIC
9+
add_library(TSCclibc STATIC
1010
libc.c)
11-
target_include_directories(clibc PUBLIC
11+
target_include_directories(TSCclibc PUBLIC
1212
include)
1313

1414
if(NOT BUILD_SHARED_LIBS)
15-
install(TARGETS clibc
15+
install(TARGETS TSCclibc
1616
ARCHIVE DESTINATION lib)
1717
endif()
18+
19+
set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCclibc)

Utilities/build-using-cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
7+
SRCROOT="`cd "${__dir}/..";pwd`"
8+
echo "SRCROOT is $SRCROOT"
9+
10+
BUILD_DIR=$SRCROOT/build
11+
echo "BUILD_DIR is $BUILD_DIR"
12+
13+
mkdir -p $BUILD_DIR
14+
cd $BUILD_DIR
15+
16+
CMAKE_Swift_FLAGS=""
17+
if (uname | grep -qi darwin); then
18+
CMAKE_Swift_FLAGS="-sdk $(xcrun --sdk macosx --show-sdk-path)"
19+
fi
20+
21+
set -x
22+
cmake \
23+
-G Ninja \
24+
-DCMAKE_BUILD_TYPE=Debug \
25+
-DCMAKE_Swift_FLAGS="$CMAKE_Swift_FLAGS" \
26+
$SRCROOT
27+
28+
ninja

cmake/modules/CMakeLists.txt

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

cmake/modules/TSCConfig.cmake.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(@TSC_EXPORTS_FILE@)

0 commit comments

Comments
 (0)