Skip to content

Commit

Permalink
update cmakelist for unix
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendon committed Dec 12, 2024
1 parent 6af5abc commit 7130834
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 87 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(INCLUDE_PATHS
${BOOST_ROOT}
${CROW_INCLUDE_DIR}
${ASIO_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIRS}
/usr/local/include/mongocxx/v_noabi
/usr/local/include/bsoncxx/v_noabi
/usr/local/include/libmongoc-1.0
Expand All @@ -48,7 +49,15 @@ set(INCLUDE_PATHS
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${MONGO_CXX_ROOT}/build)

# Set paths for OpenSSL libraries
set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl@3")
if (APPLE)
set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl@3")
else()
set(OPENSSL_ROOT_DIR "/usr")
set(OPENSSL_INCLUDE_DIR "/usr/include")
set(OPENSSL_CRYPTO_LIBRARY "/usr/lib/x86_64-linux-gnu/libcrypto.so")
set(OPENSSL_SSL_LIBRARY "/usr/lib/x86_64-linux-gnu/libssl.so")
endif()

find_package(OpenSSL REQUIRED)

set(SOURCE_FILES
Expand Down
159 changes: 73 additions & 86 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,46 @@ BASE_PATH="$(pwd)"

# Define directories
BUILD_DIR="$BASE_PATH/build"
SRC_DIR="$BASE_PATH/src"
TEST_DIR="$BASE_PATH/test"
EXTERNAL_LIBRARIES_DIR="$BASE_PATH/external_libraries"
COVERAGE_DIR="$BUILD_DIR/coverage"

# Create external_libraries directory if it doesn't exist
mkdir -p "$EXTERNAL_LIBRARIES_DIR"

# Install system dependencies
echo "Installing system dependencies..."
sudo apt-get update
sudo apt-get install -y \
libmongoc-1.0-0 \
curl \
cmake \
build-essential \
libssl-dev \
openssl \
pkg-config \
libboost-all-dev \
libpoco-dev \
libcurl4-openssl-dev \
docker.io

# Install spdlog
echo "Installing spdlog..."
if [ ! -d "spdlog" ]; then
git clone https://github.com/gabime/spdlog.git
cd spdlog
git checkout v1.12.0
mkdir build && cd build
cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON
sudo make install
sudo ldconfig
cd ../..
else
echo "spdlog already exists, skipping installation."
fi

# Install external libraries
echo "Starting the download of external libraries..."
# Create external_libraries directory
mkdir -p "$EXTERNAL_LIBRARIES_DIR"
cd "$EXTERNAL_LIBRARIES_DIR"

cd "$EXTERNAL_LIBRARIES_DIR" || { echo "Failed to change to external libraries directory"; exit 1; }
# Clone Crow
echo "Setting up Crow..."
[ ! -d "Crow" ] && git clone --recurse-submodules https://github.com/CrowCpp/Crow.git Crow

# Function to download and extract library
download_and_extract() {
Expand All @@ -28,128 +55,88 @@ download_and_extract() {
echo "Downloading $name..."
curl -L "$url" -o "$file"
tar -xzf "$file"
mv "${dir%-*}" "$dir"
# Get the actual extracted directory name
extracted_dir=$(tar -tzf "$file" | head -1 | cut -f1 -d"/")
# Move only if source and destination are different
if [ "$extracted_dir" != "$dir" ]; then
mv "$extracted_dir" "$dir"
fi
rm "$file"
else
echo "$name library already exists, skipping download."
fi
}

# Download libraries
[ ! -d "Crow" ] && git clone --recurse-submodules https://github.com/CrowCpp/Crow.git Crow || echo "Crow library already exists, skipping download."

# Download and setup libraries
echo "Setting up Boost..."
download_and_extract "Boost" "https://archives.boost.io/release/1.86.0/source/boost_1_86_0.tar.gz" "boost" "boost_1_86_0.tar.gz"

echo "Setting up Asio..."
download_and_extract "Asio" "https://sourceforge.net/projects/asio/files/asio/1.30.2%20%28Stable%29/asio-1.30.2.tar.gz/download" "asio" "asio-1.30.2.tar.gz"

# Download and install MongoDB C++ Driver
# MongoDB C++ Driver
echo "Setting up MongoDB C++ Driver..."
if [ ! -d "mongo-cxx-driver" ]; then
echo "Installing MongoDB C++ Driver..."
download_and_extract "MongoDB C++ Driver" "https://github.com/mongodb/mongo-cxx-driver/releases/download/r3.11.0/mongo-cxx-driver-r3.11.0.tar.gz" "mongo-cxx-driver" "mongo-cxx-driver-r3.11.0.tar.gz"
cd mongo-cxx-driver/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DMONGOCXX_OVERRIDE_DEFAULT_INSTALL_PREFIX=OFF
sudo cmake --build . --target install
cd ../..
else
echo "MongoDB C++ Driver already exists, skipping installation."
fi

# Download and install jwt-cpp
# JWT-CPP
echo "Setting up jwt-cpp..."
if [ ! -d "jwt-cpp" ]; then
echo "Installing jwt-cpp..."
git clone https://github.com/Thalhammer/jwt-cpp.git
cd jwt-cpp
mkdir build && cd build
cmake ..
sudo make install
cd ../..
else
echo "jwt-cpp already exists, skipping installation."
fi

# Download and install bcrypt
# BCrypt
echo "Setting up bcrypt..."
if [ ! -d "bcrypt" ]; then
echo "Installing bcrypt..."
git clone https://github.com/trusch/libbcrypt.git bcrypt
cd bcrypt
mkdir build && cd build
cmake ..
make
sudo make install
cd ../..
else
echo "bcrypt already exists, skipping installation."
fi

# Download and install spdlog
if [ ! -d "spdlog" ]; then
echo "Installing spdlog..."
git clone https://github.com/gabime/spdlog.git
cd spdlog
mkdir build && cd build
cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON
sudo make install
cd ../..
else
echo "spdlog already exists, skipping installation."
fi

# Download and install Poco library
# Poco
echo "Setting up Poco library..."
if [ ! -d "Poco" ]; then
echo "Downloading and installing Poco library..."
git clone https://github.com/pocoproject/poco.git Poco
cd Poco || { echo "Failed to change to Poco directory"; exit 1; }
cd Poco
mkdir -p cmake-build
cd cmake-build || { echo "Failed to change to Poco build directory"; exit 1; }
cd cmake-build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
make install
cd ../../
else
echo "Poco library already exists, skipping download and installation."
sudo make install
cd ../..
fi

echo "All external libraries processed successfully."

# Return to external libraries directory
cd "$EXTERNAL_LIBRARIES_DIR" || { echo "Failed to return to external libraries directory"; exit 1; }

# Clean up downloaded archives if they exist
for archive in asio-1.30.2.tar.gz boost_1_86_0.tar.gz mongo-cxx-driver-r3.11.0.tar.gz
do
if [ -f "$archive" ]; then
rm "$archive"
echo "Removed $archive"
else
echo "$archive not found, skipping removal"
fi
done

echo "All external libraries downloaded and installed successfully."

# Return to the base directory
cd "$BASE_PATH" || { echo "Failed to return to base directory"; exit 1; }

# Create build directory if it doesn't exist
# Return to base directory and setup build
cd "$BASE_PATH"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake .. -DCMAKE_BUILD_TYPE=Release

cd "$BUILD_DIR" || { echo "Failed to change to build directory"; exit 1; }
cmake ..
# Build the project
echo "Building the project..."
cmake --build . --config Release

# Compile the project
make -C "$BUILD_DIR" || { echo "Compilation failed"; exit 1; }
# Setup database
echo "Setting up database..."
docker compose up -d

sudo apt-get update
sudo apt-get install libmongoc-1.0-0

# Clean up downloaded archives if they exist
for archive in asio-1.30.2.tar.gz boost_1_86_0.tar.gz mongo-cxx-driver-r3.11.0.tar.gz
do
if [ -f "$archive" ]; then
rm "$archive"
echo "Removed $archive"
else
echo "$archive not found, skipping removal"
fi
done
# Clean up
echo "Cleaning up..."
cd "$EXTERNAL_LIBRARIES_DIR"
rm -f *.tar.gz

echo "Setup complete!"
echo "Setup complete! 🎉"
1 change: 1 addition & 0 deletions spdlog
Submodule spdlog added at 7e635f

0 comments on commit 7130834

Please sign in to comment.