CMakeLists.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # MinIO C++ Library for Amazon S3 Compatible Cloud Storage
  2. # Copyright 2021 MinIO, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. project(miniocpp)
  16. cmake_minimum_required(VERSION 3.10)
  17. macro(set_globals)
  18. set(CMAKE_BUILD_TYPE_INIT Release)
  19. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  20. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  21. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  22. set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} --coverage")
  23. set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage")
  24. set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --coverage")
  25. set(CMAKE_MODULE_LINKER_FLAGS_COVERAGE "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} --coverage")
  26. endmacro()
  27. # specify the C++ standard
  28. set(CMAKE_CXX_STANDARD 17)
  29. set(CMAKE_CXX_STANDARD_REQUIRED True)
  30. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  31. # prohibit in-source-builds
  32. IF (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
  33. MESSAGE(STATUS "In-source-builds are not allowed")
  34. MESSAGE(STATUS "Clean your source directory (e.g. delete the CMakeCache.txt file)")
  35. MESSAGE(FATAL_ERROR "Please create a separate build directory and call CMake again")
  36. ENDIF (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
  37. # Look for required libraries
  38. SET(requiredlibs)
  39. IF(CMAKE_COMPILER_IS_GNUCC)
  40. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
  41. IF(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0 AND NOT MINGW)
  42. list(APPEND requiredlibs stdc++fs)
  43. ENDIF()
  44. ENDIF()
  45. find_package(CURL REQUIRED)
  46. IF(CURL_FOUND)
  47. INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
  48. list(APPEND requiredlibs CURL::libcurl)
  49. ELSE(CURL_FOUND)
  50. MESSAGE(FATAL_ERROR "Could not find the CURL library and development files.")
  51. ENDIF(CURL_FOUND)
  52. if (MSVC)
  53. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/utf-cpp/include)
  54. set(STRPTIME
  55. ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/strptime/strptime.h
  56. ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/strptime/strptime.c
  57. )
  58. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/strptime)
  59. add_library(strptime STATIC ${STRPTIME})
  60. set_property(TARGET strptime PROPERTY
  61. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  62. endif()
  63. set(INIH
  64. ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/inih-r58/ini.c
  65. ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/inih-r58/ini.h
  66. ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/inih-r58/cpp/INIReader.cpp
  67. ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/inih-r58/cpp/INIReader.h
  68. )
  69. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/inih-r58)
  70. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/inih-r58/cpp)
  71. add_library(inih STATIC ${INIH})
  72. if (MSVC)
  73. set_property(TARGET inih PROPERTY
  74. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  75. endif()
  76. include (find_unofficial_curlpp.cmake)
  77. include (find_pugixml.cmake)
  78. include (find_nlohmann_json.cmake)
  79. find_package(ZLIB REQUIRED)
  80. IF(ZLIB_FOUND)
  81. INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
  82. list(APPEND requiredlibs ZLIB::ZLIB)
  83. ENDIF()
  84. find_package(OpenSSL REQUIRED)
  85. IF(OPENSSL_FOUND)
  86. INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
  87. list(APPEND requiredlibs OpenSSL::SSL OpenSSL::Crypto) # bugfix, because libcrypto is not found automatically
  88. ELSE(OPENSSL_FOUND)
  89. MESSAGE(FATAL_ERROR "Could not find the OpenSSL library and development files.")
  90. ENDIF(OPENSSL_FOUND)
  91. message(STATUS "Found required libs: ${requiredlibs}")
  92. INCLUDE (CheckIncludeFiles)
  93. INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
  94. SET(MINIOCPP_MAJOR_VERSION "0")
  95. SET(MINIOCPP_MINOR_VERSION "1")
  96. SET(MINIOCPP_PATCH_VERSION "0")
  97. add_subdirectory(include)
  98. add_subdirectory(src)
  99. if (MSVC)
  100. set_property(TARGET miniocpp PROPERTY
  101. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  102. endif()
  103. option(BUILD_EXAMPLES "Build examples" ON)
  104. if (BUILD_EXAMPLES)
  105. add_subdirectory(examples)
  106. endif (BUILD_EXAMPLES)
  107. option(BUILD_TESTS "Build tests" ON)
  108. if (BUILD_TESTS)
  109. add_subdirectory(tests)
  110. endif (BUILD_TESTS)
  111. option(BUILD_DOC "Build documentation" ON)
  112. if (BUILD_DOC)
  113. # check if Doxygen is installed
  114. find_package(Doxygen)
  115. if (DOXYGEN_FOUND)
  116. # set input and output files
  117. set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
  118. set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
  119. # request to configure the file
  120. configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
  121. message("Doxygen build started")
  122. # note the option ALL which allows to build the docs together with the application
  123. add_custom_target(doc_doxygen ALL
  124. COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
  125. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  126. COMMENT "Generating API documentation with Doxygen"
  127. VERBATIM )
  128. else (DOXYGEN_FOUND)
  129. message("Doxygen need to be installed to generate the doxygen documentation")
  130. endif (DOXYGEN_FOUND)
  131. endif(BUILD_DOC)
  132. configure_file(miniocpp.pc.in miniocpp.pc @ONLY)
  133. install(FILES ${CMAKE_BINARY_DIR}/miniocpp.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  134. if (MSVC)
  135. install(TARGETS strptime DESTINATION lib)
  136. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/strptime/strptime.h DESTINATION include/strptime)
  137. endif()
  138. install(TARGETS inih DESTINATION lib)
  139. install(FILES
  140. ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/inih-r58/ini.h
  141. DESTINATION include/inih-r58)
  142. install(FILES
  143. ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/inih-r58/cpp/INIReader.h
  144. DESTINATION include/inih-r58/cpp)