diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d31750..69750b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,50 +1,58 @@ -cmake_minimum_required(VERSION 3.10) -project(AppwriteSDK CXX) +cmake_minimum_required(VERSION 3.15) +project(AppwriteSDK VERSION 1.0.0 LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) -include_directories(${CMAKE_BINARY_DIR}/conan/include) -link_directories(${CMAKE_BINARY_DIR}/conan/lib) +if(WIN32) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + add_definitions(-DWIN32_LEAN_AND_MEAN) + add_definitions(-DNOMINMAX) +endif() -find_package(CURL REQUIRED) +find_package(PkgConfig QUIET) -set(SRCS - src/Appwrite.cpp - src/services/Account.cpp - src/services/Query.cpp - src/services/Databases.cpp - src/services/Messaging.cpp - src/services/Storage.cpp - src/services/Health.cpp - src/Utils.cpp - src/Validator.cpp -) +# Ensure CMake uses Conan's find modules for dependencies +if(EXISTS "${CMAKE_BINARY_DIR}/generators/CURLConfig.cmake") + list(PREPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/generators") +endif() -add_library(AppwriteSDK STATIC ${SRCS}) +find_package(CURL REQUIRED) -include_directories(include) +file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") +file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") -target_link_libraries(AppwriteSDK CURL::libcurl) +add_library(AppwriteSDK STATIC ${SOURCES}) -set_target_properties(AppwriteSDK PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib +target_include_directories(AppwriteSDK + PUBLIC + $ + $ + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src ) -set(HEADERS - include/Appwrite.hpp - include/classes/Account.hpp - include/classes/Query.hpp - include/classes/Databases.hpp - include/classes/Messaging.hpp - include/classes/Storage.hpp - include/classes/Health.hpp - include/config/Config.hpp - include/enums/HttpStatus.hpp - include/exceptions/AppwriteException.hpp - include/Utils.hpp - include/Validator.hpp +if(TARGET CURL::libcurl) + target_link_libraries(AppwriteSDK PUBLIC CURL::libcurl) + message(STATUS "AppwriteSDK: Linked with CURL::libcurl") +elseif(TARGET CURL::CURL) + target_link_libraries(AppwriteSDK PUBLIC CURL::CURL) + message(STATUS "AppwriteSDK: Linked with CURL::CURL") +else() + message(FATAL_ERROR "CURL library not found! Ensure Conan CMakeDeps configured correctly.") +endif() + +if(WIN32) + target_link_libraries(AppwriteSDK PRIVATE ws2_32 wldap32 crypt32) +endif() + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION include/AppwriteSDK +) +install(TARGETS AppwriteSDK + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin ) -install(DIRECTORY include/ DESTINATION /usr/local/include/AppwriteSDK) -install(FILES ${HEADERS} DESTINATION /usr/local/include/AppwriteSDK) -install(TARGETS AppwriteSDK ARCHIVE DESTINATION /usr/local/lib) +message(STATUS "AppwriteSDK: Ready for install, all dependencies resolved.") diff --git a/README.md b/README.md index d9388c5..a8bd991 100644 --- a/README.md +++ b/README.md @@ -24,30 +24,56 @@ This **C++ SDK** is built from scratch as a **prototype** for interacting with A ### Prerequisites -Before you begin, ensure that you have `conan` & `clang-format` installed on your system. -- You can install `conan` using `pip`, -- and `clang-format` using `apt` - +Before you begin, ensure `conan`, `clang-format`, and `cmake` are installed: ```bash -sudo apt install clang-format +sudo apt install clang-format cmake pip install conan ``` -### Build From Source Code +#### Build From Source Code -Clone the repository and run the following commands +Clone the repository and run the following commands **(out-of-source build, all artifacts in `build/` only):** ```bash mkdir build && cd build -conan install .. --build=missing -cmake .. +conan install .. --output-folder=. --build=missing +cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release make ``` +All Conan and CMake files will be in `build/`. + Install the SDK. ```bash sudo make install ``` +## Installation (Windows) + +#### Prerequisites + +- Install [MinGW-w64](http://mingw-w64.org/) and add it to your system PATH. +- Install [Conan](https://conan.io/) using Python/pip. +- Install [CMake](https://cmake.org/). + +#### Build From Source Code + +1. Open a MinGW-w64 environment or Command Prompt with MinGW in PATH. +2. Clone the repository and run: + +```bash +mkdir build +cd build +conan install .. --output-folder=. --build=missing +cmake .. -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake +mingw64-make +``` +#### Install SDK (MinGW) + +To copy the headers and library to your MinGW installation, use: +./install_windows.bat + +This will place headers in `\include\AppwriteSDK` and library files in `\lib`. + ## Getting Started ### Make Your First Request diff --git a/build_windows.bat b/build_windows.bat new file mode 100644 index 0000000..423ef8f --- /dev/null +++ b/build_windows.bat @@ -0,0 +1,58 @@ +@echo off +echo AppwriteSDK Windows Build (Fixed) +echo ================================= + +:: Ensure MinGW is in PATH +where gcc >nul 2>&1 +if %errorlevel% neq 0 ( + echo Error: GCC not found. Ensure MinGW is in your PATH. + pause + exit /b 1 +) + +:: Clean build directory +if exist "build" rmdir /s /q "build" +mkdir build +cd build + +:: Install dependencies with explicit output folder +echo Installing dependencies with Conan... +conan install .. --output-folder=. --build=missing -s build_type=Release + +:: Verify toolchain file was created +if exist "conan_toolchain.cmake" ( + echo ✅ Found conan_toolchain.cmake + set "TOOLCHAIN_FILE=conan_toolchain.cmake" +) else ( + echo ❌ conan_toolchain.cmake not found, listing build contents: + dir /b + echo Trying without toolchain file... + set "TOOLCHAIN_FILE=" +) + +:: Configure with CMake +echo Configuring with CMake... +if defined TOOLCHAIN_FILE ( + cmake .. -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=%TOOLCHAIN_FILE% -DCMAKE_BUILD_TYPE=Release +) else ( + cmake .. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release +) + +if %errorlevel% neq 0 ( + echo ❌ CMake configuration failed + pause + exit /b 1 +) + +:: Build +echo Building... +cmake --build . --config Release + +if %errorlevel% equ 0 ( + echo ✅ Build successful! + cd .. + call install_windows.bat +) else ( + echo ❌ Build failed + pause +) diff --git a/cmake/AppwriteSDKConfig.cmake.in b/cmake/AppwriteSDKConfig.cmake.in new file mode 100644 index 0000000..61ff2b1 --- /dev/null +++ b/cmake/AppwriteSDKConfig.cmake.in @@ -0,0 +1,10 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +find_dependency(CURL REQUIRED) +find_dependency(nlohmann_json REQUIRED) + +include("${CMAKE_CURRENT_LIST_DIR}/AppwriteSDKTargets.cmake") + +check_required_components(AppwriteSDK) diff --git a/conanfile.txt b/conanfile.txt index b05a13b..960cc4b 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,9 +1,9 @@ [requires] -libcurl/8.10.1 +libcurl/7.87.0 [generators] CMakeDeps CMakeToolchain -[layout] -cmake_layout \ No newline at end of file +[options] +libcurl/*:shared=False diff --git a/install_windows.bat b/install_windows.bat new file mode 100644 index 0000000..ad075db --- /dev/null +++ b/install_windows.bat @@ -0,0 +1,24 @@ +@echo off +echo Installing AppwriteSDK to MinGW directories... + +:: Find MinGW installation +for /f "tokens=*" %%i in ('where gcc') do set "GCC_PATH=%%i" +for %%i in ("%GCC_PATH%") do set "MINGW_BIN=%%~dpi" +set "MINGW_ROOT=%MINGW_BIN:~0,-5%" + +echo MinGW Root: %MINGW_ROOT% + +:: Install headers +set "INCLUDE_DIR=%MINGW_ROOT%\include\AppwriteSDK" +if not exist "%INCLUDE_DIR%" mkdir "%INCLUDE_DIR%" +xcopy /E /I /Y "include\*" "%INCLUDE_DIR%\" + +:: Install libraries +copy /Y "build\*.a" "%MINGW_ROOT%\lib\" 2>nul + +echo Installation complete! +echo Headers installed to: %INCLUDE_DIR% +echo Libraries installed to: %MINGW_ROOT%\lib\ +echo. +echo Test compilation: g++ -o test.exe test.cpp -lAppwriteSDK +pause