🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
6.8 KiB

2 years ago
  1. # Copyright (c) 2014 Jarryd Beck
  2. #
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights
  6. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. # copies of the Software, and to permit persons to whom the Software is
  8. # furnished to do so, subject to the following conditions:
  9. #
  10. # The above copyright notice and this permission notice shall be included in
  11. # all copies or substantial portions of the Software.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. # THE SOFTWARE.
  20. if (CMAKE_VERSION VERSION_GREATER 3.10 OR CMAKE_VERSION VERSION_EQUAL 3.10)
  21. # Use include_guard() added in cmake 3.10
  22. include_guard()
  23. endif()
  24. include(CMakePackageConfigHelpers)
  25. function(cxxopts_getversion version_arg)
  26. # Parse the current version from the cxxopts header
  27. file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/cxxopts.hpp" cxxopts_version_defines
  28. REGEX "#define CXXOPTS__VERSION_(MAJOR|MINOR|PATCH)")
  29. foreach(ver ${cxxopts_version_defines})
  30. if(ver MATCHES "#define CXXOPTS__VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
  31. set(CXXOPTS__VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
  32. endif()
  33. endforeach()
  34. set(VERSION ${CXXOPTS__VERSION_MAJOR}.${CXXOPTS__VERSION_MINOR}.${CXXOPTS__VERSION_PATCH})
  35. # Give feedback to the user. Prefer DEBUG when available since large projects tend to have a lot
  36. # going on already
  37. if (CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15)
  38. message(DEBUG "cxxopts version ${VERSION}")
  39. else()
  40. message(STATUS "cxxopts version ${VERSION}")
  41. endif()
  42. # Return the information to the caller
  43. set(${version_arg} ${VERSION} PARENT_SCOPE)
  44. endfunction()
  45. # Optionally, enable unicode support using the ICU library
  46. function(cxxopts_use_unicode)
  47. find_package(PkgConfig)
  48. pkg_check_modules(ICU REQUIRED icu-uc)
  49. target_link_libraries(cxxopts INTERFACE ${ICU_LDFLAGS})
  50. target_compile_options(cxxopts INTERFACE ${ICU_CFLAGS})
  51. target_compile_definitions(cxxopts INTERFACE CXXOPTS_USE_UNICODE)
  52. endfunction()
  53. # Request C++11 without gnu extension for the whole project and enable more warnings
  54. macro(cxxopts_set_cxx_standard)
  55. if (CXXOPTS_CXX_STANDARD)
  56. set(CMAKE_CXX_STANDARD ${CXXOPTS_CXX_STANDARD})
  57. else()
  58. set(CMAKE_CXX_STANDARD 11)
  59. endif()
  60. set(CMAKE_CXX_EXTENSIONS OFF)
  61. endmacro()
  62. # Helper function to enable warnings
  63. function(cxxopts_enable_warnings)
  64. if(MSVC)
  65. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2")
  66. elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
  67. if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
  68. if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL 5.0)
  69. set(COMPILER_SPECIFIC_FLAGS "-Wsuggest-override")
  70. endif()
  71. endif()
  72. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion ${COMPILER_SPECIFIC_FLAGS}")
  73. endif()
  74. set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE)
  75. endfunction()
  76. # Helper function to ecapsulate install logic
  77. function(cxxopts_install_logic)
  78. string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}")
  79. set(CXXOPTS_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/cxxopts" CACHE STRING "Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")
  80. set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")
  81. set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")
  82. set(targets_export_name cxxopts-targets)
  83. set(PackagingTemplatesDir "${PROJECT_SOURCE_DIR}/packaging")
  84. if(${CMAKE_VERSION} VERSION_GREATER "3.14")
  85. set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT")
  86. endif()
  87. # Generate the version, config and target files into the build directory.
  88. write_basic_package_version_file(
  89. ${version_config}
  90. VERSION ${VERSION}
  91. COMPATIBILITY AnyNewerVersion
  92. ${OPTIONAL_ARCH_INDEPENDENT}
  93. )
  94. configure_package_config_file(
  95. ${PackagingTemplatesDir}/cxxopts-config.cmake.in
  96. ${project_config}
  97. INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR})
  98. export(TARGETS cxxopts NAMESPACE cxxopts::
  99. FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
  100. # Install version, config and target files.
  101. install(
  102. FILES ${project_config} ${version_config}
  103. DESTINATION ${CXXOPTS_CMAKE_DIR})
  104. install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}
  105. NAMESPACE cxxopts::)
  106. # Install the header file and export the target
  107. install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
  108. install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  109. set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
  110. set(CPACK_PACKAGE_VENDOR "cxxopt developers")
  111. set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
  112. set(CPACK_DEBIAN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
  113. set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
  114. set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
  115. set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
  116. set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}")
  117. set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
  118. set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
  119. set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}-dev")
  120. set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6-dev")
  121. set(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, pkg-config, pkg-conf")
  122. set(CPACK_RPM_PACKAGE_NAME "lib${PROJECT_NAME}-devel")
  123. set(CPACK_RPM_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}")
  124. set(CPACK_DEB_COMPONENT_INSTALL ON)
  125. set(CPACK_RPM_COMPONENT_INSTALL ON)
  126. set(CPACK_NSIS_COMPONENT_INSTALL ON)
  127. set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
  128. set(PKG_CONFIG_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc")
  129. configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
  130. install(FILES "${PKG_CONFIG_FILE_NAME}"
  131. DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/pkgconfig"
  132. )
  133. include(CPack)
  134. endfunction()