Skip to content

Commit

Permalink
Reworked CMakeLists.txt
Browse files Browse the repository at this point in the history
  * Moved the logic into a single CMakeLists.txt file
  * Added miniocpp:: namespace and thus miniocpp::miniocpp target
  * Removed the generation of header files (config.h.in)
  * Consolidated tests and examples - use MINIO_CPP_TEST to build
    them all
  * Use miniocpp::miniocpp target in tests and exampels to simplify
    the use of dependencies
  * Setup the cmake project with DESCRIPTION and VERSION
  * Use GNUInstallDirs when installing targets
  * Export cmake files so another cmake can find minio-cpp by
    using find_package(miniocpp) and then use miniocpp::miniocpp
  * Building both documentation and tests/examples is OFF by default
  • Loading branch information
kobalicek committed Mar 19, 2024
1 parent e711a21 commit 6810d03
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 370 deletions.
Empty file removed .gitmodules
Empty file.
307 changes: 205 additions & 102 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# MinIO C++ Library for Amazon S3 Compatible Cloud Storage
# Copyright 2021 MinIO, Inc.
# Copyright 2021-2024 MinIO, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,124 +15,227 @@
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0091 NEW)

project(miniocpp)
# Minio C++ Project
# -----------------

set(MINIO_CPP_MAJOR_VERSION "0")
set(MINIO_CPP_MINOR_VERSION "1")
set(MINIO_CPP_PATCH_VERSION "0")
set(MINIO_CPP_VERSION_STRING "${MINIO_CPP_MAJOR_VERSION}.${MINIO_CPP_MINOR_VERSION}.${MINIO_CPP_PATCH_VERSION}")

project(miniocpp
DESCRIPTION "MinIO C++ Client SDK provides simple APIs to access S3 compatible object storage"
VERSION ${MINIO_CPP_VERSION_STRING}
LANGUAGES C CXX
)

include(GNUInstallDirs)
include(CheckIncludeFiles)

option(MINIO_CPP_TEST "Build tests" OFF)
option(MINIO_CPP_MAKE_DOC "Build documentation" OFF)

# TODO: Leftovers from previous CMake build script:
#set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(MINIO_CPP_CFLAGS)
set(MINIO_CPP_LIBS)
set(MINIO_CPP_STD "17")

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC")
# MSVC
else()
# GCC/Clang/AppleClang/...
LIST(APPEND MINIO_CPP_CFLAGS -Wall -Wextra -Wconversion)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0 AND NOT MINGW)
list(APPEND MINIO_CPP_LIBS stdc++fs)
endif()
endif()

macro(set_globals)
set(CMAKE_BUILD_TYPE_INIT Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} --coverage")
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --coverage")
set(CMAKE_MODULE_LINKER_FLAGS_COVERAGE "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} --coverage")
endmacro()

# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# prohibit in-source-builds
IF (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
MESSAGE(STATUS "In-source-builds are not allowed")
MESSAGE(STATUS "Clean your source directory (e.g. delete the CMakeCache.txt file)")
MESSAGE(FATAL_ERROR "Please create a separate build directory and call CMake again")
ENDIF (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})

# Look for required libraries
SET(requiredlibs)

IF(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Wconversion")
IF(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0 AND NOT MINGW)
list(APPEND requiredlibs stdc++fs)
ENDIF()
ENDIF()
# Dependencies
# ------------

find_package(CURL REQUIRED)
IF(CURL_FOUND)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
list(APPEND requiredlibs CURL::libcurl)
ELSE(CURL_FOUND)
MESSAGE(FATAL_ERROR "Could not find the CURL library and development files.")
ENDIF(CURL_FOUND)

find_package(OpenSSL REQUIRED)
find_package(unofficial-curlpp CONFIG REQUIRED)
list(APPEND requiredlibs unofficial::curlpp::curlpp)

find_package(unofficial-inih CONFIG REQUIRED)
list(APPEND requiredlibs unofficial::inih::inireader)

find_package(nlohmann_json CONFIG REQUIRED)
list(APPEND requiredlibs nlohmann_json::nlohmann_json)

find_package(pugixml CONFIG REQUIRED)
list(APPEND requiredlibs pugixml)

find_package(OpenSSL REQUIRED)
IF(OPENSSL_FOUND)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
list(APPEND requiredlibs OpenSSL::SSL OpenSSL::Crypto) # bugfix, because libcrypto is not found automatically
ELSE(OPENSSL_FOUND)
MESSAGE(FATAL_ERROR "Could not find the OpenSSL library and development files.")
ENDIF(OPENSSL_FOUND)

if(WIN32)
list(APPEND requiredlibs wsock32)
list(APPEND requiredlibs ws2_32)
list(APPEND requiredlibs ZLIB::ZLIB)
list(APPEND MINIO_CPP_LIBS
CURL::libcurl
unofficial::curlpp::curlpp
unofficial::inih::inireader
nlohmann_json::nlohmann_json
pugixml
OpenSSL::SSL OpenSSL::Crypto
)

if (WIN32)
list(APPEND MINIO_CPP_LIBS wsock32)
list(APPEND MINIO_CPP_LIBS ws2_32)
list(APPEND MINIO_CPP_LIBS ZLIB::ZLIB)
endif()

message(STATUS "Found required libs: ${requiredlibs}")

INCLUDE (CheckIncludeFiles)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)

SET(MINIOCPP_MAJOR_VERSION "0")
SET(MINIOCPP_MINOR_VERSION "1")
SET(MINIOCPP_PATCH_VERSION "0")

add_subdirectory(include)
add_subdirectory(src)

option(BUILD_EXAMPLES "Build examples" ON)
if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif (BUILD_EXAMPLES)

option(BUILD_TESTS "Build tests" ON)
if (BUILD_TESTS)
add_subdirectory(tests)
endif (BUILD_TESTS)
# Minio C++ Library
# -----------------

set(MINIO_CPP_SOURCES
src/args.cc
src/baseclient.cc
src/client.cc
src/credentials.cc
src/http.cc
src/providers.cc
src/request.cc
src/response.cc
src/select.cc
src/signer.cc
src/sse.cc
src/types.cc
src/utils.cc
)

set(MINIO_CPP_HEADERS
include/args.h
include/baseclient.h
include/client.h
include/config.h
include/credentials.h
include/error.h
include/http.h
include/providers.h
include/request.h
include/response.h
include/select.h
include/signer.h
include/sse.h
include/types.h
include/utils.h
)

add_library(miniocpp STATIC ${MINIO_CPP_SOURCES} ${MINIO_CPP_HEADERS})
target_compile_options(miniocpp PRIVATE ${MINIO_CPP_CFLAGS})
target_compile_features(miniocpp PUBLIC cxx_std_${MINIO_CPP_STD})
target_include_directories(miniocpp PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(miniocpp PUBLIC ${MINIO_CPP_LIBS})
set_target_properties(miniocpp PROPERTIES VERSION "${MINIO_CPP_VERSION_STRING}")

# Add a cmake alias - this is how users should use minio-cpp in their cmake projects.
add_library(miniocpp::miniocpp ALIAS miniocpp)

# Minio C++ Tests
# ---------------

if (MINIO_CPP_TEST)
set(EXAMPLE_APPS
MakeBucket
RemoveBucket
BucketExists
ListBuckets
StatObject
RemoveObject
DownloadObject
UploadObject
GetObject
ListObjects
PutObject
CopyObject
ComposeObject
RemoveObjects
SelectObjectContent
ListenBucketNotification
DeleteBucketPolicy
GetBucketPolicy
SetBucketPolicy
DeleteBucketNotification
GetBucketNotification
SetBucketNotification
DeleteBucketEncryption
GetBucketEncryption
SetBucketEncryption
GetBucketVersioning
SetBucketVersioning
DeleteBucketReplication
GetBucketReplication
SetBucketReplication
DeleteBucketLifecycle
GetBucketLifecycle
SetBucketLifecycle
DeleteBucketTags
GetBucketTags
SetBucketTags
DeleteObjectLockConfig
GetObjectLockConfig
SetObjectLockConfig
DeleteObjectTags
GetObjectTags
SetObjectTags
DisableObjectLegalHold
EnableObjectLegalHold
IsObjectLegalHoldEnabled
GetObjectRetention
SetObjectRetention
GetPresignedObjectUrl
GetPresignedPostFormData
PutObjectProgress
GetObjectProgress
)

foreach(target ${EXAMPLE_APPS})
add_executable(${target} examples/${target}.cc)
target_compile_features(${target} PUBLIC cxx_std_${MINIO_CPP_STD})
target_include_directories(${target} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(${target} PRIVATE miniocpp::miniocpp ${MINIO_CPP_LIBS})
endforeach()

add_executable(tests tests/tests.cc)
target_compile_features(tests PUBLIC cxx_std_${MINIO_CPP_STD})
target_include_directories(tests PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(tests miniocpp ${MINIO_CPP_LIBS})
endif()

option(BUILD_DOC "Build documentation" ON)
# Minio C++ Documentation
# -----------------------

if (BUILD_DOC)
if (MINIO_CPP_MAKE_DOC)
# check if Doxygen is installed
find_package(Doxygen)
if (DOXYGEN_FOUND)
# set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build started")

# note the option ALL which allows to build the docs together with the application
add_custom_target(doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
else (DOXYGEN_FOUND)
# set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)

# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)

# note the option ALL which allows to build the docs together with the application
add_custom_target(doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
else()
message("Doxygen need to be installed to generate the doxygen documentation")
endif (DOXYGEN_FOUND)
endif(BUILD_DOC)
endif()
endif()

# Installation Instructions
# -------------------------

install(TARGETS miniocpp
EXPORT miniocpp-config
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

install(EXPORT miniocpp-config
NAMESPACE miniocpp::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/miniocpp")

configure_file(miniocpp.pc.in miniocpp.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/miniocpp.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES
${MINIO_CPP_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/miniocpp")

configure_file(miniocpp.pc.in ${CMAKE_CURRENT_BINARY_DIR}/miniocpp.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/miniocpp.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
15 changes: 15 additions & 0 deletions configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

BUILD_OPTIONS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"

if [ -n "$VCPKG_ROOT" ]; then
BUILD_OPTIONS="${BUILD_OPTIONS} -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
fi

echo "== [Configuring Build - Debug] =="
eval cmake . -B build/Debug -DCMAKE_BUILD_TYPE=Debug ${BUILD_OPTIONS} "$@"
echo ""

echo "== [Configuring Build - Release] =="
eval cmake . -B build/Release -DCMAKE_BUILD_TYPE=Release ${BUILD_OPTIONS} "$@"
echo ""
Loading

0 comments on commit 6810d03

Please sign in to comment.