mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
CMake updates from @slurps-mad-rips
This commit is contained in:
parent
c356ec8702
commit
60e2932356
@ -2,7 +2,7 @@ steps:
|
||||
|
||||
- task: CMake@1
|
||||
inputs:
|
||||
cmakeArgs: .. -DCLI11_WARNINGS_AS_ERRORS=ON -DCLI11_SINGLE_FILE=$(cli11.single) -DCLI11_CXX_STD=$(cli11.std) -DCLI11_SINGLE_FILE_TESTS=$(cli11.single) -DCMAKE_BUILD_TYPE=$(cli11.build_type) $(cli11.options)
|
||||
cmakeArgs: .. -DCLI11_WARNINGS_AS_ERRORS=ON -DCLI11_SINGLE_FILE=$(cli11.single) -DCMAKE_CXX_STANDARD=$(cli11.std) -DCLI11_SINGLE_FILE_TESTS=$(cli11.single) -DCMAKE_BUILD_TYPE=$(cli11.build_type) $(cli11.options)
|
||||
displayName: 'Configure'
|
||||
|
||||
- script: cmake --build .
|
||||
|
@ -8,7 +8,7 @@ set -evx
|
||||
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake .. -DCLI11_WARNINGS_AS_ERRORS=ON -DCLI11_SINGLE_FILE=ON -DCLI11_CXX_STD=$STD -DCLI11_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER_LAUNCHER=ccache $@
|
||||
cmake .. -DCLI11_WARNINGS_AS_ERRORS=ON -DCLI11_SINGLE_FILE=ON -DCMAKE_CXX_STANDARD=$STD -DCLI11_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER_LAUNCHER=ccache $@
|
||||
cmake --build . -- -j2
|
||||
|
||||
set +evx
|
||||
|
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -1,9 +1,3 @@
|
||||
[submodule "extern/googletest"]
|
||||
path = extern/googletest
|
||||
url = ../../google/googletest.git
|
||||
[submodule "extern/sanitizers"]
|
||||
path = extern/sanitizers
|
||||
url = ../../arsenm/sanitizers-cmake
|
||||
[submodule "extern/json"]
|
||||
path = extern/json
|
||||
url = ../../nlohmann/json.git
|
||||
|
298
CMakeLists.txt
298
CMakeLists.txt
@ -24,29 +24,140 @@ string(REGEX REPLACE ${VERSION_REGEX} "\\1" VERSION_STRING "${VERSION_STRING}")
|
||||
# Add the project
|
||||
project(CLI11 LANGUAGES CXX VERSION ${VERSION_STRING})
|
||||
|
||||
# Print the version number of CMake if this is the main project
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
message(STATUS "CMake ${CMAKE_VERSION}")
|
||||
endif()
|
||||
|
||||
include(CMakeDependentOption)
|
||||
include(GNUInstallDirs)
|
||||
include(CTest)
|
||||
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.11)
|
||||
include(FetchContent)
|
||||
endif()
|
||||
|
||||
find_package(Doxygen)
|
||||
|
||||
list(APPEND force-libcxx "CMAKE_CXX_COMPILER_ID STREQUAL \"Clang\"")
|
||||
list(APPEND force-libcxx "CMAKE_SYSTEM_NAME STREQUAL \"Linux\"")
|
||||
list(APPEND force-libcxx "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME")
|
||||
|
||||
list(APPEND build-docs "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME")
|
||||
list(APPEND build-docs "NOT CMAKE_VERSION VERSION_LESS 3.11")
|
||||
list(APPEND build-docs "Doxygen_FOUND")
|
||||
list(APPEND build-docs "EXISTS docs")
|
||||
|
||||
option(CLI11_WARNINGS_AS_ERRORS "Turn all warnings into errors (for CI)")
|
||||
option(CLI11_SINGLE_FILE "Generate a single header file")
|
||||
cmake_dependent_option(CLI11_SANITIZERS
|
||||
"Download the sanatizers CMake config" OFF
|
||||
"NOT CMAKE_VERSION VERSION_LESS 3.11" OFF)
|
||||
|
||||
cmake_dependent_option(CLI11_BUILD_DOCS
|
||||
"Build CLI11 documentation" ON
|
||||
"${build-docs}" OFF)
|
||||
|
||||
cmake_dependent_option(CLI11_BUILD_TESTS
|
||||
"Build CLI11 tests" ON
|
||||
"BUILD_TESTING;CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF)
|
||||
|
||||
cmake_dependent_option(CLI11_BUILD_EXAMPLES
|
||||
"Build CLI11 examples" ON
|
||||
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;EXISTS examples" OFF)
|
||||
|
||||
cmake_dependent_option(CLI11_BUILD_EXAMPLES_JSON
|
||||
"Build CLI11 json example" OFF
|
||||
"CLI11_BUILD_EXAMPLES;NOT CMAKE_VERSION VERSION_LESS 3.11" OFF)
|
||||
|
||||
cmake_dependent_option(CLI11_SINGLE_FILE_TESTS
|
||||
"Duplicate all the tests for a single file build" OFF
|
||||
"BUILD_TESTING;CLI11_SINGLE_FILE" OFF)
|
||||
|
||||
cmake_dependent_option(CLI11_INSTALL
|
||||
"Install the CLI11 folder to include during install process" ON
|
||||
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF)
|
||||
|
||||
cmake_dependent_option(CLI11_FORCE_LIBCXX
|
||||
"Force clang to use libc++ instead of libstdc++ (Linux only)" OFF
|
||||
"${force-libcxx}" OFF)
|
||||
|
||||
cmake_dependent_option(CLI11_CUDA_TESTS
|
||||
"Build the tests with NVCC to check for warnings there - requires CMake 3.9+" OFF
|
||||
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME" OFF)
|
||||
|
||||
cmake_dependent_option(CLI11_CLANG_TIDY
|
||||
"Look for and use Clang-Tidy" OFF
|
||||
"CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME;NOT CMAKE_VERSION VERSION_LESS 3.6" OFF)
|
||||
set(CLI11_CLANG_TIDY_OPTIONS "" CACHE STRING "Clang tidy options, such as -fix, simicolon separated")
|
||||
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT DEFINED CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CMAKE_CXX_EXTENSIONS)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
endif()
|
||||
|
||||
|
||||
# Allow IDE's to group targets into folders
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
endif()
|
||||
|
||||
if(CMAKE_VERSION VERSION_LESS 3.10)
|
||||
message(STATUS "CMake 3.10+ adds Doxygen support. Update CMake to build documentation")
|
||||
elseif(NOT Doxygen_FOUND)
|
||||
message(STATUS "Doxygen not found, building docs has been disabled")
|
||||
endif()
|
||||
|
||||
# Special target that adds warnings. Is not exported.
|
||||
add_library(CLI11_warnings INTERFACE)
|
||||
|
||||
# Only if built as the main project
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
# User settable
|
||||
set(CLI11_CXX_STD "11" CACHE STRING "The CMake standard to require")
|
||||
set(unix-warnings -Wall -Wextra -pedantic -Wshadow -Wsign-conversion -Wswitch-enum)
|
||||
|
||||
# Special override for Clang on Linux (useful with an old stdlibc++ and a newer clang)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
option(CLI11_FORCE_LIBCXX "Force Clang to use libc++ instead of libstdc++ (Linux only)" OFF)
|
||||
if(CLI11_FORCE_LIBCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
|
||||
endif()
|
||||
# Buggy in GCC 4.8
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
|
||||
list(APPEND unix-warnings -Weffc++)
|
||||
endif()
|
||||
|
||||
target_compile_options(CLI11_warnings
|
||||
INTERFACE
|
||||
$<$<BOOL:${CLI11_FORCE_LIBCXX}>:-stdlib=libc++>
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/W4 $<$<BOOL:${CLI11_WARNINGS_AS_ERRORS}>:/WX>>
|
||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:${unix-warnings} $<$<BOOL:${CLI11_WARNINGS_AS_ERRORS}>:-Werror>>)
|
||||
|
||||
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.13)
|
||||
target_link_options(CLI11_warnings
|
||||
INTERFACE
|
||||
$<$<BOOL:${CLI11_FORCE_LIBCXX}>:-stdlib=libc++>)
|
||||
endif()
|
||||
|
||||
set(CUR_PROJ ON)
|
||||
set(CMAKE_CXX_STANDARD ${CLI11_CXX_STD})
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
option(CLI11_CUDA_TESTS "Build the tests with NVCC to check for warnings there - requires CMake 3.9+")
|
||||
# Allow IDE's to group targets into folders
|
||||
add_library(CLI11 INTERFACE)
|
||||
add_library(CLI11::CLI11 ALIAS CLI11) # for add_subdirectory calls
|
||||
|
||||
# Duplicated because CMake adds the current source dir if you don't.
|
||||
target_include_directories(CLI11 INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
|
||||
# To see in IDE, headers must be listed for target
|
||||
set(header-patterns "${PROJECT_SOURCE_DIR}/include/CLI/*")
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.12)
|
||||
list(INSERT header-patterns 0 CONFIGURE_DEPENDS)
|
||||
endif()
|
||||
|
||||
file(GLOB CLI11_headers ${header-patterns})
|
||||
|
||||
# Allow tests to be run on CUDA
|
||||
if(CLI11_CUDA_TESTS)
|
||||
enable_language(CUDA)
|
||||
|
||||
@ -54,33 +165,9 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe --display_error_number")
|
||||
endif()
|
||||
|
||||
option(CLI11_WARNINGS_AS_ERRORS "Turn all warnings into errors (for CI)")
|
||||
|
||||
# Be moderately paranoid with flags
|
||||
if(MSVC)
|
||||
target_compile_options(CLI11_warnings INTERFACE "/W4")
|
||||
if(CLI11_WARNINGS_AS_ERRORS)
|
||||
target_compile_options(CLI11_warnings INTERFACE "/WX")
|
||||
endif()
|
||||
else()
|
||||
target_compile_options(CLI11_warnings INTERFACE -Wall -Wextra -pedantic -Wshadow -Wsign-conversion -Wswitch-enum)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
|
||||
# GCC 4.8 has a false positive
|
||||
# Other compilers ignore this flag
|
||||
target_compile_options(CLI11_warnings INTERFACE -Weffc++)
|
||||
endif()
|
||||
endif()
|
||||
if(CLI11_WARNINGS_AS_ERRORS)
|
||||
target_compile_options(CLI11_warnings INTERFACE -Werror)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.6)
|
||||
option(CLI11_CLANG_TIDY "Look for and use Clang-Tidy")
|
||||
set(CLI11_CLANG_TIDY_OPTIONS "" CACHE STRING "Clang tidy option, such as -fix")
|
||||
if(CLI11_CLANG_TIDY)
|
||||
|
||||
# Prepare Clang-Tidy
|
||||
if(CLI11_CLANG_TIDY)
|
||||
find_program(
|
||||
CLANG_TIDY_EXE
|
||||
NAMES "clang-tidy"
|
||||
@ -89,55 +176,16 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
)
|
||||
|
||||
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" ${CLI11_CLANG_TIDY_OPTIONS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (EXISTS book)
|
||||
add_subdirectory(book)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_VERSION VERSION_LESS 3.9)
|
||||
find_package(Doxygen)
|
||||
if(Doxygen_FOUND)
|
||||
add_subdirectory(docs)
|
||||
else()
|
||||
message(STATUS "Doxygen not found, not building docs")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Newer CMake adds Doxygen support, update CMake for docs")
|
||||
endif()
|
||||
else()
|
||||
set(CUR_PROJ OFF)
|
||||
endif()
|
||||
|
||||
# Allow dependent options
|
||||
include(CMakeDependentOption)
|
||||
|
||||
# Allow IDE's to group targets into folders
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
file(GLOB CLI11_headers "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/*")
|
||||
# To see in IDE, must be listed for target
|
||||
|
||||
add_library(CLI11 INTERFACE)
|
||||
|
||||
# Duplicated because CMake adds the current source dir if you don't.
|
||||
target_include_directories(CLI11 INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
|
||||
# Make add_subdirectory work like find_package
|
||||
add_library(CLI11::CLI11 ALIAS CLI11)
|
||||
|
||||
option(CLI11_INSTALL "Install the CLI11 folder to include during install process" ${CUR_PROJ})
|
||||
|
||||
# This folder should be installed
|
||||
if(CLI11_INSTALL)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/CLI DESTINATION include)
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
# Make an export target
|
||||
install(TARGETS CLI11
|
||||
EXPORT CLI11Targets)
|
||||
install(TARGETS CLI11 EXPORT CLI11Targets)
|
||||
endif()
|
||||
|
||||
# Use find_package on the installed package
|
||||
@ -146,14 +194,13 @@ endif()
|
||||
# import Targets.cmake
|
||||
|
||||
# Add the version in a CMake readable way
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CLI11ConfigVersion.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/CLI11ConfigVersion.cmake" @ONLY)
|
||||
configure_file("cmake/CLI11ConfigVersion.cmake.in"
|
||||
"CLI11ConfigVersion.cmake" @ONLY)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
# These installs only make sense for a local project
|
||||
if(CUR_PROJ)
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
# Make version available in the install
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/CLI11ConfigVersion.cmake"
|
||||
install(FILES "${PROJECT_BINARY_DIR}/CLI11ConfigVersion.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CLI11)
|
||||
|
||||
# Install the export target as a file
|
||||
@ -171,67 +218,64 @@ if(CUR_PROJ)
|
||||
export(PACKAGE CLI11)
|
||||
endif()
|
||||
|
||||
option(CLI11_SINGLE_FILE "Generate a single header file" OFF)
|
||||
|
||||
if(CLI11_SINGLE_FILE)
|
||||
# Single file test
|
||||
# Single file test
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
find_package(PythonInterp REQUIRED)
|
||||
set(Python_VERSION ${PYTHON_VERSION_STRING})
|
||||
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
|
||||
add_executable(Python::Interpreter IMPORTED)
|
||||
set_target_properties(Python::Interpreter
|
||||
PROPERTIES
|
||||
IMPORTED_LOCATION "${PYTHON_EXECUTABLE}"
|
||||
VERSION "${PYTHON_VERSION_STRING}")
|
||||
else()
|
||||
find_package(Python REQUIRED)
|
||||
find_package(Python COMPONENTS Interpreter REQUIRED)
|
||||
endif()
|
||||
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include")
|
||||
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp"
|
||||
COMMAND "${Python_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py" "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp"
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp" ${CLI11_headers}
|
||||
)
|
||||
add_custom_target(generate_cli_single_file ALL
|
||||
COMMAND Python::Interpreter
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp"
|
||||
DEPENDS
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp"
|
||||
${CLI11_headers})
|
||||
add_custom_target(CLI11-generate-single-file ALL
|
||||
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp")
|
||||
set_target_properties(generate_cli_single_file
|
||||
PROPERTIES FOLDER "Scripts")
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp DESTINATION include)
|
||||
set_property(TARGET CLI11-generate-single-file PROPERTY FOLDER "Scripts")
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp
|
||||
DESTINATION include)
|
||||
add_library(CLI11_SINGLE INTERFACE)
|
||||
target_link_libraries(CLI11_SINGLE INTERFACE CLI11)
|
||||
add_dependencies(CLI11_SINGLE generate_cli_single_file)
|
||||
add_dependencies(CLI11_SINGLE CLI11-generate-single-file)
|
||||
target_compile_definitions(CLI11_SINGLE INTERFACE -DCLI11_SINGLE_FILE)
|
||||
target_include_directories(CLI11_SINGLE INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/")
|
||||
target_include_directories(CLI11_SINGLE INTERFACE
|
||||
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include/>
|
||||
$<INSTALL_INTERFACE:include>)
|
||||
endif()
|
||||
|
||||
cmake_dependent_option(CLI11_SINGLE_FILE_TESTS
|
||||
"Duplicate all the tests for a single file build"
|
||||
OFF
|
||||
"CLI11_SINGLE_FILE"
|
||||
OFF)
|
||||
|
||||
|
||||
if(DEFINED CLI11_TESTING)
|
||||
set(CLI11_TESTING_INTERNAL "${CLI11_TESTING}")
|
||||
elseif(CUR_PROJ)
|
||||
option(BUILD_TESTING "Build the tests" ON)
|
||||
set(CLI11_TESTING_INTERNAL "${BUILD_TESTING}")
|
||||
else()
|
||||
set(CLI11_TESTING_INTERNAL OFF)
|
||||
endif()
|
||||
|
||||
if(CLI11_TESTING_INTERNAL)
|
||||
enable_testing()
|
||||
if(CLI11_BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
cmake_dependent_option(CLI11_EXAMPLES "Build the examples" ON "CUR_PROJ" OFF)
|
||||
if(CLI11_EXAMPLES)
|
||||
if(CLI11_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
if(CLI11_BUILD_DOCS)
|
||||
add_subdirectory(docs)
|
||||
endif()
|
||||
|
||||
# From a build system, this might not be included.
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND EXISTS book)
|
||||
add_subdirectory(book)
|
||||
endif()
|
||||
|
||||
# Packaging support
|
||||
# Packaging support
|
||||
set(CPACK_PACKAGE_VENDOR "github.com/CLIUtils/CLI11")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Command line interface")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR ${CLI11_VERSION_MAJOR})
|
||||
set(CPACK_PACKAGE_VERSION_MINOR ${CLI11_VERSION_MINOR})
|
||||
set(CPACK_PACKAGE_VERSION_PATCH ${CLI11_VERSION_PATCH})
|
||||
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Command line parser with simple and intuitive interface")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
||||
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
|
||||
set(CPACK_SOURCE_GENERATOR "TGZ;ZIP")
|
||||
|
@ -10,7 +10,7 @@ variables:
|
||||
cli11.single: ON
|
||||
cli11.std: 14
|
||||
cli11.build_type: Debug
|
||||
cli11.options:
|
||||
cli11.options: -DCLI11_EXAMPLES_JSON=ON
|
||||
CMAKE_BUILD_PARALLEL_LEVEL: 4
|
||||
|
||||
jobs:
|
||||
@ -84,6 +84,7 @@ jobs:
|
||||
gcc4.8:
|
||||
containerImage: gcc:4.8
|
||||
cli11.std: 11
|
||||
cli11.options:
|
||||
clang3.4:
|
||||
containerImage: silkeh/clang:3.4
|
||||
cli11.std: 11
|
||||
|
@ -37,6 +37,10 @@ macro(add_gtest TESTNAME)
|
||||
else()
|
||||
add_test(${TESTNAME} ${TESTNAME})
|
||||
set_target_properties(${TESTNAME} PROPERTIES FOLDER "Tests")
|
||||
if (CLI11_FORCE_LIBCXX)
|
||||
set_property(TARGET ${T} APPEND_STRING
|
||||
PROPERTY LINK_FLAGS -stdlib=libc++)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endmacro()
|
||||
|
@ -1,46 +1,48 @@
|
||||
|
||||
function(add_cli_exe T)
|
||||
add_executable(${T} ${ARGN} ${CLI11_headers})
|
||||
target_link_libraries(${T} PUBLIC CLI11)
|
||||
set_target_properties(
|
||||
${T} PROPERTIES
|
||||
FOLDER "Examples"
|
||||
)
|
||||
|
||||
if(CLANG_TIDY_EXE)
|
||||
set_target_properties(
|
||||
${T} PROPERTIES
|
||||
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
|
||||
)
|
||||
set_property(TARGET ${T} PROPERTY FOLDER "Examples")
|
||||
if(CLI11_FORCE_LIBCXX)
|
||||
set_property(TARGET ${T} APPEND_STRING PROPERTY LINK_FLAGS -stdlib=libc++)
|
||||
endif()
|
||||
if(CLI11_CLANG_TIDY)
|
||||
set_property(TARGET ${T} PROPERTY CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
option(CLI11_EXAMPLE_JSON OFF)
|
||||
if(CLI11_EXAMPLE_JSON)
|
||||
if(NOT EXISTS "${CLI11_SOURCE_DIR}/extern/json/single_include/nlohmann/json.hpp")
|
||||
message(ERROR "You are missing the json package for CLI11_EXAMPLE_JSON. Please update your submodules (git submodule update --init)")
|
||||
endif()
|
||||
if(CMAKE_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
|
||||
message(WARNING "The json example requires GCC 4.8+ (requirement on json library)")
|
||||
if(CLI11_BUILD_EXAMPLES_JSON)
|
||||
FetchContent_Declare(json
|
||||
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
||||
GIT_SHALLOW 1
|
||||
GIT_TAG v3.7.3)
|
||||
FetchContent_GetProperties(json)
|
||||
if (NOT json_POPULATED)
|
||||
FetchContent_Populate(json)
|
||||
endif()
|
||||
|
||||
add_cli_exe(json json.cpp)
|
||||
target_include_directories(json PUBLIC SYSTEM "${CLI11_SOURCE_DIR}/extern/json/single_include")
|
||||
target_include_directories(json PUBLIC SYSTEM "${json_SOURCE_DIR}/single_include")
|
||||
|
||||
add_test(NAME json_config_out COMMAND json --item 2)
|
||||
set_property(TEST json_config_out PROPERTY PASS_REGULAR_EXPRESSION
|
||||
"{"
|
||||
"\"item\": \"2\""
|
||||
"\"simple\": false"
|
||||
"}")
|
||||
[[{]]
|
||||
[["item": "2"]]
|
||||
[["simple": false]]
|
||||
[[}]]
|
||||
)
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/input.json" [=[{"item":3,"simple":false}]=])
|
||||
add_test(NAME json_config_in COMMAND json --config "${CMAKE_CURRENT_BINARY_DIR}/input.json")
|
||||
set_property(TEST json_config_in PROPERTY PASS_REGULAR_EXPRESSION
|
||||
"{"
|
||||
"\"item\": \"3\""
|
||||
"\"simple\": false"
|
||||
"}")
|
||||
[[{]]
|
||||
[["item": "3"]]
|
||||
[["simple": false]]
|
||||
[[}]]
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
add_cli_exe(simple simple.cpp)
|
||||
add_test(NAME simple_basic COMMAND simple)
|
||||
add_test(NAME simple_all COMMAND simple -f filename.txt -c 12 --flag --flag -d 1.2)
|
||||
|
1
extern/json
vendored
1
extern/json
vendored
@ -1 +0,0 @@
|
||||
Subproject commit 1126c9ca74fdea22d2ce3a065ac0fcb5792cbdaf
|
1
extern/sanitizers
vendored
1
extern/sanitizers
vendored
@ -1 +0,0 @@
|
||||
Subproject commit 99e159ec9bc8dd362b08d18436bd40ff0648417b
|
@ -5,10 +5,20 @@ endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/cmake")
|
||||
|
||||
# If submodule is available, add sanitizers
|
||||
# Set SANITIZE_ADDRESS, SANITIZE_MEMORY, SANITIZE_THREAD or SANITIZE_UNDEFINED
|
||||
if(EXISTS "${CLI11_SOURCE_DIR}/extern/sanitizers/cmake/FindSanitizers.cmake")
|
||||
list(APPEND CMAKE_MODULE_PATH "${CLI11_SOURCE_DIR}/extern/sanitizers/cmake")
|
||||
if(CLI11_SANITIZERS)
|
||||
FetchContent_Declare(sanitizers
|
||||
GIT_REPOSITORY https://github.com/arsenm/sanitizers-cmake.git
|
||||
GIT_SHALLOW 1
|
||||
GIT_TAG 99e159e)
|
||||
|
||||
FetchContent_GetProperties(sanitizers)
|
||||
|
||||
if (NOT sanitizers_POPULATED)
|
||||
FetchContent_Populate(sanitizers)
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${sanitizers_SOURCE_DIR}/cmake")
|
||||
|
||||
find_package(Sanitizers)
|
||||
if(SANITIZE_ADDRESS)
|
||||
message(STATUS "You might want to use \"${ASan_WRAPPER}\" to run your program")
|
||||
@ -44,61 +54,53 @@ if(WIN32)
|
||||
list(APPEND CLI11_TESTS WindowsTest)
|
||||
endif()
|
||||
|
||||
set(CLI11_MULTIONLY_TESTS
|
||||
TimerTest
|
||||
)
|
||||
set(CLI11_MULTIONLY_TESTS TimerTest)
|
||||
|
||||
# Only affects current directory, so safe
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
foreach(T ${CLI11_TESTS})
|
||||
foreach(T IN LISTS CLI11_TESTS)
|
||||
if(CLI11_CUDA_TESTS)
|
||||
set_property(
|
||||
SOURCE ${T}.cpp
|
||||
PROPERTY
|
||||
LANGUAGE CUDA
|
||||
PROPERTY LANGUAGE CUDA
|
||||
)
|
||||
endif()
|
||||
|
||||
add_executable(${T} ${T}.cpp ${CLI11_headers})
|
||||
add_sanitizers(${T})
|
||||
target_link_libraries(${T} PUBLIC CLI11)
|
||||
if(NOT CLI11_CUDA_TESTS)
|
||||
target_link_libraries(${T} PUBLIC CLI11_warnings)
|
||||
target_link_libraries(${T} PRIVATE CLI11_warnings)
|
||||
endif()
|
||||
target_link_libraries(${T} PRIVATE CLI11)
|
||||
add_gtest(${T})
|
||||
|
||||
if(CLI11_SINGLE_FILE AND CLI11_SINGLE_FILE_TESTS)
|
||||
add_executable(${T}_Single ${T}.cpp)
|
||||
target_link_libraries(${T}_Single PUBLIC CLI11_SINGLE)
|
||||
target_link_libraries(${T}_Single PRIVATE CLI11_SINGLE)
|
||||
add_gtest(${T}_Single)
|
||||
set_target_properties(${T}_Single
|
||||
PROPERTIES
|
||||
FOLDER "Tests Single File")
|
||||
set_property(TARGET ${T}_Single PROPERTY FOLDER "Tests Single File")
|
||||
endif()
|
||||
|
||||
endforeach()
|
||||
|
||||
foreach(T ${CLI11_MULTIONLY_TESTS})
|
||||
|
||||
foreach(T IN LISTS CLI11_MULTIONLY_TESTS)
|
||||
add_executable(${T} ${T}.cpp ${CLI11_headers})
|
||||
add_sanitizers(${T})
|
||||
target_link_libraries(${T} PUBLIC CLI11)
|
||||
add_gtest(${T})
|
||||
|
||||
endforeach()
|
||||
|
||||
# Add -Wno-deprecated-declarations to DeprecatedTest
|
||||
if(NOT MSVC)
|
||||
target_compile_options(DeprecatedTest PRIVATE -Wno-deprecated-declarations)
|
||||
if(TARGET DeprecatedTest_Single)
|
||||
target_compile_options(DeprecatedTest_Single PRIVATE -Wno-deprecated-declarations)
|
||||
endif()
|
||||
else()
|
||||
target_compile_options(DeprecatedTest PRIVATE "/wd4996")
|
||||
if(TARGET DeprecatedTest_Single)
|
||||
target_compile_options(DeprecatedTest_Single PRIVATE "/wd4996")
|
||||
endif()
|
||||
set(no-deprecated-declarations
|
||||
$<$<CXX_COMPILER_ID:MSVC>:/wd4996>
|
||||
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated-declarations>
|
||||
)
|
||||
target_compile_options(DeprecatedTest
|
||||
PRIVATE
|
||||
${no-deprecated-declarations})
|
||||
if (TARGET DeprecatedTest_Single)
|
||||
target_compile_options(DeprecatedTest_Single
|
||||
PRIVATE
|
||||
${no-deprecated-declarations})
|
||||
endif()
|
||||
|
||||
# Link test (build error if inlines missing)
|
||||
@ -108,11 +110,22 @@ set_target_properties(link_test_1 PROPERTIES FOLDER "Tests")
|
||||
add_executable(link_test_2 link_test_2.cpp)
|
||||
target_link_libraries(link_test_2 PUBLIC CLI11 link_test_1)
|
||||
add_gtest(link_test_2)
|
||||
if(CLI11_FORCE_LIBCXX)
|
||||
set_property(TARGET link_test_1 APPEND_STRING
|
||||
PROPERTY LINK_FLAGS -stdlib=libc++)
|
||||
set_property(TARGET link_test_2 APPEND_STRING
|
||||
PROPERTY LINK_FLAGS -stdlib=libc++)
|
||||
endif()
|
||||
|
||||
# Add informational printout
|
||||
# Force this to be in a standard location so CTest can find it
|
||||
add_executable(informational informational.cpp)
|
||||
target_link_libraries(informational PUBLIC CLI11)
|
||||
if(CLI11_FORCE_LIBCXX)
|
||||
set_property(TARGET informational APPEND_STRING
|
||||
PROPERTY LINK_FLAGS -stdlib=libc++)
|
||||
endif()
|
||||
|
||||
# Force this to be in a standard location so CTest can find it
|
||||
set_target_properties(informational PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
|
||||
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}"
|
||||
@ -124,21 +137,22 @@ set_target_properties(informational PROPERTIES
|
||||
# Adding this printout to CTest
|
||||
file(WRITE "${PROJECT_BINARY_DIR}/CTestCustom.cmake"
|
||||
"set(CTEST_CUSTOM_PRE_TEST \"${CMAKE_BINARY_DIR}/informational\")"
|
||||
)
|
||||
)
|
||||
|
||||
# Add boost to test boost::optional if available
|
||||
find_package(Boost 1.61)
|
||||
if(Boost_FOUND)
|
||||
if(TARGET Boost::boost)
|
||||
|
||||
set(boost-optional-def $<$<BOOL:${Boost_FOUND}>:CLI11_BOOST_OPTIONAL>)
|
||||
|
||||
target_compile_definitions(informational PRIVATE ${boost-optional-def})
|
||||
target_compile_definitions(OptionalTest PRIVATE ${boost-optional-def})
|
||||
|
||||
if(TARGET Boost::boost)
|
||||
target_link_libraries(informational PRIVATE Boost::boost)
|
||||
target_link_libraries(OptionalTest PRIVATE Boost::boost)
|
||||
else()
|
||||
elseif(BOOST_FOUND)
|
||||
target_include_directories(informational PRIVATE ${Boost_INCLUDE_DIRS})
|
||||
target_include_directories(OptionalTest PRIVATE ${Boost_INCLUDE_DIRS})
|
||||
endif()
|
||||
|
||||
target_compile_definitions(informational PRIVATE CLI11_BOOST_OPTIONAL)
|
||||
target_compile_definitions(OptionalTest PRIVATE CLI11_BOOST_OPTIONAL)
|
||||
endif()
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL Coverage)
|
||||
@ -148,6 +162,7 @@ if(CMAKE_BUILD_TYPE STREQUAL Coverage)
|
||||
EXECUTABLE ctest
|
||||
DEPENDENCIES
|
||||
${CLI11_TESTS}
|
||||
${CLI11_MULTIONLY_TESTS})
|
||||
${CLI11_MULTIONLY_TESTS}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user