11cmake_minimum_required (VERSION 3.16 )
22project (RingFTPClient LANGUAGES C )
33
4+ include (FetchContent )
5+
46set (RING_ROOT_DEFAULT "${CMAKE_CURRENT_SOURCE_DIR } /../.." )
57if (DEFINED ENV{RING})
68 set (RING_ROOT_DEFAULT "$ENV{RING} " )
@@ -67,9 +69,26 @@ endif()
6769# Set the destination directory for the built library
6870set (LIB_DEST_DIR "${CMAKE_CURRENT_SOURCE_DIR } /lib/${OS_DIR} /${ARCH_DIR} " )
6971
70- # Find CURL package
72+ # Find libcurl
7173find_package (CURL REQUIRED )
7274
75+ # Don't build examples from ftpclient
76+ set (BUILD_EXAMPLES OFF )
77+
78+ # Add ftpclient.h as a subdirectory to build it
79+ if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR } /src/c_src/ftpclient/CMakeLists.txt" )
80+ message (STATUS "ftpclient.h source not found, fetching from GitHub..." )
81+ FetchContent_Declare (
82+ ftpclient
83+ GIT_REPOSITORY https://github.com/ysdragon/ftpclient.h
84+ GIT_TAG v1.0.0
85+ )
86+ FetchContent_MakeAvailable (ftpclient)
87+ else ()
88+ message (STATUS "ftpclient.h found locally, adding as subdirectory." )
89+ add_subdirectory (src/c_src/ftpclient )
90+ endif ()
91+
7392# Create the Ring FTP Client extension shared library
7493add_library (ring_ftp SHARED
7594 ${CMAKE_CURRENT_SOURCE_DIR } /src/c_src/ring_ftp.c
@@ -78,26 +97,15 @@ add_library(ring_ftp SHARED
7897# Include directories
7998target_include_directories (ring_ftp PRIVATE
8099 ${RING_INCLUDE}
81- ${CMAKE_CURRENT_SOURCE_DIR }
82- ${CURL_INCLUDE_DIRS}
100+ ${CURL_INCLUDE_DIRS}
83101)
84102
85103# Link libraries
86104target_link_libraries (ring_ftp PRIVATE
87105 Ring::Ring
88- CURL::libcurl
106+ ftpclient
89107)
90108
91- # On Windows, link additional dependencies required for static CURL
92- if (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
93- target_link_libraries (ring_ftp PRIVATE
94- ws2_32
95- wldap32
96- crypt32
97- normaliz
98- )
99- endif ()
100-
101109target_compile_options (ring_ftp PRIVATE
102110 $<$<CONFIG :Release ,RelWithDebInfo ,MinSizeRel >:
103111 $<$<C_COMPILER_ID :MSVC >:/O2 >
0 commit comments