Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
124 changes: 82 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,90 @@
cmake_minimum_required(VERSION 3.10)
project(AppwriteSDK CXX)

set(CMAKE_CXX_STANDARD 11)

include_directories(${CMAKE_BINARY_DIR}/conan/include)
link_directories(${CMAKE_BINARY_DIR}/conan/lib)

find_package(CURL REQUIRED)

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
)
cmake_minimum_required(VERSION 3.15)
project(AppwriteSDK VERSION 1.0.0 LANGUAGES CXX)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 11)

This should be 17 i guess, keeping the same as the current standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have set the standard set as 17 only is there an issue?

set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Platform-specific configurations
if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DNOMINMAX)
endif()

# Include Conan toolchain
include(${CMAKE_BINARY_DIR}/Release/generators/conan_toolchain.cmake)

# Make PkgConfig optional for Windows compatibility
find_package(PkgConfig QUIET)

add_library(AppwriteSDK STATIC ${SRCS})
# CRITICAL: Use Conan targets directly without find_package
# This bypasses CMake's problematic built-in find modules
set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/generators ${CMAKE_PREFIX_PATH})

include_directories(include)
# Include Conan's generated target files directly
include(${CMAKE_BINARY_DIR}/generators/CURL-config.cmake OPTIONAL)
include(${CMAKE_BINARY_DIR}/generators/nlohmann_json-config.cmake OPTIONAL)

target_link_libraries(AppwriteSDK CURL::libcurl)
# Alternative: Load all Conan targets
file(GLOB CONAN_CONFIGS "${CMAKE_BINARY_DIR}/generators/*-config.cmake")
foreach(config_file ${CONAN_CONFIGS})
include(${config_file})
endforeach()

set_target_properties(AppwriteSDK PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
# Create a simple library (adjust source file locations as needed)
# For testing, create a minimal library
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/dummy.cpp

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only includes dummy.cpp but misses all the actual source files (Appwrite.cpp, Account.cpp, Query.cpp, etc.). Doesn't it need to include all implementation files like the existing CMake does?

)

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 dummy.cpp doesn't exist, create a header-only library
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/dummy.cpp)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt this conditional INTERFACE library approach incorrect for a static library. We need to explicitly specify STATIC library type and include all source files, not just dummy.cpp, the dummy file doesn't exist in the src folder

add_library(AppwriteSDK INTERFACE)
target_include_directories(AppwriteSDK
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
else()
add_library(AppwriteSDK ${SOURCES})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing explicit STATIC library type specification.

target_include_directories(AppwriteSDK
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
)
endif()

# Link libraries using Conan targets (these should be available now)
# Handle CURL target compatibility
if(TARGET CURL::libcurl)
set(CURL_TARGET CURL::libcurl)
elseif(TARGET CURL::CURL)
set(CURL_TARGET CURL::CURL)
else()
# Fallback to variables
set(CURL_TARGET ${CURL_LIBRARIES})
endif()

target_link_libraries(AppwriteSDK
INTERFACE
${CURL_TARGET}
nlohmann_json::nlohmann_json
)

install(DIRECTORY include/ DESTINATION /usr/local/include/AppwriteSDK)
install(FILES ${HEADERS} DESTINATION /usr/local/include/AppwriteSDK)
install(TARGETS AppwriteSDK ARCHIVE DESTINATION /usr/local/lib)
if(WIN32)
target_link_libraries(AppwriteSDK INTERFACE ws2_32 wldap32 crypt32)
endif()

message(STATUS "AppwriteSDK configured successfully with CURL target: ${CURL_TARGET}")

# Windows-specific linking
if(WIN32)
target_link_libraries(AppwriteSDK PRIVATE ws2_32 wldap32 crypt32)
endif()

# Print debug info
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message(STATUS "Available targets: ${CMAKE_BINARY_DIR}/generators")
36 changes: 36 additions & 0 deletions build_windows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@echo off
echo AppwriteSDK Windows Build
echo ========================

:: Create build directory
if not exist "build" mkdir build
cd build

:: Install dependencies
echo Installing dependencies with Conan...
conan install .. --build=missing -s build_type=Release

:: Configure using Conan toolchain
echo Configuring with CMake using Conan toolchain...
cmake .. -G "MinGW Makefiles" ^
-DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake ^
-DCMAKE_BUILD_TYPE=Release

if %errorlevel% neq 0 (
echo Configuration failed. Check the error messages above.
pause
exit /b 1
)

echo Building...
cmake --build . --config Release

if %errorlevel% equ 0 (
echo Build successful!
echo Proceeding with installation...
cd ..
call install_windows.bat
) else (
echo Build failed. Check the error messages above.
pause
)
10 changes: 10 additions & 0 deletions cmake/AppwriteSDKConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 7 additions & 2 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
[requires]
libcurl/8.10.1
libcurl/7.87.0
nlohmann_json/3.11.2

[generators]
CMakeDeps
CMakeToolchain

[layout]
cmake_layout
cmake_layout

[options]
libcurl/*:shared=False
libcurl/*:with_ssl=False
24 changes: 24 additions & 0 deletions install_windows.bat
Original file line number Diff line number Diff line change
@@ -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