Skip to content

Commit

Permalink
Update Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
irfanghat committed Nov 18, 2024
1 parent 8b3cb9a commit ec88bf3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 112 deletions.
99 changes: 36 additions & 63 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,70 +21,43 @@ test:
cargo test --manifest-path=$(RUST_MANIFEST_PATH) -- --nocapture


# C++ target config.
CPP_SRC_DIR = ./librender_cdk/src
CPP_BUILD_DIR = build
CPP_LIBRARY_DIR = librender_cdk
CPP_INCLUDE_DIRS = -I./librender_cdk/extern/dotenv-cpp/include -I./librender_cdk/include
CPP_FLAGS = -std=c++17 -Wall

# OpenSSL for HTTPS, json for de/serialization.
CPP_LIBS = -lssl -lcrypto -ljsoncpp


# Identifier for the static library.
CPP_LIB_NAME = librender_cdk.a

# Identifier for the shared library.
CPP_SHARED_LIB_NAME = librender_cdk.so

# Ensure the C++ build directory exists.
$(CPP_BUILD_DIR):
mkdir -p $(CPP_BUILD_DIR)


# Static library build target.
cpp-static-lib: $(CPP_BUILD_DIR)
ar rcs $(CPP_BUILD_DIR)/$(CPP_LIB_NAME) $(CPP_SRC_DIR)/*.cpp


# Shared library build target.
cpp-shared-lib: $(CPP_BUILD_DIR)
g++ -shared -fPIC $(CPP_FLAGS) $(CPP_INCLUDE_DIRS) $(CPP_SRC_DIR)/*.cpp -o $(CPP_BUILD_DIR)/$(CPP_SHARED_LIB_NAME) $(CPP_LIBS)


# Clean C++ build files and libraries.
cpp-clean:
rm -rf $(CPP_BUILD_DIR)


# Combined targets.
build: debug cpp-static-lib
release-build: release cpp-static-lib


# Optionally build shared library.
build-shared: debug cpp-shared-lib
release-build-shared: release cpp-shared-lib


# Run both Rust and C++ executables.
run-all: build
cargo run


# Clean all build files, both Rust and C++.
clean: cpp-clean
cargo clean


# CPP Compiler and flags.
CXX = g++
CXX_FLAGS = -std=c++17 -fPIC -I./librender_cdk/extern/dotenv-cpp/include -I./librender_cdk/extern/nlohmann-json/include
LD_FLAGS = -lcurl -ljsoncpp
CPP_SRC = ./librender_cdk/src/authorization.cpp ./librender_cdk/src/environment_manager.cpp ./librender_cdk/src/service_manager.cpp
CPP_OUTPUT_DIR = ./librender_cdk/build
UNIT_TEST_SRC = ./tests/unit_tests.cpp

# Install missing dependencies.
check-dependencies:
@dpkg -l | grep -E 'nlohmann-json3-dev|libjsoncpp-dev' || (echo "Installing missing dependencies..." && sudo apt update && sudo apt -y install nlohmann-json3-dev libjsoncpp-dev)

# CPP targets.
shared: $(CPP_OUTPUT_DIR) check-dependencies
$(CXX) $(CXX_FLAGS) -shared $(CPP_SRC) -o $(CPP_OUTPUT_DIR)/librender_cdk.so $(LD_FLAGS)

$(CPP_OUTPUT_DIR):
mkdir -p $(CPP_OUTPUT_DIR)

unit_test: shared $(UNIT_TEST_SRC)
$(CXX) $(CXX_FLAGS) $(UNIT_TEST_SRC) -L$(CPP_OUTPUT_DIR) -lrender_cdk -o $(CPP_OUTPUT_DIR)/unit_tests
# Set the LD_LIBRARY_PATH to include the directory where the shared library is located
export LD_LIBRARY_PATH=$(CPP_OUTPUT_DIR):$$LD_LIBRARY_PATH && ./$(CPP_OUTPUT_DIR)/unit_tests

# Clean all build artifacts (Rust and CPP).
clean:
rm -rf $(CPP_OUTPUT_DIR) $(CPP_OUTPUT_DIR)/unit_tests
cargo clean --manifest-path=$(RUST_MANIFEST_PATH)

# Targets to build both Rust and CPP together.
build-debug: shared debug
build-release: shared release

# Quick build for CPP (used for testing).
quick-build:
cd ./librender_cdk && g++ -I./librender_cdk/extern/dotenv-cpp/include -I./librender_cdk/extern/nlohmann-json/include src/main.cpp src/environment_manager.cpp src/authorization.cpp src/service_manager.cpp -o main_executable -lcurl -ljsoncpp
cd ./librender_cdk && g++ -I./librender_cdk/extern/dotenv-cpp/include -I./librender_cdk/extern/nlohmann-json/include src/debug-build.cpp src/environment_manager.cpp src/authorization.cpp src/service_manager.cpp -o librender_cdk_DEBUG -lcurl -ljsoncpp


# deps:
# Dependencies:
# sudo apt -y install nlohmann-json3-dev
# sudo apt -y install libjsoncpp-dev
# sudo apt-get install doxygen

# Quick build command: g++ -I./librender_cdk/extern/dotenv-cpp/include -I./librender_cdk/extern/nlohmann-json/include src/main.cpp src/environment_manager.cpp src/authorization.cpp src/service_manager.cpp -o librender_cdk_DEBUG -lcurl -ljsoncpp
Empty file.
File renamed without changes.
Empty file.
49 changes: 0 additions & 49 deletions librender_cdk/tests/unit_tests.cpp

This file was deleted.

15 changes: 15 additions & 0 deletions tests/unit_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "../librender_cdk/src/authorization.h"
#include "../librender_cdk/src/environment_manager.h"
#include <iostream>

int main() {
try {
Config config = load_config();
AuthorizationManager auth_manager(config.api_key);
auth_manager.list_authorized_users(config.owner_credentials, "10");
} catch (const std::exception &e) {
std::cerr << "Error: " << e.what() << "\n";
return 1;
}
return 0;
}

0 comments on commit ec88bf3

Please sign in to comment.