Skip to content

Commit

Permalink
(feat): Add CMake and build script
Browse files Browse the repository at this point in the history
  • Loading branch information
N3v1 committed Jul 17, 2024
1 parent 452bc3d commit 467a339
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 7 deletions.
127 changes: 120 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,121 @@
.DS_Store
/.build
/Packages
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

cmake_install.cmake
CMakeCache.txt
Makefile

build/
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
)
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,12 @@ Once CryptoSwiftWrapper is added as a dependency using SPM, you need to ensure i

> [!IMPORTANT]
Avoid directly including _cyfn/cyfn.h to maintain encapsulation and proper abstraction.

### Build process

After cloning the CryptoSwiftWrapper repository to your local machine, navigate to the project directory in your Terminal. Once there, run our build script:

```sh
chmod u+x build_script.sh
./build_script.sh
```
58 changes: 58 additions & 0 deletions build_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

GREEN='\033[1;32m' # Change to bold green
RED='\033[0;31m'
ORANGE='\033[0;33m'
BOLD='\033[1m'
RESET='\033[0m'

# Check if terminal supports ANSI escape codes
if [[ "$TERM" != "xterm-256color" ]] && ! command -v tput &> /dev/null; then
echo "Warning: ANSI escape codes not supported. Falling back to basic text formatting."
# Define basic text formatting functions
bold() { echo -e "${BOLD}$1${RESET}"; }
red() { echo -e "${RED}$1${RESET}"; }
green() { echo -e "${GREEN}$1${RESET}"; }
orange() { echo -e "${ORANGE}$1${RESET}"; }
reset() { echo -e "$1"; }
else
# Define functions using tput for terminal text formatting
bold() { tput bold; echo -e "$1"; tput sgr0; }
red() { tput setaf 1; echo -e "$1"; tput sgr0; }
green() { tput setaf 2; tput bold; echo -e "$1"; tput sgr0; } # Modify green to be bold
orange() { tput setaf 3; echo -e "$1"; tput sgr0; }
reset() { tput sgr0; echo -e "$1"; }
fi

bold "${BOLD}Welcome to the ScribbleLabApp CryptoSwiftWrapper build script${BOLD}"
echo ""
echo "Version: 0.1.0-beta (1)"
echo "Copyright (c) 2024 - ScribbleLabApp. All rights reserved."
echo ""

# Check for required tools
if ! command -v cmake &> /dev/null; then
red "Error: cmake is not installed."
exit 1
fi

if ! command -v make &> /dev/null; then
red "Error: make is not installed."
exit 1
fi

# Build process
orange "Creating build folder..."
mkdir -p build
cd build

orange "Configuring cmake..."
echo ""
cmake ..

orange "Building project..."
echo ""
make .

echo ""
green "${GREEN}[Success]: Build completed successfully.${RESET}"

0 comments on commit 467a339

Please sign in to comment.