Skip to content

Feature/macos support #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,4 @@ packages/
# vcpkg manifest mode generated files
vcpkg_manifest_install_*.log
/CMakeLists.txt
build/
67 changes: 50 additions & 17 deletions Synapse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.10)

# Project Name
project(Synapse LANGUAGES CXX)
project(Synapse)

# Set C++ Standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Resolve Solution Directory (Parent of CMake Directory)
set(SOLUTION_DIR ${CMAKE_SOURCE_DIR}/..)
# Windows-specific configuration
if(WIN32)
set(CMAKE_PREFIX_PATH "C:/Program Files/Armadillo")
set(CMAKE_INCLUDE_PATH "C:/Program Files/Armadillo/include")
set(CMAKE_LIBRARY_PATH "C:/Program Files/Armadillo/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib)
endif()

# Include Paths
include_directories(
${SOLUTION_DIR}/armadillo/include # Armadillo headers
${SOLUTION_DIR}/vcpkg_installed/x64-windows/include # VCPKG headers
)
# macOS-specific configuration
if(APPLE)
# Find required packages using Homebrew paths
set(CMAKE_PREFIX_PATH "/opt/homebrew/opt/armadillo;/opt/homebrew/opt/openblas;/opt/homebrew/opt/eigen")
set(CMAKE_INCLUDE_PATH "/opt/homebrew/opt/armadillo/include;/opt/homebrew/opt/openblas/include;/opt/homebrew/opt/eigen/include")
set(CMAKE_LIBRARY_PATH "/opt/homebrew/opt/armadillo/lib;/opt/homebrew/opt/openblas/lib")

# Set Armadillo paths for macOS
set(ARMADILLO_INCLUDE_DIRS "/opt/homebrew/opt/armadillo/include")
set(ARMADILLO_LIBRARIES "/opt/homebrew/opt/armadillo/lib/libarmadillo.dylib")

# Set OpenBLAS paths for macOS
set(OpenBLAS_INCLUDE_DIRS "/opt/homebrew/opt/openblas/include")
set(OpenBLAS_LIBRARIES "/opt/homebrew/opt/openblas/lib/libopenblas.dylib")

# Set Eigen paths for macOS
set(EIGEN3_INCLUDE_DIR "/opt/homebrew/opt/eigen/include/eigen3")
endif()

# Library Paths
link_directories(
${SOLUTION_DIR}/armadillo/lib # Armadillo libraries
${SOLUTION_DIR}/OpenBlas # OpenBLAS libraries
)
# Find required packages
find_package(Armadillo REQUIRED)
find_package(OpenBLAS REQUIRED)
find_package(Eigen3 REQUIRED)

# Source Files
set(SOURCES
Expand All @@ -45,9 +70,17 @@ set(HEADERS
add_executable(Synapse ${SOURCES} ${HEADERS})

# Link External Libraries
target_link_libraries(Synapse PRIVATE
${SOLUTION_DIR}/armadillo/lib/armadillo_x64d.lib
${SOLUTION_DIR}/OpenBlas/libopenblas.lib
if(APPLE)
target_link_libraries(Synapse PRIVATE ${ARMADILLO_LIBRARIES} ${OpenBLAS_LIBRARIES})
else()
target_link_libraries(Synapse PRIVATE Armadillo::Armadillo OpenBLAS::OpenBLAS)
endif()

# Include directories
target_include_directories(Synapse PRIVATE
${ARMADILLO_INCLUDE_DIRS}
${OpenBLAS_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
)

# Enable Debug Symbols in Debug Mode
Expand Down
21 changes: 16 additions & 5 deletions bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
$vcpkgDir = "$PSScriptRoot\vcpkg"
$vcpkgExe = "$vcpkgDir\vcpkg.exe"

# Check if Ninja is installed
$ninjaExe = (Get-Command ninja -ErrorAction SilentlyContinue).Source
if (-not $ninjaExe) {
Write-Host "Ninja not found! Installing using winget..." -ForegroundColor Yellow
winget install Ninja-build.Ninja --silent
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
$ninjaExe = (Get-Command ninja -ErrorAction SilentlyContinue).Source
if (-not $ninjaExe) {
Write-Host "Ninja installation failed!" -ForegroundColor Red
exit 1
}
}

# Ninja,vcpkg
# Check if vcpkg is available in the system environment
Expand Down Expand Up @@ -47,11 +59,10 @@ else
& vcpkg install
}


# vcpkg section up.

Write-Host "Performing Cmake Configuration" -ForegroundColor Yellow
# Check if CMake is installed
# Check if CMake is installed
$cmakeExe = (Get-Command cmake -ErrorAction SilentlyContinue).Source

if (-not $cmakeExe)
Expand All @@ -71,9 +82,7 @@ if (-not $cmakeExe)
}
}


# Run CMake to list available generators

$cmakeGenerators = & cmake --help | Select-String "Generators" -Context 0,50 | Out-String
Write-Host "Available CMake Generators: $cmakeGenerators"

Expand Down Expand Up @@ -104,4 +113,6 @@ do {

} while ($true) # Infinite loop until 'yes' is entered

& cmake ../synapse -G $selected_generator
& cmake ../synapse -G $selected_generator
& ninja
& .\bin\Synapse.exe
115 changes: 115 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash

# Define the local vcpkg directory within the cloned repository
VCPKG_DIR="$(dirname "$0")/vcpkg"
VCPKG_EXE="$VCPKG_DIR/vcpkg"

# Function to print colored output
print_colored() {
local color=$1
local message=$2
case $color in
"yellow") echo -e "\033[1;33m$message\033[0m" ;;
"green") echo -e "\033[1;32m$message\033[0m" ;;
"red") echo -e "\033[1;31m$message\033[0m" ;;
"cyan") echo -e "\033[1;36m$message\033[0m" ;;
*) echo "$message" ;;
esac
}

# Check if running on macOS
if [[ "$OSTYPE" != "darwin"* ]]; then
print_colored "red" "This script is for macOS only. Please use bootstrap.ps1 for Windows."
exit 1
fi

# Check if vcpkg is available in the system
if command -v vcpkg &> /dev/null; then
print_colored "green" "System-wide vcpkg found: $(which vcpkg)"
elif [ -f "$VCPKG_EXE" ]; then
print_colored "green" "Local vcpkg found: $VCPKG_EXE"
else
print_colored "yellow" "vcpkg not found. Installing locally..."

# Clone the vcpkg repository
print_colored "yellow" "Cloning vcpkg repository..."
git clone https://github.com/microsoft/vcpkg.git "$VCPKG_DIR"

if [ ! -d "$VCPKG_DIR" ]; then
print_colored "red" "Failed to clone vcpkg repository."
exit 1
fi

# Run the bootstrap script to build vcpkg
print_colored "yellow" "Bootstrapping vcpkg..."
"$VCPKG_DIR/bootstrap-vcpkg.sh"

if [ -f "$VCPKG_EXE" ]; then
print_colored "green" "vcpkg installation completed successfully."
# Add vcpkg to the environment PATH (only for this session)
export PATH="$VCPKG_DIR:$PATH"
print_colored "green" "vcpkg set for local path env var"
else
print_colored "red" "vcpkg installation failed."
exit 1
fi

print_colored "yellow" "Installing dependencies"
vcpkg install
fi

# Check if Homebrew is installed
if ! command -v brew &> /dev/null; then
print_colored "yellow" "Homebrew not found! Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

# Install required packages
print_colored "yellow" "Installing required packages..."
brew install cmake armadillo openblas eigen

# Create build directory in the Synapse subdirectory
print_colored "yellow" "Creating build directory..."
cd Synapse

# Show available build systems and prompt for choice
print_colored "cyan" "Available CMake Generators:"
cmake --help | grep -A 50 "Generators" | grep -v "Generators"

print_colored "yellow" "Please copy and paste the generator name from the list above"
read -p "Enter generator name: " selected_generator

print_colored "cyan" "Selected generator: $selected_generator"

while true; do
read -p "Do you want to continue? (yes/no): " response
response=$(echo "$response" | tr '[:upper:]' '[:lower:]' | tr -d ' ')

if [ "$response" = "yes" ]; then
print_colored "green" "Proceeding..."
break
elif [ "$response" = "no" ]; then
print_colored "yellow" "You selected No. Asking again..."
else
print_colored "red" "Invalid input. Please enter 'yes' or 'no'."
fi
done

print_colored "yellow" "Cleaning build directory..."
rm -rf build
mkdir -p build
cd build

print_colored "cyan" "Configuring with $selected_generator..."
cmake .. -G "$selected_generator"

print_colored "cyan" "Building..."
if [[ "$selected_generator" == "Ninja" ]]; then
ninja
elif [[ "$selected_generator" == "Xcode" ]]; then
xcodebuild -configuration Debug
else
make
fi

print_colored "green" "Build complete!"