-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
64 lines (53 loc) · 1.95 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
##===----------------------------------------------------------------------===##
##
## This source file is part of the CryptoSwiftWrapper open source project
##
## Copyright (c) 2024 ScribbleLabApp
## Copyright (c) 2021-2024 Apple Inc. and the SwiftCrypto project authors
## Licensed under Apache License v2.0
##
## See LICENSE for license information
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
cmake_minimum_required(VERSION 3.15.1)
project(CryptoSwiftWrapper)
# Set paths
set(SWIFT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Sources/CryptoSwiftWrapper)
set(C_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Sources/_cyfn)
# Set include directories
include_directories(
${SWIFT_SRC_DIR}/include
${C_SRC_DIR}
)
# Define the Swift target name
set(SWIFT_TARGET_NAME CryptoSwiftWrapper)
# Find Swift and set its compiler path
find_program(SWIFT_EXECUTABLE swift)
if(NOT SWIFT_EXECUTABLE)
message(FATAL_ERROR "Swift compiler not found!")
endif()
# Add SwiftPM as an ExternalProject
include(ExternalProject)
ExternalProject_Add(${SWIFT_TARGET_NAME}_External
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/${SWIFT_TARGET_NAME}-prefix
SOURCE_DIR ${SWIFT_SRC_DIR}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${SWIFT_TARGET_NAME}-build
CONFIGURE_COMMAND ""
BUILD_COMMAND ${SWIFT_EXECUTABLE} build --package-path ${SWIFT_SRC_DIR}
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${SWIFT_TARGET_NAME}-build/*.dylib
)
# Dummy target for header-only C library
add_library(cyfn INTERFACE)
target_include_directories(cyfn INTERFACE ${C_SRC_DIR})
# Create custom target to build the C library
add_custom_target(CLibrary DEPENDS cyfn)
add_dependencies(CLibrary ${SWIFT_TARGET_NAME}_External)
# Optional: Install targets
# Since cyfn is a header-only library, no need to install anything
# Clean command
add_custom_target(clean-all
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/clean-all.cmake
)