@@ -102,6 +102,10 @@ list(APPEND MINIO_CPP_LIBS ${MINIO_CPP_DEPS_LINK_LIBS})
102102if (WIN32 )
103103 list (APPEND MINIO_CPP_LIBS wsock32)
104104 list (APPEND MINIO_CPP_LIBS ws2_32)
105+ # miniocpp.pc.in has no visibility into target_link_libraries() - without this,
106+ # pkg-config consumers (non-CMake) are missing wsock32/ws2_32 at link time
107+ # (getaddrinfo, select, ...).
108+ set (MINIO_CPP_PC_EXTRA_LIBS " -lwsock32 -lws2_32" )
105109endif ()
106110if (APPLE )
107111 # httplib loads macOS system certificates from the Keychain
@@ -179,6 +183,78 @@ target_include_directories(miniocpp PUBLIC
179183 $<BUILD_INTERFACE :${MINIO_CPP_INCLUDES} >
180184)
181185target_link_libraries (miniocpp PUBLIC ${MINIO_CPP_LIBS} )
186+
187+ # Optional C++20 module interface for the public API (modules/miniocpp.cc).
188+ # FILE_SET CXX_MODULES (CMake 3.28+) attaches it as a real part of the miniocpp
189+ # target's build - the compiler gets whatever flags it needs for a module
190+ # interface unit (e.g. /interface for MSVC) based on this declaration, not on
191+ # the file's extension, so any CMake/MSBuild/Meson (via cmake.subproject())
192+ # consumer of this target picks up `import miniocpp;` automatically. Requires
193+ # C++20 (MINIO_CPP_STD=20); silently skipped otherwise for older setups.
194+ #
195+ # CMake's module dependency scanning is only implemented for the Ninja,
196+ # Ninja Multi-Config, and Visual Studio (17.4+) generators - with any other
197+ # generator (e.g. the Linux/macOS default "Unix Makefiles") CMake hard-errors
198+ # at the Generate step as soon as it sees FILE_SET CXX_MODULES sources, even
199+ # if MINIO_CPP_STD=20 was requested intentionally. Generator *name* alone is
200+ # not enough either: CMake 3.28 requires Ninja 1.11+ for the dyndep-based
201+ # scanning, and each compiler has its own minimum version for module support
202+ # (MSVC 14.34 / VS 17.4, reported as compiler version 19.34; Clang 16;
203+ # GCC 14) - see https://cmake.org/cmake/help/v3.28/manual/cmake-cxxmodules.7.html.
204+ # An older or unrecognized compiler can still match the generator check
205+ # above and then break module dependency scanning instead of falling back
206+ # cleanly, so reject anything not explicitly known-good rather than
207+ # defaulting to allowed.
208+ set (MINIO_CPP_HAS_CXX_MODULE OFF )
209+ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28" AND MINIO_CPP_STD STREQUAL "20" )
210+ set (MINIO_CPP_MODULE_TOOLCHAIN_OK OFF )
211+ if (CMAKE_GENERATOR STREQUAL "Ninja" OR CMAKE_GENERATOR STREQUAL "Ninja Multi-Config" )
212+ execute_process (
213+ COMMAND "${CMAKE_MAKE_PROGRAM } " --version
214+ OUTPUT_VARIABLE MINIO_CPP_NINJA_VERSION
215+ OUTPUT_STRIP_TRAILING_WHITESPACE
216+ ERROR_QUIET
217+ )
218+ if (MINIO_CPP_NINJA_VERSION VERSION_GREATER_EQUAL "1.11" )
219+ set (MINIO_CPP_MODULE_TOOLCHAIN_OK ON )
220+ endif ()
221+ elseif (CMAKE_GENERATOR MATCHES "^Visual Studio " )
222+ set (MINIO_CPP_MODULE_TOOLCHAIN_OK ON )
223+ endif ()
224+
225+ # Applies regardless of which of the generators above is in use - Ninja can
226+ # also drive an MSVC/Clang/GCC toolchain, and each compiler's own module
227+ # support is gated on its own version, not the generator. Reject any
228+ # compiler not explicitly listed here, rather than silently allowing it.
229+ if (MINIO_CPP_MODULE_TOOLCHAIN_OK)
230+ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
231+ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.34" )
232+ set (MINIO_CPP_MODULE_TOOLCHAIN_OK OFF )
233+ endif ()
234+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
235+ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "16.0" )
236+ set (MINIO_CPP_MODULE_TOOLCHAIN_OK OFF )
237+ endif ()
238+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
239+ if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14" )
240+ set (MINIO_CPP_MODULE_TOOLCHAIN_OK OFF )
241+ endif ()
242+ else ()
243+ set (MINIO_CPP_MODULE_TOOLCHAIN_OK OFF )
244+ endif ()
245+ endif ()
246+
247+ if (MINIO_CPP_MODULE_TOOLCHAIN_OK)
248+ set (MINIO_CPP_HAS_CXX_MODULE ON )
249+ target_sources (miniocpp
250+ PUBLIC
251+ FILE_SET CXX_MODULES
252+ BASE_DIRS modules
253+ FILES modules/miniocpp.cc
254+ )
255+ endif ()
256+ endif ()
257+
182258# httplib's class layout depends on CPPHTTPLIB_OPENSSL_SUPPORT; define it once
183259# target-wide so every translation unit compiles httplib.h identically.
184260target_compile_definitions (miniocpp PRIVATE CPPHTTPLIB_OPENSSL_SUPPORT )
@@ -317,12 +393,22 @@ if (MINIO_CPP_ENABLE_RDMA)
317393 INSTALL_RPATH "$ORIGIN" )
318394endif ()
319395
320- install (TARGETS miniocpp
321- EXPORT miniocpp-targets
322- RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR} "
323- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR} "
324- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR} "
325- INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} " )
396+ if (MINIO_CPP_HAS_CXX_MODULE)
397+ install (TARGETS miniocpp
398+ EXPORT miniocpp-targets
399+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR} "
400+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR} "
401+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR} "
402+ INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} "
403+ FILE_SET CXX_MODULES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} /miniocpp/modules" )
404+ else ()
405+ install (TARGETS miniocpp
406+ EXPORT miniocpp-targets
407+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR} "
408+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR} "
409+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR} "
410+ INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} " )
411+ endif ()
326412
327413# Source-built deps must be in an export set for install(EXPORT) to resolve
328414# them (miniocpp_inih does not export itself).
@@ -334,6 +420,17 @@ if (MINIO_CPP_DEPS_EXPORT_TARGETS)
334420 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR} " )
335421endif ()
336422
423+ # Known limitation: this export does not pass CXX_MODULES_DIRECTORY, so an
424+ # installed package (via find_package(miniocpp) + CMake, as opposed to
425+ # consuming subprojects/miniocpp source directly, or via pkg-config/vcpkg)
426+ # is missing the generated module metadata CMake needs to let a downstream
427+ # CMake consumer `import miniocpp;` - see
428+ # https://cmake.org/cmake/help/latest/command/install.html#exporting-c-modules.
429+ # Separately, installing module interfaces is not supported at all with
430+ # the Visual Studio generator (independent of the MINIO_CPP_HAS_CXX_MODULE
431+ # toolchain gate above, which only covers the build step). Neither gap is
432+ # covered by an automated test yet.
433+
337434# The link interface is not exported; miniocpp-config.cmake re-applies it.
338435install (EXPORT miniocpp-targets
339436 NAMESPACE miniocpp::
0 commit comments