🛠️🐜 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.

108 lines
4.4 KiB

  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. cmake_minimum_required(VERSION 3.1)
  21. # parse the current version from the cxxopts header
  22. file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/cxxopts.hpp" cxxopts_version_defines
  23. REGEX "#define CXXOPTS__VERSION_(MAJOR|MINOR|PATCH)")
  24. foreach(ver ${cxxopts_version_defines})
  25. if(ver MATCHES "#define CXXOPTS__VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
  26. set(CXXOPTS__VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
  27. endif()
  28. endforeach()
  29. set(VERSION ${CXXOPTS__VERSION_MAJOR}.${CXXOPTS__VERSION_MINOR}.${CXXOPTS__VERSION_PATCH})
  30. message(STATUS "cxxopts version ${VERSION}")
  31. project(cxxopts VERSION "${VERSION}" LANGUAGES CXX)
  32. enable_testing()
  33. option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)
  34. option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ON)
  35. option(CXXOPTS_ENABLE_INSTALL "Generate the install target" ON)
  36. # request c++11 without gnu extension for the whole project and enable more warnings
  37. if (CXXOPTS_CXX_STANDARD)
  38. set(CMAKE_CXX_STANDARD ${CXXOPTS_CXX_STANDARD})
  39. else()
  40. set(CMAKE_CXX_STANDARD 11)
  41. endif()
  42. set(CMAKE_CXX_EXTENSIONS OFF)
  43. if(MSVC)
  44. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2")
  45. elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
  46. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow")
  47. endif()
  48. add_library(cxxopts INTERFACE)
  49. add_library(cxxopts::cxxopts ALIAS cxxopts)
  50. # optionally, enable unicode support using the ICU library
  51. set(CXXOPTS_USE_UNICODE_HELP FALSE CACHE BOOL "Use ICU Unicode library")
  52. if(CXXOPTS_USE_UNICODE_HELP)
  53. find_package(PkgConfig)
  54. pkg_check_modules(ICU REQUIRED icu-uc)
  55. target_link_libraries(cxxopts INTERFACE ${ICU_LDFLAGS})
  56. target_compile_options(cxxopts INTERFACE ${ICU_CFLAGS})
  57. target_compile_definitions(cxxopts INTERFACE CXXOPTS_USE_UNICODE)
  58. endif()
  59. target_include_directories(cxxopts INTERFACE
  60. $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
  61. $<INSTALL_INTERFACE:include>
  62. )
  63. if(CXXOPTS_ENABLE_INSTALL)
  64. include(CMakePackageConfigHelpers)
  65. set(CXXOPTS_CMAKE_DIR "lib/cmake/cxxopts" CACHE STRING
  66. "Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")
  67. set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")
  68. set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")
  69. set(targets_export_name cxxopts-targets)
  70. # Generate the version, config and target files into the build directory.
  71. write_basic_package_version_file(
  72. ${version_config}
  73. VERSION ${VERSION}
  74. COMPATIBILITY AnyNewerVersion)
  75. configure_package_config_file(
  76. ${PROJECT_SOURCE_DIR}/cxxopts-config.cmake.in
  77. ${project_config}
  78. INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR})
  79. export(TARGETS cxxopts NAMESPACE cxxopts::
  80. FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
  81. # Install version, config and target files.
  82. install(
  83. FILES ${project_config} ${version_config}
  84. DESTINATION ${CXXOPTS_CMAKE_DIR})
  85. install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}
  86. NAMESPACE cxxopts::)
  87. # Install the header file and export the target
  88. install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION lib)
  89. install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION include)
  90. endif()
  91. add_subdirectory(src)
  92. add_subdirectory(test)