2014-10-02 15:12:28 +04:00
|
|
|
# Copyright (c) 2014 Jarryd Beck
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
# THE SOFTWARE.
|
2016-12-02 23:44:46 +03:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
2014-09-10 10:47:22 +04:00
|
|
|
|
2018-10-29 10:51:26 +03:00
|
|
|
# parse the current version from the cxxopts header
|
|
|
|
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/cxxopts.hpp" cxxopts_version_defines
|
|
|
|
REGEX "#define CXXOPTS__VERSION_(MAJOR|MINOR|PATCH)")
|
2018-07-05 10:53:53 +03:00
|
|
|
foreach(ver ${cxxopts_version_defines})
|
2018-10-29 10:51:26 +03:00
|
|
|
if(ver MATCHES "#define CXXOPTS__VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
|
|
|
|
set(CXXOPTS__VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
|
2018-07-05 10:53:53 +03:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(VERSION ${CXXOPTS__VERSION_MAJOR}.${CXXOPTS__VERSION_MINOR}.${CXXOPTS__VERSION_PATCH})
|
2018-10-29 10:51:26 +03:00
|
|
|
message(STATUS "cxxopts version ${VERSION}")
|
2018-07-05 10:53:53 +03:00
|
|
|
|
2019-07-31 11:15:58 +03:00
|
|
|
project(cxxopts VERSION "${VERSION}" LANGUAGES CXX)
|
2018-10-29 10:51:26 +03:00
|
|
|
|
|
|
|
enable_testing()
|
2014-09-10 10:47:22 +04:00
|
|
|
|
2016-02-05 23:23:17 +03:00
|
|
|
option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)
|
2018-11-07 10:52:40 +03:00
|
|
|
option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ON)
|
2019-08-01 10:51:01 +03:00
|
|
|
option(CXXOPTS_ENABLE_INSTALL "Generate the install target" ON)
|
2016-02-05 23:23:17 +03:00
|
|
|
|
2017-06-23 11:38:42 +03:00
|
|
|
# request c++11 without gnu extension for the whole project and enable more warnings
|
2018-01-31 10:25:52 +03:00
|
|
|
if (CXXOPTS_CXX_STANDARD)
|
|
|
|
set(CMAKE_CXX_STANDARD ${CXXOPTS_CXX_STANDARD})
|
|
|
|
else()
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
endif()
|
|
|
|
|
2017-06-23 11:38:42 +03:00
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
2018-01-31 10:25:52 +03:00
|
|
|
|
2017-06-23 11:38:42 +03:00
|
|
|
if(MSVC)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2")
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
2020-10-21 02:24:41 +03:00
|
|
|
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 -Wsuggest-override")
|
2017-06-23 11:38:42 +03:00
|
|
|
endif()
|
|
|
|
|
|
|
|
add_library(cxxopts INTERFACE)
|
2019-08-01 10:50:05 +03:00
|
|
|
add_library(cxxopts::cxxopts ALIAS cxxopts)
|
2017-06-23 11:38:42 +03:00
|
|
|
|
|
|
|
# optionally, enable unicode support using the ICU library
|
2014-10-27 14:06:24 +03:00
|
|
|
set(CXXOPTS_USE_UNICODE_HELP FALSE CACHE BOOL "Use ICU Unicode library")
|
|
|
|
if(CXXOPTS_USE_UNICODE_HELP)
|
2017-06-23 11:38:42 +03:00
|
|
|
find_package(PkgConfig)
|
|
|
|
pkg_check_modules(ICU REQUIRED icu-uc)
|
2014-10-27 14:06:24 +03:00
|
|
|
|
2017-06-23 11:38:42 +03:00
|
|
|
target_link_libraries(cxxopts INTERFACE ${ICU_LDFLAGS})
|
|
|
|
target_compile_options(cxxopts INTERFACE ${ICU_CFLAGS})
|
|
|
|
target_compile_definitions(cxxopts INTERFACE CXXOPTS_USE_UNICODE)
|
|
|
|
endif()
|
2014-10-27 14:06:24 +03:00
|
|
|
|
2017-06-23 11:38:42 +03:00
|
|
|
target_include_directories(cxxopts INTERFACE
|
|
|
|
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
|
|
|
$<INSTALL_INTERFACE:include>
|
|
|
|
)
|
2014-10-27 14:06:24 +03:00
|
|
|
|
2019-08-01 10:51:01 +03:00
|
|
|
if(CXXOPTS_ENABLE_INSTALL)
|
2020-08-19 02:16:11 +03:00
|
|
|
include(GNUInstallDirs)
|
2019-08-01 10:51:01 +03:00
|
|
|
include(CMakePackageConfigHelpers)
|
2020-08-19 02:16:11 +03:00
|
|
|
set(CXXOPTS_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/cxxopts" CACHE STRING
|
2019-08-01 10:51:01 +03:00
|
|
|
"Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")
|
|
|
|
set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")
|
|
|
|
set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")
|
|
|
|
set(targets_export_name cxxopts-targets)
|
|
|
|
|
|
|
|
# Generate the version, config and target files into the build directory.
|
|
|
|
write_basic_package_version_file(
|
|
|
|
${version_config}
|
|
|
|
VERSION ${VERSION}
|
|
|
|
COMPATIBILITY AnyNewerVersion)
|
|
|
|
configure_package_config_file(
|
|
|
|
${PROJECT_SOURCE_DIR}/cxxopts-config.cmake.in
|
|
|
|
${project_config}
|
|
|
|
INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR})
|
|
|
|
export(TARGETS cxxopts NAMESPACE cxxopts::
|
|
|
|
FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
|
|
|
|
|
|
|
|
# Install version, config and target files.
|
|
|
|
install(
|
|
|
|
FILES ${project_config} ${version_config}
|
|
|
|
DESTINATION ${CXXOPTS_CMAKE_DIR})
|
|
|
|
install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}
|
|
|
|
NAMESPACE cxxopts::)
|
|
|
|
|
|
|
|
# Install the header file and export the target
|
2020-08-19 02:16:11 +03:00
|
|
|
install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
|
|
|
install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
2019-08-01 10:51:01 +03:00
|
|
|
endif()
|
2016-12-02 23:44:46 +03:00
|
|
|
|
2015-03-18 19:31:29 +03:00
|
|
|
add_subdirectory(src)
|
2016-08-25 01:49:56 +03:00
|
|
|
add_subdirectory(test)
|