diff --git a/.gitignore b/.gitignore index f909a9c..0e0e35c 100644 --- a/.gitignore +++ b/.gitignore @@ -421,3 +421,4 @@ packages/ # vcpkg manifest mode generated files vcpkg_manifest_install_*.log /CMakeLists.txt +build/ diff --git a/Synapse/CMakeLists.txt b/Synapse/CMakeLists.txt index 671d484..749dcbc 100644 --- a/Synapse/CMakeLists.txt +++ b/Synapse/CMakeLists.txt @@ -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 @@ -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 diff --git a/bootstrap.ps1 b/bootstrap.ps1 index ee3546b..f02a71a 100644 --- a/bootstrap.ps1 +++ b/bootstrap.ps1 @@ -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 @@ -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) @@ -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" @@ -104,4 +113,6 @@ do { } while ($true) # Infinite loop until 'yes' is entered -& cmake ../synapse -G $selected_generator \ No newline at end of file +& cmake ../synapse -G $selected_generator +& ninja +& .\bin\Synapse.exe \ No newline at end of file diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..07901fb --- /dev/null +++ b/bootstrap.sh @@ -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!" \ No newline at end of file