Skip to content
This repository was archived by the owner on Apr 12, 2025. It is now read-only.

Commit 467a339

Browse files
committed
(feat): Add CMake and build script
1 parent 452bc3d commit 467a339

File tree

5 files changed

+258
-7
lines changed

5 files changed

+258
-7
lines changed

.gitignore

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,121 @@
1-
.DS_Store
2-
/.build
3-
/Packages
1+
# Xcode
2+
#
3+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4+
5+
## User settings
46
xcuserdata/
5-
DerivedData/
6-
.swiftpm/configuration/registries.json
7-
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8-
.netrc
7+
8+
## Obj-C/Swift specific
9+
*.hmap
10+
11+
## App packaging
12+
*.ipa
13+
*.dSYM.zip
14+
*.dSYM
15+
16+
## Playgrounds
17+
timeline.xctimeline
18+
playground.xcworkspace
19+
20+
# Swift Package Manager
21+
#
22+
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
23+
# Packages/
24+
# Package.pins
25+
# Package.resolved
26+
# *.xcodeproj
27+
#
28+
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
29+
# hence it is not needed unless you have added a package configuration file to your project
30+
# .swiftpm
31+
32+
.build/
33+
34+
# CocoaPods
35+
#
36+
# We recommend against adding the Pods directory to your .gitignore. However
37+
# you should judge for yourself, the pros and cons are mentioned at:
38+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
39+
#
40+
# Pods/
41+
#
42+
# Add this line if you want to avoid checking in source code from the Xcode workspace
43+
# *.xcworkspace
44+
45+
# Carthage
46+
#
47+
# Add this line if you want to avoid checking in source code from Carthage dependencies.
48+
# Carthage/Checkouts
49+
50+
Carthage/Build/
51+
52+
# fastlane
53+
#
54+
# It is recommended to not store the screenshots in the git repo.
55+
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
56+
# For more information about the recommended setup visit:
57+
# https://docs.fastlane.tools/best-practices/source-control/#source-control
58+
59+
fastlane/report.xml
60+
fastlane/Preview.html
61+
fastlane/screenshots/**/*.png
62+
fastlane/test_output
63+
64+
# Prerequisites
65+
*.d
66+
67+
# Object files
68+
*.o
69+
*.ko
70+
*.obj
71+
*.elf
72+
73+
# Linker output
74+
*.ilk
75+
*.map
76+
*.exp
77+
78+
# Precompiled Headers
79+
*.gch
80+
*.pch
81+
82+
# Libraries
83+
*.lib
84+
*.a
85+
*.la
86+
*.lo
87+
88+
# Shared objects (inc. Windows DLLs)
89+
*.dll
90+
*.so
91+
*.so.*
92+
*.dylib
93+
94+
# Executables
95+
*.exe
96+
*.out
97+
*.app
98+
*.i*86
99+
*.x86_64
100+
*.hex
101+
102+
# Debug files
103+
*.dSYM/
104+
*.su
105+
*.idb
106+
*.pdb
107+
108+
# Kernel Module Compile Results
109+
*.mod*
110+
*.cmd
111+
.tmp_versions/
112+
modules.order
113+
Module.symvers
114+
Mkfile.old
115+
dkms.conf
116+
117+
cmake_install.cmake
118+
CMakeCache.txt
119+
Makefile
120+
121+
build/

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CMakeLists.txt

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

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,12 @@ Once CryptoSwiftWrapper is added as a dependency using SPM, you need to ensure i
5858

5959
> [!IMPORTANT]
6060
Avoid directly including _cyfn/cyfn.h to maintain encapsulation and proper abstraction.
61+
62+
### Build process
63+
64+
After cloning the CryptoSwiftWrapper repository to your local machine, navigate to the project directory in your Terminal. Once there, run our build script:
65+
66+
```sh
67+
chmod u+x build_script.sh
68+
./build_script.sh
69+
```

build_script.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
GREEN='\033[1;32m' # Change to bold green
4+
RED='\033[0;31m'
5+
ORANGE='\033[0;33m'
6+
BOLD='\033[1m'
7+
RESET='\033[0m'
8+
9+
# Check if terminal supports ANSI escape codes
10+
if [[ "$TERM" != "xterm-256color" ]] && ! command -v tput &> /dev/null; then
11+
echo "Warning: ANSI escape codes not supported. Falling back to basic text formatting."
12+
# Define basic text formatting functions
13+
bold() { echo -e "${BOLD}$1${RESET}"; }
14+
red() { echo -e "${RED}$1${RESET}"; }
15+
green() { echo -e "${GREEN}$1${RESET}"; }
16+
orange() { echo -e "${ORANGE}$1${RESET}"; }
17+
reset() { echo -e "$1"; }
18+
else
19+
# Define functions using tput for terminal text formatting
20+
bold() { tput bold; echo -e "$1"; tput sgr0; }
21+
red() { tput setaf 1; echo -e "$1"; tput sgr0; }
22+
green() { tput setaf 2; tput bold; echo -e "$1"; tput sgr0; } # Modify green to be bold
23+
orange() { tput setaf 3; echo -e "$1"; tput sgr0; }
24+
reset() { tput sgr0; echo -e "$1"; }
25+
fi
26+
27+
bold "${BOLD}Welcome to the ScribbleLabApp CryptoSwiftWrapper build script${BOLD}"
28+
echo ""
29+
echo "Version: 0.1.0-beta (1)"
30+
echo "Copyright (c) 2024 - ScribbleLabApp. All rights reserved."
31+
echo ""
32+
33+
# Check for required tools
34+
if ! command -v cmake &> /dev/null; then
35+
red "Error: cmake is not installed."
36+
exit 1
37+
fi
38+
39+
if ! command -v make &> /dev/null; then
40+
red "Error: make is not installed."
41+
exit 1
42+
fi
43+
44+
# Build process
45+
orange "Creating build folder..."
46+
mkdir -p build
47+
cd build
48+
49+
orange "Configuring cmake..."
50+
echo ""
51+
cmake ..
52+
53+
orange "Building project..."
54+
echo ""
55+
make .
56+
57+
echo ""
58+
green "${GREEN}[Success]: Build completed successfully.${RESET}"

0 commit comments

Comments
 (0)