[med-svn] [Git][med-team/libmcfp][master] 2 commits: New upstream version 1.4.2
Maarten L. Hekkelman (@mhekkel-guest)
gitlab at salsa.debian.org
Mon May 26 09:49:51 BST 2025
Maarten L. Hekkelman pushed to branch master at Debian Med / libmcfp
Commits:
c0f7dfcb by Maarten L. Hekkelman at 2025-05-26T10:39:14+02:00
New upstream version 1.4.2
- - - - -
5361de6d by Maarten L. Hekkelman at 2025-05-26T10:45:31+02:00
Update upstream source from tag 'upstream/1.4.2'
Update to upstream version '1.4.2'
with Debian dir 5f1a87b18f5a4bebbca2dd4c6c779b3303d74f66
- - - - -
20 changed files:
- .github/workflows/build-documentation.yml
- CMakeLists.txt
- LICENSE
- README.md
- changelog
- + cmake/CPM.cmake
- − cmake/libmcfpConfig.cmake.in
- + cmake/test-charconv.cpp
- debian/changelog
- debian/rules
- docs/CMakeLists.txt
- examples/example.cpp
- include/mcfp/detail/charconv.hpp
- include/mcfp/detail/options.hpp
- include/mcfp/error.hpp
- include/mcfp/mcfp.hpp
- include/mcfp/text.hpp
- include/mcfp/utilities.hpp
- test/CMakeLists.txt
- test/unit-test.cpp
Changes:
=====================================
.github/workflows/build-documentation.yml
=====================================
@@ -19,7 +19,7 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout at v1
+ - uses: actions/checkout at v4
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
@@ -29,7 +29,7 @@ jobs:
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Install dependencies Ubuntu
- run: sudo apt-get update && sudo apt-get install cmake doxygen
+ run: sudo apt-get update && sudo apt-get install cmake doxygen graphviz
- uses: actions/setup-python at v4
with:
@@ -47,7 +47,7 @@ jobs:
ls -l ${{ steps.strings.outputs.build-output-dir }}/docs/sphinx
- name: Upload artifact
- uses: actions/upload-pages-artifact at v2
+ uses: actions/upload-pages-artifact at v3
with:
path: ${{ steps.strings.outputs.build-output-dir }}/docs/sphinx
@@ -62,4 +62,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
- uses: actions/deploy-pages at v2
+ uses: actions/deploy-pages at v4
=====================================
CMakeLists.txt
=====================================
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-2-Clause
#
-# Copyright (c) 2022 Maarten L. Hekkelman
+# Copyright (c) 2022-2025 Maarten L. Hekkelman
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
@@ -25,18 +25,14 @@
cmake_minimum_required(VERSION 3.23)
# set the project name
-project(mcfp VERSION 1.3.5 LANGUAGES CXX)
+project(mcfp VERSION 1.4.2 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
-include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
+include(CPM)
include(CTest)
-set(CXX_EXTENSIONS OFF)
-set(CMAKE_CXX_STANDARD 17 CACHE STRING "The minimum version of C++ required for this library")
-set(CMAKE_CXX_STANDARD_REQUIRED ON)
-
option(BUILD_DOCUMENTATION "Build the documentation" OFF)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
@@ -49,32 +45,12 @@ elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
-if(MSVC)
- # make msvc standards compliant...
- add_compile_options(/permissive-)
-
- if(${CMAKE_SYSTEM_VERSION} GREATER_EQUAL 10) # Windows 10
- add_definitions(-D _WIN32_WINNT=0x0A00)
- elseif(${CMAKE_SYSTEM_VERSION} EQUAL 6.3) # Windows 8.1
- add_definitions(-D _WIN32_WINNT=0x0603)
- elseif(${CMAKE_SYSTEM_VERSION} EQUAL 6.2) # Windows 8
- add_definitions(-D _WIN32_WINNT=0x0602)
- elseif(${CMAKE_SYSTEM_VERSION} EQUAL 6.1) # Windows 7
- add_definitions(-D _WIN32_WINNT=0x0601)
- elseif(${CMAKE_SYSTEM_VERSION} EQUAL 6.0) # Windows Vista
- add_definitions(-D _WIN32_WINNT=0x0600)
- else() # Windows XP (5.1)
- add_definitions(-D _WIN32_WINNT=0x0501)
- endif()
-
- add_definitions(-DNOMINMAX)
-endif()
-
add_library(mcfp INTERFACE)
add_library(mcfp::mcfp ALIAS mcfp)
target_compile_features(mcfp INTERFACE cxx_std_20)
+# My god... why?
if(MSVC)
target_compile_definitions(mcfp INTERFACE NOMINMAX=1)
endif()
@@ -104,6 +80,13 @@ if(OLD_CONFIG_FILES)
install(CODE "file(REMOVE_RECURSE ${OLD_CONFIG_FILES})")
endif()
+# And an old include file
+if(EXISTS ${CMAKE_INSTALL_FULL_INCLUDEDIR}/mcfp.hpp)
+ message(
+ WARNING "Installation will remove old header file: ${CMAKE_INSTALL_FULL_INCLUDEDIR}/mcfp.hpp")
+ install(CODE "file(REMOVE ${CMAKE_INSTALL_FULL_INCLUDEDIR}/mcfp.hpp)")
+endif()
+
install(TARGETS mcfp
EXPORT mcfp
FILE_SET mcfp_headers
@@ -123,28 +106,10 @@ write_basic_package_version_file(
COMPATIBILITY AnyNewerVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mcfpConfig.cmake"
- "${CMAKE_CURRENT_BINARY_DIR}/mcfpConfigVersion.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/mcfpConfigVersion.cmake"
DESTINATION lib/cmake/mcfp)
-# Install old config file, for use in older code
-install(EXPORT mcfp
- NAMESPACE libmcfp::
- DESTINATION lib/cmake/libmcfp
- FILE "libmcfpTargets.cmake")
-
-configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/libmcfpConfig.cmake.in
- ${CMAKE_CURRENT_BINARY_DIR}/libmcfpConfig.cmake
- INSTALL_DESTINATION lib/cmake/libmcfp)
-write_basic_package_version_file(
- ${CMAKE_CURRENT_BINARY_DIR}/libmcfpConfigVersion.cmake
- VERSION ${PROJECT_VERSION}
- COMPATIBILITY AnyNewerVersion)
-
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmcfpConfig.cmake"
- "${CMAKE_CURRENT_BINARY_DIR}/libmcfpConfigVersion.cmake"
- DESTINATION lib/cmake/libmcfp)
-
-if(BUILD_TESTING)
+if(BUILD_TESTING AND PROJECT_IS_TOP_LEVEL)
add_subdirectory(test)
endif()
=====================================
LICENSE
=====================================
@@ -1,6 +1,6 @@
BSD-2-Clause License
-Copyright (c) 2022 Maarten L. Hekkelman
+Copyright (c) 2025 Maarten L. Hekkelman
All rights reserved.
Redistribution and use in source and binary forms, with or without
=====================================
README.md
=====================================
@@ -11,7 +11,7 @@ There's a config file parser as well.
## Synopsis
-```c++
+```cpp
// Example of using libmcfp
#include <iostream>
@@ -62,7 +62,7 @@ int main(int argc, char * const argv[])
config.parse(argc, argv, ec);
if (ec)
{
- std::cerr << "Error parsing arguments: " << ec.message() << std::endl;
+ std::cerr << "Error parsing argument " << std::quoted(config.get_last_option()) << ": " << ec.message() << std::endl;
exit(1);
}
@@ -82,7 +82,7 @@ int main(int argc, char * const argv[])
config.parse_config_file("config", "example.conf", { "." }, ec);
if (ec)
{
- std::cerr << "Error parsing config file: " << ec.message() << std::endl;
+ std::cerr << "Error parsing config file, option " << std::quoted(config.get_last_option()) << ": " << ec.message() << std::endl;
exit(1);
}
@@ -128,9 +128,7 @@ Use [cmake](https://cmake.org/) to install _libmcfp_.
```bash
git clone https://github.com/mhekkel/libmcfp.git
cd libmcfp
-mkdir build
-cd build
-cmake ..
-cmake --build .
-cmake --install .
+cmake -S . -B build
+cmake --build build
+cmake --install build
```
=====================================
changelog
=====================================
@@ -1,3 +1,15 @@
+Version 1.4.2
+- Clean up makefile
+
+Version 1.4.1
+- Remove libmcfp cmake config entirely
+- Do not build tests when BUILD_TESTING is ON, use
+ our own flag instead. Avoids building tests when
+ included by other packages.
+
+Version 1.4.0
+- Better error reporting
+
Version 1.3.5
- Install a cmake version file
- Avoid using catch2 version 2
=====================================
cmake/CPM.cmake
=====================================
@@ -0,0 +1,1291 @@
+# CPM.cmake - CMake's missing package manager
+# ===========================================
+# See https://github.com/cpm-cmake/CPM.cmake for usage and update instructions.
+#
+# MIT License
+# -----------
+#[[
+ Copyright (c) 2019-2023 Lars Melchior and contributors
+
+ 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.
+]]
+
+cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
+
+# Initialize logging prefix
+if(NOT CPM_INDENT)
+ set(CPM_INDENT
+ "CPM:"
+ CACHE INTERNAL ""
+ )
+endif()
+
+if(NOT COMMAND cpm_message)
+ function(cpm_message)
+ message(${ARGV})
+ endfunction()
+endif()
+
+if(DEFINED EXTRACTED_CPM_VERSION)
+ set(CURRENT_CPM_VERSION "${EXTRACTED_CPM_VERSION}${CPM_DEVELOPMENT}")
+else()
+ set(CURRENT_CPM_VERSION 0.40.8)
+endif()
+
+get_filename_component(CPM_CURRENT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
+if(CPM_DIRECTORY)
+ if(NOT CPM_DIRECTORY STREQUAL CPM_CURRENT_DIRECTORY)
+ if(CPM_VERSION VERSION_LESS CURRENT_CPM_VERSION)
+ message(
+ AUTHOR_WARNING
+ "${CPM_INDENT} \
+A dependency is using a more recent CPM version (${CURRENT_CPM_VERSION}) than the current project (${CPM_VERSION}). \
+It is recommended to upgrade CPM to the most recent version. \
+See https://github.com/cpm-cmake/CPM.cmake for more information."
+ )
+ endif()
+ if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
+ include(FetchContent)
+ endif()
+ return()
+ endif()
+
+ get_property(
+ CPM_INITIALIZED GLOBAL ""
+ PROPERTY CPM_INITIALIZED
+ SET
+ )
+ if(CPM_INITIALIZED)
+ return()
+ endif()
+endif()
+
+if(CURRENT_CPM_VERSION MATCHES "development-version")
+ message(
+ WARNING "${CPM_INDENT} Your project is using an unstable development version of CPM.cmake. \
+Please update to a recent release if possible. \
+See https://github.com/cpm-cmake/CPM.cmake for details."
+ )
+endif()
+
+set_property(GLOBAL PROPERTY CPM_INITIALIZED true)
+
+macro(cpm_set_policies)
+ # the policy allows us to change options without caching
+ cmake_policy(SET CMP0077 NEW)
+ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
+
+ # the policy allows us to change set(CACHE) without caching
+ if(POLICY CMP0126)
+ cmake_policy(SET CMP0126 NEW)
+ set(CMAKE_POLICY_DEFAULT_CMP0126 NEW)
+ endif()
+
+ # The policy uses the download time for timestamp, instead of the timestamp in the archive. This
+ # allows for proper rebuilds when a projects url changes
+ if(POLICY CMP0135)
+ cmake_policy(SET CMP0135 NEW)
+ set(CMAKE_POLICY_DEFAULT_CMP0135 NEW)
+ endif()
+
+ # treat relative git repository paths as being relative to the parent project's remote
+ if(POLICY CMP0150)
+ cmake_policy(SET CMP0150 NEW)
+ set(CMAKE_POLICY_DEFAULT_CMP0150 NEW)
+ endif()
+endmacro()
+cpm_set_policies()
+
+option(CPM_USE_LOCAL_PACKAGES "Always try to use `find_package` to get dependencies"
+ $ENV{CPM_USE_LOCAL_PACKAGES}
+)
+option(CPM_LOCAL_PACKAGES_ONLY "Only use `find_package` to get dependencies"
+ $ENV{CPM_LOCAL_PACKAGES_ONLY}
+)
+option(CPM_DOWNLOAD_ALL "Always download dependencies from source" $ENV{CPM_DOWNLOAD_ALL})
+option(CPM_DONT_UPDATE_MODULE_PATH "Don't update the module path to allow using find_package"
+ $ENV{CPM_DONT_UPDATE_MODULE_PATH}
+)
+option(CPM_DONT_CREATE_PACKAGE_LOCK "Don't create a package lock file in the binary path"
+ $ENV{CPM_DONT_CREATE_PACKAGE_LOCK}
+)
+option(CPM_INCLUDE_ALL_IN_PACKAGE_LOCK
+ "Add all packages added through CPM.cmake to the package lock"
+ $ENV{CPM_INCLUDE_ALL_IN_PACKAGE_LOCK}
+)
+option(CPM_USE_NAMED_CACHE_DIRECTORIES
+ "Use additional directory of package name in cache on the most nested level."
+ $ENV{CPM_USE_NAMED_CACHE_DIRECTORIES}
+)
+
+set(CPM_VERSION
+ ${CURRENT_CPM_VERSION}
+ CACHE INTERNAL ""
+)
+set(CPM_DIRECTORY
+ ${CPM_CURRENT_DIRECTORY}
+ CACHE INTERNAL ""
+)
+set(CPM_FILE
+ ${CMAKE_CURRENT_LIST_FILE}
+ CACHE INTERNAL ""
+)
+set(CPM_PACKAGES
+ ""
+ CACHE INTERNAL ""
+)
+set(CPM_DRY_RUN
+ OFF
+ CACHE INTERNAL "Don't download or configure dependencies (for testing)"
+)
+
+if(DEFINED ENV{CPM_SOURCE_CACHE})
+ set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE})
+else()
+ set(CPM_SOURCE_CACHE_DEFAULT OFF)
+endif()
+
+set(CPM_SOURCE_CACHE
+ ${CPM_SOURCE_CACHE_DEFAULT}
+ CACHE PATH "Directory to download CPM dependencies"
+)
+
+if(NOT CPM_DONT_UPDATE_MODULE_PATH AND NOT DEFINED CMAKE_FIND_PACKAGE_REDIRECTS_DIR)
+ set(CPM_MODULE_PATH
+ "${CMAKE_BINARY_DIR}/CPM_modules"
+ CACHE INTERNAL ""
+ )
+ # remove old modules
+ file(REMOVE_RECURSE ${CPM_MODULE_PATH})
+ file(MAKE_DIRECTORY ${CPM_MODULE_PATH})
+ # locally added CPM modules should override global packages
+ set(CMAKE_MODULE_PATH "${CPM_MODULE_PATH};${CMAKE_MODULE_PATH}")
+endif()
+
+if(NOT CPM_DONT_CREATE_PACKAGE_LOCK)
+ set(CPM_PACKAGE_LOCK_FILE
+ "${CMAKE_BINARY_DIR}/cpm-package-lock.cmake"
+ CACHE INTERNAL ""
+ )
+ file(WRITE ${CPM_PACKAGE_LOCK_FILE}
+ "# CPM Package Lock\n# This file should be committed to version control\n\n"
+ )
+endif()
+
+include(FetchContent)
+
+# Try to infer package name from git repository uri (path or url)
+function(cpm_package_name_from_git_uri URI RESULT)
+ if("${URI}" MATCHES "([^/:]+)/?.git/?$")
+ set(${RESULT}
+ ${CMAKE_MATCH_1}
+ PARENT_SCOPE
+ )
+ else()
+ unset(${RESULT} PARENT_SCOPE)
+ endif()
+endfunction()
+
+# Try to infer package name and version from a url
+function(cpm_package_name_and_ver_from_url url outName outVer)
+ if(url MATCHES "[/\\?]([a-zA-Z0-9_\\.-]+)\\.(tar|tar\\.gz|tar\\.bz2|zip|ZIP)(\\?|/|$)")
+ # We matched an archive
+ set(filename "${CMAKE_MATCH_1}")
+
+ if(filename MATCHES "([a-zA-Z0-9_\\.-]+)[_-]v?(([0-9]+\\.)*[0-9]+[a-zA-Z0-9]*)")
+ # We matched <name>-<version> (ie foo-1.2.3)
+ set(${outName}
+ "${CMAKE_MATCH_1}"
+ PARENT_SCOPE
+ )
+ set(${outVer}
+ "${CMAKE_MATCH_2}"
+ PARENT_SCOPE
+ )
+ elseif(filename MATCHES "(([0-9]+\\.)+[0-9]+[a-zA-Z0-9]*)")
+ # We couldn't find a name, but we found a version
+ #
+ # In many cases (which we don't handle here) the url would look something like
+ # `irrelevant/ACTUAL_PACKAGE_NAME/irrelevant/1.2.3.zip`. In such a case we can't possibly
+ # distinguish the package name from the irrelevant bits. Moreover if we try to match the
+ # package name from the filename, we'd get bogus at best.
+ unset(${outName} PARENT_SCOPE)
+ set(${outVer}
+ "${CMAKE_MATCH_1}"
+ PARENT_SCOPE
+ )
+ else()
+ # Boldly assume that the file name is the package name.
+ #
+ # Yes, something like `irrelevant/ACTUAL_NAME/irrelevant/download.zip` will ruin our day, but
+ # such cases should be quite rare. No popular service does this... we think.
+ set(${outName}
+ "${filename}"
+ PARENT_SCOPE
+ )
+ unset(${outVer} PARENT_SCOPE)
+ endif()
+ else()
+ # No ideas yet what to do with non-archives
+ unset(${outName} PARENT_SCOPE)
+ unset(${outVer} PARENT_SCOPE)
+ endif()
+endfunction()
+
+function(cpm_find_package NAME VERSION)
+ string(REPLACE " " ";" EXTRA_ARGS "${ARGN}")
+ find_package(${NAME} ${VERSION} ${EXTRA_ARGS} QUIET)
+ if(${CPM_ARGS_NAME}_FOUND)
+ if(DEFINED ${CPM_ARGS_NAME}_VERSION)
+ set(VERSION ${${CPM_ARGS_NAME}_VERSION})
+ endif()
+ cpm_message(STATUS "${CPM_INDENT} Using local package ${CPM_ARGS_NAME}@${VERSION}")
+ CPMRegisterPackage(${CPM_ARGS_NAME} "${VERSION}")
+ set(CPM_PACKAGE_FOUND
+ YES
+ PARENT_SCOPE
+ )
+ else()
+ set(CPM_PACKAGE_FOUND
+ NO
+ PARENT_SCOPE
+ )
+ endif()
+endfunction()
+
+# Create a custom FindXXX.cmake module for a CPM package This prevents `find_package(NAME)` from
+# finding the system library
+function(cpm_create_module_file Name)
+ if(NOT CPM_DONT_UPDATE_MODULE_PATH)
+ if(DEFINED CMAKE_FIND_PACKAGE_REDIRECTS_DIR)
+ # Redirect find_package calls to the CPM package. This is what FetchContent does when you set
+ # OVERRIDE_FIND_PACKAGE. The CMAKE_FIND_PACKAGE_REDIRECTS_DIR works for find_package in CONFIG
+ # mode, unlike the Find${Name}.cmake fallback. CMAKE_FIND_PACKAGE_REDIRECTS_DIR is not defined
+ # in script mode, or in CMake < 3.24.
+ # https://cmake.org/cmake/help/latest/module/FetchContent.html#fetchcontent-find-package-integration-examples
+ string(TOLOWER ${Name} NameLower)
+ file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config.cmake
+ "include(\"\${CMAKE_CURRENT_LIST_DIR}/${NameLower}-extra.cmake\" OPTIONAL)\n"
+ "include(\"\${CMAKE_CURRENT_LIST_DIR}/${Name}Extra.cmake\" OPTIONAL)\n"
+ )
+ file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config-version.cmake
+ "set(PACKAGE_VERSION_COMPATIBLE TRUE)\n" "set(PACKAGE_VERSION_EXACT TRUE)\n"
+ )
+ else()
+ file(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake
+ "include(\"${CPM_FILE}\")\n${ARGN}\nset(${Name}_FOUND TRUE)"
+ )
+ endif()
+ endif()
+endfunction()
+
+# Find a package locally or fallback to CPMAddPackage
+function(CPMFindPackage)
+ set(oneValueArgs NAME VERSION GIT_TAG FIND_PACKAGE_ARGUMENTS)
+
+ cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "" ${ARGN})
+
+ if(NOT DEFINED CPM_ARGS_VERSION)
+ if(DEFINED CPM_ARGS_GIT_TAG)
+ cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)
+ endif()
+ endif()
+
+ set(downloadPackage ${CPM_DOWNLOAD_ALL})
+ if(DEFINED CPM_DOWNLOAD_${CPM_ARGS_NAME})
+ set(downloadPackage ${CPM_DOWNLOAD_${CPM_ARGS_NAME}})
+ elseif(DEFINED ENV{CPM_DOWNLOAD_${CPM_ARGS_NAME}})
+ set(downloadPackage $ENV{CPM_DOWNLOAD_${CPM_ARGS_NAME}})
+ endif()
+ if(downloadPackage)
+ CPMAddPackage(${ARGN})
+ cpm_export_variables(${CPM_ARGS_NAME})
+ return()
+ endif()
+
+ cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})
+
+ if(NOT CPM_PACKAGE_FOUND)
+ CPMAddPackage(${ARGN})
+ cpm_export_variables(${CPM_ARGS_NAME})
+ endif()
+
+endfunction()
+
+# checks if a package has been added before
+function(cpm_check_if_package_already_added CPM_ARGS_NAME CPM_ARGS_VERSION)
+ if("${CPM_ARGS_NAME}" IN_LIST CPM_PACKAGES)
+ CPMGetPackageVersion(${CPM_ARGS_NAME} CPM_PACKAGE_VERSION)
+ if("${CPM_PACKAGE_VERSION}" VERSION_LESS "${CPM_ARGS_VERSION}")
+ message(
+ WARNING
+ "${CPM_INDENT} Requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION})."
+ )
+ endif()
+ cpm_get_fetch_properties(${CPM_ARGS_NAME})
+ set(${CPM_ARGS_NAME}_ADDED NO)
+ set(CPM_PACKAGE_ALREADY_ADDED
+ YES
+ PARENT_SCOPE
+ )
+ cpm_export_variables(${CPM_ARGS_NAME})
+ else()
+ set(CPM_PACKAGE_ALREADY_ADDED
+ NO
+ PARENT_SCOPE
+ )
+ endif()
+endfunction()
+
+# Parse the argument of CPMAddPackage in case a single one was provided and convert it to a list of
+# arguments which can then be parsed idiomatically. For example gh:foo/bar at 1.2.3 will be converted
+# to: GITHUB_REPOSITORY;foo/bar;VERSION;1.2.3
+function(cpm_parse_add_package_single_arg arg outArgs)
+ # Look for a scheme
+ if("${arg}" MATCHES "^([a-zA-Z]+):(.+)$")
+ string(TOLOWER "${CMAKE_MATCH_1}" scheme)
+ set(uri "${CMAKE_MATCH_2}")
+
+ # Check for CPM-specific schemes
+ if(scheme STREQUAL "gh")
+ set(out "GITHUB_REPOSITORY;${uri}")
+ set(packageType "git")
+ elseif(scheme STREQUAL "gl")
+ set(out "GITLAB_REPOSITORY;${uri}")
+ set(packageType "git")
+ elseif(scheme STREQUAL "bb")
+ set(out "BITBUCKET_REPOSITORY;${uri}")
+ set(packageType "git")
+ # A CPM-specific scheme was not found. Looks like this is a generic URL so try to determine
+ # type
+ elseif(arg MATCHES ".git/?(@|#|$)")
+ set(out "GIT_REPOSITORY;${arg}")
+ set(packageType "git")
+ else()
+ # Fall back to a URL
+ set(out "URL;${arg}")
+ set(packageType "archive")
+
+ # We could also check for SVN since FetchContent supports it, but SVN is so rare these days.
+ # We just won't bother with the additional complexity it will induce in this function. SVN is
+ # done by multi-arg
+ endif()
+ else()
+ if(arg MATCHES ".git/?(@|#|$)")
+ set(out "GIT_REPOSITORY;${arg}")
+ set(packageType "git")
+ else()
+ # Give up
+ message(FATAL_ERROR "${CPM_INDENT} Can't determine package type of '${arg}'")
+ endif()
+ endif()
+
+ # For all packages we interpret @... as version. Only replace the last occurrence. Thus URIs
+ # containing '@' can be used
+ string(REGEX REPLACE "@([^@]+)$" ";VERSION;\\1" out "${out}")
+
+ # Parse the rest according to package type
+ if(packageType STREQUAL "git")
+ # For git repos we interpret #... as a tag or branch or commit hash
+ string(REGEX REPLACE "#([^#]+)$" ";GIT_TAG;\\1" out "${out}")
+ elseif(packageType STREQUAL "archive")
+ # For archives we interpret #... as a URL hash.
+ string(REGEX REPLACE "#([^#]+)$" ";URL_HASH;\\1" out "${out}")
+ # We don't try to parse the version if it's not provided explicitly. cpm_get_version_from_url
+ # should do this at a later point
+ else()
+ # We should never get here. This is an assertion and hitting it means there's a problem with the
+ # code above. A packageType was set, but not handled by this if-else.
+ message(FATAL_ERROR "${CPM_INDENT} Unsupported package type '${packageType}' of '${arg}'")
+ endif()
+
+ set(${outArgs}
+ ${out}
+ PARENT_SCOPE
+ )
+endfunction()
+
+# Check that the working directory for a git repo is clean
+function(cpm_check_git_working_dir_is_clean repoPath gitTag isClean)
+
+ find_package(Git REQUIRED)
+
+ if(NOT GIT_EXECUTABLE)
+ # No git executable, assume directory is clean
+ set(${isClean}
+ TRUE
+ PARENT_SCOPE
+ )
+ return()
+ endif()
+
+ # check for uncommitted changes
+ execute_process(
+ COMMAND ${GIT_EXECUTABLE} status --porcelain
+ RESULT_VARIABLE resultGitStatus
+ OUTPUT_VARIABLE repoStatus
+ OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
+ WORKING_DIRECTORY ${repoPath}
+ )
+ if(resultGitStatus)
+ # not supposed to happen, assume clean anyway
+ message(WARNING "${CPM_INDENT} Calling git status on folder ${repoPath} failed")
+ set(${isClean}
+ TRUE
+ PARENT_SCOPE
+ )
+ return()
+ endif()
+
+ if(NOT "${repoStatus}" STREQUAL "")
+ set(${isClean}
+ FALSE
+ PARENT_SCOPE
+ )
+ return()
+ endif()
+
+ # check for committed changes
+ execute_process(
+ COMMAND ${GIT_EXECUTABLE} diff -s --exit-code ${gitTag}
+ RESULT_VARIABLE resultGitDiff
+ OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_QUIET
+ WORKING_DIRECTORY ${repoPath}
+ )
+
+ if(${resultGitDiff} EQUAL 0)
+ set(${isClean}
+ TRUE
+ PARENT_SCOPE
+ )
+ else()
+ set(${isClean}
+ FALSE
+ PARENT_SCOPE
+ )
+ endif()
+
+endfunction()
+
+# Add PATCH_COMMAND to CPM_ARGS_UNPARSED_ARGUMENTS. This method consumes a list of files in ARGN
+# then generates a `PATCH_COMMAND` appropriate for `ExternalProject_Add()`. This command is appended
+# to the parent scope's `CPM_ARGS_UNPARSED_ARGUMENTS`.
+function(cpm_add_patches)
+ # Return if no patch files are supplied.
+ if(NOT ARGN)
+ return()
+ endif()
+
+ # Find the patch program.
+ find_program(PATCH_EXECUTABLE patch)
+ if(CMAKE_HOST_WIN32 AND NOT PATCH_EXECUTABLE)
+ # The Windows git executable is distributed with patch.exe. Find the path to the executable, if
+ # it exists, then search `../usr/bin` and `../../usr/bin` for patch.exe.
+ find_package(Git QUIET)
+ if(GIT_EXECUTABLE)
+ get_filename_component(extra_search_path ${GIT_EXECUTABLE} DIRECTORY)
+ get_filename_component(extra_search_path_1up ${extra_search_path} DIRECTORY)
+ get_filename_component(extra_search_path_2up ${extra_search_path_1up} DIRECTORY)
+ find_program(
+ PATCH_EXECUTABLE patch HINTS "${extra_search_path_1up}/usr/bin"
+ "${extra_search_path_2up}/usr/bin"
+ )
+ endif()
+ endif()
+ if(NOT PATCH_EXECUTABLE)
+ message(FATAL_ERROR "Couldn't find `patch` executable to use with PATCHES keyword.")
+ endif()
+
+ # Create a temporary
+ set(temp_list ${CPM_ARGS_UNPARSED_ARGUMENTS})
+
+ # Ensure each file exists (or error out) and add it to the list.
+ set(first_item True)
+ foreach(PATCH_FILE ${ARGN})
+ # Make sure the patch file exists, if we can't find it, try again in the current directory.
+ if(NOT EXISTS "${PATCH_FILE}")
+ if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/${PATCH_FILE}")
+ message(FATAL_ERROR "Couldn't find patch file: '${PATCH_FILE}'")
+ endif()
+ set(PATCH_FILE "${CMAKE_CURRENT_LIST_DIR}/${PATCH_FILE}")
+ endif()
+
+ # Convert to absolute path for use with patch file command.
+ get_filename_component(PATCH_FILE "${PATCH_FILE}" ABSOLUTE)
+
+ # The first patch entry must be preceded by "PATCH_COMMAND" while the following items are
+ # preceded by "&&".
+ if(first_item)
+ set(first_item False)
+ list(APPEND temp_list "PATCH_COMMAND")
+ else()
+ list(APPEND temp_list "&&")
+ endif()
+ # Add the patch command to the list
+ list(APPEND temp_list "${PATCH_EXECUTABLE}" "-p1" "<" "${PATCH_FILE}")
+ endforeach()
+
+ # Move temp out into parent scope.
+ set(CPM_ARGS_UNPARSED_ARGUMENTS
+ ${temp_list}
+ PARENT_SCOPE
+ )
+
+endfunction()
+
+# method to overwrite internal FetchContent properties, to allow using CPM.cmake to overload
+# FetchContent calls. As these are internal cmake properties, this method should be used carefully
+# and may need modification in future CMake versions. Source:
+# https://github.com/Kitware/CMake/blob/dc3d0b5a0a7d26d43d6cfeb511e224533b5d188f/Modules/FetchContent.cmake#L1152
+function(cpm_override_fetchcontent contentName)
+ cmake_parse_arguments(PARSE_ARGV 1 arg "" "SOURCE_DIR;BINARY_DIR" "")
+ if(NOT "${arg_UNPARSED_ARGUMENTS}" STREQUAL "")
+ message(FATAL_ERROR "${CPM_INDENT} Unsupported arguments: ${arg_UNPARSED_ARGUMENTS}")
+ endif()
+
+ string(TOLOWER ${contentName} contentNameLower)
+ set(prefix "_FetchContent_${contentNameLower}")
+
+ set(propertyName "${prefix}_sourceDir")
+ define_property(
+ GLOBAL
+ PROPERTY ${propertyName}
+ BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
+ FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
+ )
+ set_property(GLOBAL PROPERTY ${propertyName} "${arg_SOURCE_DIR}")
+
+ set(propertyName "${prefix}_binaryDir")
+ define_property(
+ GLOBAL
+ PROPERTY ${propertyName}
+ BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
+ FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
+ )
+ set_property(GLOBAL PROPERTY ${propertyName} "${arg_BINARY_DIR}")
+
+ set(propertyName "${prefix}_populated")
+ define_property(
+ GLOBAL
+ PROPERTY ${propertyName}
+ BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
+ FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
+ )
+ set_property(GLOBAL PROPERTY ${propertyName} TRUE)
+endfunction()
+
+# Download and add a package from source
+function(CPMAddPackage)
+ cpm_set_policies()
+
+ list(LENGTH ARGN argnLength)
+ if(argnLength EQUAL 1)
+ cpm_parse_add_package_single_arg("${ARGN}" ARGN)
+
+ # The shorthand syntax implies EXCLUDE_FROM_ALL and SYSTEM
+ set(ARGN "${ARGN};EXCLUDE_FROM_ALL;YES;SYSTEM;YES;")
+ endif()
+
+ set(oneValueArgs
+ NAME
+ FORCE
+ VERSION
+ GIT_TAG
+ DOWNLOAD_ONLY
+ GITHUB_REPOSITORY
+ GITLAB_REPOSITORY
+ BITBUCKET_REPOSITORY
+ GIT_REPOSITORY
+ SOURCE_DIR
+ FIND_PACKAGE_ARGUMENTS
+ NO_CACHE
+ SYSTEM
+ GIT_SHALLOW
+ EXCLUDE_FROM_ALL
+ SOURCE_SUBDIR
+ CUSTOM_CACHE_KEY
+ )
+
+ set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND PATCHES)
+
+ cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
+
+ # Set default values for arguments
+
+ if(NOT DEFINED CPM_ARGS_VERSION)
+ if(DEFINED CPM_ARGS_GIT_TAG)
+ cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)
+ endif()
+ endif()
+
+ if(CPM_ARGS_DOWNLOAD_ONLY)
+ set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY})
+ else()
+ set(DOWNLOAD_ONLY NO)
+ endif()
+
+ if(DEFINED CPM_ARGS_GITHUB_REPOSITORY)
+ set(CPM_ARGS_GIT_REPOSITORY "https://github.com/${CPM_ARGS_GITHUB_REPOSITORY}.git")
+ elseif(DEFINED CPM_ARGS_GITLAB_REPOSITORY)
+ set(CPM_ARGS_GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITLAB_REPOSITORY}.git")
+ elseif(DEFINED CPM_ARGS_BITBUCKET_REPOSITORY)
+ set(CPM_ARGS_GIT_REPOSITORY "https://bitbucket.org/${CPM_ARGS_BITBUCKET_REPOSITORY}.git")
+ endif()
+
+ if(DEFINED CPM_ARGS_GIT_REPOSITORY)
+ list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY ${CPM_ARGS_GIT_REPOSITORY})
+ if(NOT DEFINED CPM_ARGS_GIT_TAG)
+ set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
+ endif()
+
+ # If a name wasn't provided, try to infer it from the git repo
+ if(NOT DEFINED CPM_ARGS_NAME)
+ cpm_package_name_from_git_uri(${CPM_ARGS_GIT_REPOSITORY} CPM_ARGS_NAME)
+ endif()
+ endif()
+
+ set(CPM_SKIP_FETCH FALSE)
+
+ if(DEFINED CPM_ARGS_GIT_TAG)
+ list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG})
+ # If GIT_SHALLOW is explicitly specified, honor the value.
+ if(DEFINED CPM_ARGS_GIT_SHALLOW)
+ list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SHALLOW ${CPM_ARGS_GIT_SHALLOW})
+ endif()
+ endif()
+
+ if(DEFINED CPM_ARGS_URL)
+ # If a name or version aren't provided, try to infer them from the URL
+ list(GET CPM_ARGS_URL 0 firstUrl)
+ cpm_package_name_and_ver_from_url(${firstUrl} nameFromUrl verFromUrl)
+ # If we fail to obtain name and version from the first URL, we could try other URLs if any.
+ # However multiple URLs are expected to be quite rare, so for now we won't bother.
+
+ # If the caller provided their own name and version, they trump the inferred ones.
+ if(NOT DEFINED CPM_ARGS_NAME)
+ set(CPM_ARGS_NAME ${nameFromUrl})
+ endif()
+ if(NOT DEFINED CPM_ARGS_VERSION)
+ set(CPM_ARGS_VERSION ${verFromUrl})
+ endif()
+
+ list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS URL "${CPM_ARGS_URL}")
+ endif()
+
+ # Check for required arguments
+
+ if(NOT DEFINED CPM_ARGS_NAME)
+ message(
+ FATAL_ERROR
+ "${CPM_INDENT} 'NAME' was not provided and couldn't be automatically inferred for package added with arguments: '${ARGN}'"
+ )
+ endif()
+
+ # Check if package has been added before
+ cpm_check_if_package_already_added(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}")
+ if(CPM_PACKAGE_ALREADY_ADDED)
+ cpm_export_variables(${CPM_ARGS_NAME})
+ return()
+ endif()
+
+ # Check for manual overrides
+ if(NOT CPM_ARGS_FORCE AND NOT "${CPM_${CPM_ARGS_NAME}_SOURCE}" STREQUAL "")
+ set(PACKAGE_SOURCE ${CPM_${CPM_ARGS_NAME}_SOURCE})
+ set(CPM_${CPM_ARGS_NAME}_SOURCE "")
+ CPMAddPackage(
+ NAME "${CPM_ARGS_NAME}"
+ SOURCE_DIR "${PACKAGE_SOURCE}"
+ EXCLUDE_FROM_ALL "${CPM_ARGS_EXCLUDE_FROM_ALL}"
+ SYSTEM "${CPM_ARGS_SYSTEM}"
+ PATCHES "${CPM_ARGS_PATCHES}"
+ OPTIONS "${CPM_ARGS_OPTIONS}"
+ SOURCE_SUBDIR "${CPM_ARGS_SOURCE_SUBDIR}"
+ DOWNLOAD_ONLY "${DOWNLOAD_ONLY}"
+ FORCE True
+ )
+ cpm_export_variables(${CPM_ARGS_NAME})
+ return()
+ endif()
+
+ # Check for available declaration
+ if(NOT CPM_ARGS_FORCE AND NOT "${CPM_DECLARATION_${CPM_ARGS_NAME}}" STREQUAL "")
+ set(declaration ${CPM_DECLARATION_${CPM_ARGS_NAME}})
+ set(CPM_DECLARATION_${CPM_ARGS_NAME} "")
+ CPMAddPackage(${declaration})
+ cpm_export_variables(${CPM_ARGS_NAME})
+ # checking again to ensure version and option compatibility
+ cpm_check_if_package_already_added(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}")
+ return()
+ endif()
+
+ if(NOT CPM_ARGS_FORCE)
+ if(CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY)
+ cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})
+
+ if(CPM_PACKAGE_FOUND)
+ cpm_export_variables(${CPM_ARGS_NAME})
+ return()
+ endif()
+
+ if(CPM_LOCAL_PACKAGES_ONLY)
+ message(
+ SEND_ERROR
+ "${CPM_INDENT} ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})"
+ )
+ endif()
+ endif()
+ endif()
+
+ CPMRegisterPackage("${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}")
+
+ if(DEFINED CPM_ARGS_GIT_TAG)
+ set(PACKAGE_INFO "${CPM_ARGS_GIT_TAG}")
+ elseif(DEFINED CPM_ARGS_SOURCE_DIR)
+ set(PACKAGE_INFO "${CPM_ARGS_SOURCE_DIR}")
+ else()
+ set(PACKAGE_INFO "${CPM_ARGS_VERSION}")
+ endif()
+
+ if(DEFINED FETCHCONTENT_BASE_DIR)
+ # respect user's FETCHCONTENT_BASE_DIR if set
+ set(CPM_FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR})
+ else()
+ set(CPM_FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/_deps)
+ endif()
+
+ cpm_add_patches(${CPM_ARGS_PATCHES})
+
+ if(DEFINED CPM_ARGS_DOWNLOAD_COMMAND)
+ list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND})
+ elseif(DEFINED CPM_ARGS_SOURCE_DIR)
+ list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${CPM_ARGS_SOURCE_DIR})
+ if(NOT IS_ABSOLUTE ${CPM_ARGS_SOURCE_DIR})
+ # Expand `CPM_ARGS_SOURCE_DIR` relative path. This is important because EXISTS doesn't work
+ # for relative paths.
+ get_filename_component(
+ source_directory ${CPM_ARGS_SOURCE_DIR} REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}
+ )
+ else()
+ set(source_directory ${CPM_ARGS_SOURCE_DIR})
+ endif()
+ if(NOT EXISTS ${source_directory})
+ string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
+ # remove timestamps so CMake will re-download the dependency
+ file(REMOVE_RECURSE "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild")
+ endif()
+ elseif(CPM_SOURCE_CACHE AND NOT CPM_ARGS_NO_CACHE)
+ string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
+ set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
+ list(SORT origin_parameters)
+ if(CPM_ARGS_CUSTOM_CACHE_KEY)
+ # Application set a custom unique directory name
+ set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${CPM_ARGS_CUSTOM_CACHE_KEY})
+ elseif(CPM_USE_NAMED_CACHE_DIRECTORIES)
+ string(SHA1 origin_hash "${origin_parameters};NEW_CACHE_STRUCTURE_TAG")
+ set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash}/${CPM_ARGS_NAME})
+ else()
+ string(SHA1 origin_hash "${origin_parameters}")
+ set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
+ endif()
+ # Expand `download_directory` relative path. This is important because EXISTS doesn't work for
+ # relative paths.
+ get_filename_component(download_directory ${download_directory} ABSOLUTE)
+ list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory})
+
+ if(CPM_SOURCE_CACHE)
+ file(LOCK ${download_directory}/../cmake.lock)
+ endif()
+
+ if(EXISTS ${download_directory})
+ if(CPM_SOURCE_CACHE)
+ file(LOCK ${download_directory}/../cmake.lock RELEASE)
+ endif()
+
+ cpm_store_fetch_properties(
+ ${CPM_ARGS_NAME} "${download_directory}"
+ "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build"
+ )
+ cpm_get_fetch_properties("${CPM_ARGS_NAME}")
+
+ if(DEFINED CPM_ARGS_GIT_TAG AND NOT (PATCH_COMMAND IN_LIST CPM_ARGS_UNPARSED_ARGUMENTS))
+ # warn if cache has been changed since checkout
+ cpm_check_git_working_dir_is_clean(${download_directory} ${CPM_ARGS_GIT_TAG} IS_CLEAN)
+ if(NOT ${IS_CLEAN})
+ message(
+ WARNING "${CPM_INDENT} Cache for ${CPM_ARGS_NAME} (${download_directory}) is dirty"
+ )
+ endif()
+ endif()
+
+ cpm_add_subdirectory(
+ "${CPM_ARGS_NAME}"
+ "${DOWNLOAD_ONLY}"
+ "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}"
+ "${${CPM_ARGS_NAME}_BINARY_DIR}"
+ "${CPM_ARGS_EXCLUDE_FROM_ALL}"
+ "${CPM_ARGS_SYSTEM}"
+ "${CPM_ARGS_OPTIONS}"
+ )
+ set(PACKAGE_INFO "${PACKAGE_INFO} at ${download_directory}")
+
+ # As the source dir is already cached/populated, we override the call to FetchContent.
+ set(CPM_SKIP_FETCH TRUE)
+ cpm_override_fetchcontent(
+ "${lower_case_name}" SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}"
+ BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}"
+ )
+
+ else()
+ # Enable shallow clone when GIT_TAG is not a commit hash. Our guess may not be accurate, but
+ # it should guarantee no commit hash get mis-detected.
+ if(NOT DEFINED CPM_ARGS_GIT_SHALLOW)
+ cpm_is_git_tag_commit_hash("${CPM_ARGS_GIT_TAG}" IS_HASH)
+ if(NOT ${IS_HASH})
+ list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SHALLOW TRUE)
+ endif()
+ endif()
+
+ # remove timestamps so CMake will re-download the dependency
+ file(REMOVE_RECURSE ${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild)
+ set(PACKAGE_INFO "${PACKAGE_INFO} to ${download_directory}")
+ endif()
+ endif()
+
+ if(NOT "${DOWNLOAD_ONLY}")
+ cpm_create_module_file(${CPM_ARGS_NAME} "CPMAddPackage(\"${ARGN}\")")
+ endif()
+
+ if(CPM_PACKAGE_LOCK_ENABLED)
+ if((CPM_ARGS_VERSION AND NOT CPM_ARGS_SOURCE_DIR) OR CPM_INCLUDE_ALL_IN_PACKAGE_LOCK)
+ cpm_add_to_package_lock(${CPM_ARGS_NAME} "${ARGN}")
+ elseif(CPM_ARGS_SOURCE_DIR)
+ cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "local directory")
+ else()
+ cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "${ARGN}")
+ endif()
+ endif()
+
+ cpm_message(
+ STATUS "${CPM_INDENT} Adding package ${CPM_ARGS_NAME}@${CPM_ARGS_VERSION} (${PACKAGE_INFO})"
+ )
+
+ if(NOT CPM_SKIP_FETCH)
+ # CMake 3.28 added EXCLUDE, SYSTEM (3.25), and SOURCE_SUBDIR (3.18) to FetchContent_Declare.
+ # Calling FetchContent_MakeAvailable will then internally forward these options to
+ # add_subdirectory. Up until these changes, we had to call FetchContent_Populate and
+ # add_subdirectory separately, which is no longer necessary and has been deprecated as of 3.30.
+ # A Bug in CMake prevents us to use the non-deprecated functions until 3.30.3.
+ set(fetchContentDeclareExtraArgs "")
+ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30.3")
+ if(${CPM_ARGS_EXCLUDE_FROM_ALL})
+ list(APPEND fetchContentDeclareExtraArgs EXCLUDE_FROM_ALL)
+ endif()
+ if(${CPM_ARGS_SYSTEM})
+ list(APPEND fetchContentDeclareExtraArgs SYSTEM)
+ endif()
+ if(DEFINED CPM_ARGS_SOURCE_SUBDIR)
+ list(APPEND fetchContentDeclareExtraArgs SOURCE_SUBDIR ${CPM_ARGS_SOURCE_SUBDIR})
+ endif()
+ # For CMake version <3.28 OPTIONS are parsed in cpm_add_subdirectory
+ if(CPM_ARGS_OPTIONS AND NOT DOWNLOAD_ONLY)
+ foreach(OPTION ${CPM_ARGS_OPTIONS})
+ cpm_parse_option("${OPTION}")
+ set(${OPTION_KEY} "${OPTION_VALUE}")
+ endforeach()
+ endif()
+ endif()
+ cpm_declare_fetch(
+ "${CPM_ARGS_NAME}" ${fetchContentDeclareExtraArgs} "${CPM_ARGS_UNPARSED_ARGUMENTS}"
+ )
+
+ cpm_fetch_package("${CPM_ARGS_NAME}" ${DOWNLOAD_ONLY} populated ${CPM_ARGS_UNPARSED_ARGUMENTS})
+ if(CPM_SOURCE_CACHE AND download_directory)
+ file(LOCK ${download_directory}/../cmake.lock RELEASE)
+ endif()
+ if(${populated} AND ${CMAKE_VERSION} VERSION_LESS "3.30.3")
+ cpm_add_subdirectory(
+ "${CPM_ARGS_NAME}"
+ "${DOWNLOAD_ONLY}"
+ "${${CPM_ARGS_NAME}_SOURCE_DIR}/${CPM_ARGS_SOURCE_SUBDIR}"
+ "${${CPM_ARGS_NAME}_BINARY_DIR}"
+ "${CPM_ARGS_EXCLUDE_FROM_ALL}"
+ "${CPM_ARGS_SYSTEM}"
+ "${CPM_ARGS_OPTIONS}"
+ )
+ endif()
+ cpm_get_fetch_properties("${CPM_ARGS_NAME}")
+ endif()
+
+ set(${CPM_ARGS_NAME}_ADDED YES)
+ cpm_export_variables("${CPM_ARGS_NAME}")
+endfunction()
+
+# Fetch a previously declared package
+macro(CPMGetPackage Name)
+ if(DEFINED "CPM_DECLARATION_${Name}")
+ CPMAddPackage(NAME ${Name})
+ else()
+ message(SEND_ERROR "${CPM_INDENT} Cannot retrieve package ${Name}: no declaration available")
+ endif()
+endmacro()
+
+# export variables available to the caller to the parent scope expects ${CPM_ARGS_NAME} to be set
+macro(cpm_export_variables name)
+ set(${name}_SOURCE_DIR
+ "${${name}_SOURCE_DIR}"
+ PARENT_SCOPE
+ )
+ set(${name}_BINARY_DIR
+ "${${name}_BINARY_DIR}"
+ PARENT_SCOPE
+ )
+ set(${name}_ADDED
+ "${${name}_ADDED}"
+ PARENT_SCOPE
+ )
+ set(CPM_LAST_PACKAGE_NAME
+ "${name}"
+ PARENT_SCOPE
+ )
+endmacro()
+
+# declares a package, so that any call to CPMAddPackage for the package name will use these
+# arguments instead. Previous declarations will not be overridden.
+macro(CPMDeclarePackage Name)
+ if(NOT DEFINED "CPM_DECLARATION_${Name}")
+ set("CPM_DECLARATION_${Name}" "${ARGN}")
+ endif()
+endmacro()
+
+function(cpm_add_to_package_lock Name)
+ if(NOT CPM_DONT_CREATE_PACKAGE_LOCK)
+ cpm_prettify_package_arguments(PRETTY_ARGN false ${ARGN})
+ file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name}\nCPMDeclarePackage(${Name}\n${PRETTY_ARGN})\n")
+ endif()
+endfunction()
+
+function(cpm_add_comment_to_package_lock Name)
+ if(NOT CPM_DONT_CREATE_PACKAGE_LOCK)
+ cpm_prettify_package_arguments(PRETTY_ARGN true ${ARGN})
+ file(APPEND ${CPM_PACKAGE_LOCK_FILE}
+ "# ${Name} (unversioned)\n# CPMDeclarePackage(${Name}\n${PRETTY_ARGN}#)\n"
+ )
+ endif()
+endfunction()
+
+# includes the package lock file if it exists and creates a target `cpm-update-package-lock` to
+# update it
+macro(CPMUsePackageLock file)
+ if(NOT CPM_DONT_CREATE_PACKAGE_LOCK)
+ get_filename_component(CPM_ABSOLUTE_PACKAGE_LOCK_PATH ${file} ABSOLUTE)
+ if(EXISTS ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
+ include(${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
+ endif()
+ if(NOT TARGET cpm-update-package-lock)
+ add_custom_target(
+ cpm-update-package-lock COMMAND ${CMAKE_COMMAND} -E copy ${CPM_PACKAGE_LOCK_FILE}
+ ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH}
+ )
+ endif()
+ set(CPM_PACKAGE_LOCK_ENABLED true)
+ endif()
+endmacro()
+
+# registers a package that has been added to CPM
+function(CPMRegisterPackage PACKAGE VERSION)
+ list(APPEND CPM_PACKAGES ${PACKAGE})
+ set(CPM_PACKAGES
+ ${CPM_PACKAGES}
+ CACHE INTERNAL ""
+ )
+ set("CPM_PACKAGE_${PACKAGE}_VERSION"
+ ${VERSION}
+ CACHE INTERNAL ""
+ )
+endfunction()
+
+# retrieve the current version of the package to ${OUTPUT}
+function(CPMGetPackageVersion PACKAGE OUTPUT)
+ set(${OUTPUT}
+ "${CPM_PACKAGE_${PACKAGE}_VERSION}"
+ PARENT_SCOPE
+ )
+endfunction()
+
+# declares a package in FetchContent_Declare
+function(cpm_declare_fetch PACKAGE)
+ if(${CPM_DRY_RUN})
+ cpm_message(STATUS "${CPM_INDENT} Package not declared (dry run)")
+ return()
+ endif()
+
+ FetchContent_Declare(${PACKAGE} ${ARGN})
+endfunction()
+
+# returns properties for a package previously defined by cpm_declare_fetch
+function(cpm_get_fetch_properties PACKAGE)
+ if(${CPM_DRY_RUN})
+ return()
+ endif()
+
+ set(${PACKAGE}_SOURCE_DIR
+ "${CPM_PACKAGE_${PACKAGE}_SOURCE_DIR}"
+ PARENT_SCOPE
+ )
+ set(${PACKAGE}_BINARY_DIR
+ "${CPM_PACKAGE_${PACKAGE}_BINARY_DIR}"
+ PARENT_SCOPE
+ )
+endfunction()
+
+function(cpm_store_fetch_properties PACKAGE source_dir binary_dir)
+ if(${CPM_DRY_RUN})
+ return()
+ endif()
+
+ set(CPM_PACKAGE_${PACKAGE}_SOURCE_DIR
+ "${source_dir}"
+ CACHE INTERNAL ""
+ )
+ set(CPM_PACKAGE_${PACKAGE}_BINARY_DIR
+ "${binary_dir}"
+ CACHE INTERNAL ""
+ )
+endfunction()
+
+# adds a package as a subdirectory if viable, according to provided options
+function(
+ cpm_add_subdirectory
+ PACKAGE
+ DOWNLOAD_ONLY
+ SOURCE_DIR
+ BINARY_DIR
+ EXCLUDE
+ SYSTEM
+ OPTIONS
+)
+
+ if(NOT DOWNLOAD_ONLY AND EXISTS ${SOURCE_DIR}/CMakeLists.txt)
+ set(addSubdirectoryExtraArgs "")
+ if(EXCLUDE)
+ list(APPEND addSubdirectoryExtraArgs EXCLUDE_FROM_ALL)
+ endif()
+ if("${SYSTEM}" AND "${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.25")
+ # https://cmake.org/cmake/help/latest/prop_dir/SYSTEM.html#prop_dir:SYSTEM
+ list(APPEND addSubdirectoryExtraArgs SYSTEM)
+ endif()
+ if(OPTIONS)
+ foreach(OPTION ${OPTIONS})
+ cpm_parse_option("${OPTION}")
+ set(${OPTION_KEY} "${OPTION_VALUE}")
+ endforeach()
+ endif()
+ set(CPM_OLD_INDENT "${CPM_INDENT}")
+ set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
+ add_subdirectory(${SOURCE_DIR} ${BINARY_DIR} ${addSubdirectoryExtraArgs})
+ set(CPM_INDENT "${CPM_OLD_INDENT}")
+ endif()
+endfunction()
+
+# downloads a previously declared package via FetchContent and exports the variables
+# `${PACKAGE}_SOURCE_DIR` and `${PACKAGE}_BINARY_DIR` to the parent scope
+function(cpm_fetch_package PACKAGE DOWNLOAD_ONLY populated)
+ set(${populated}
+ FALSE
+ PARENT_SCOPE
+ )
+ if(${CPM_DRY_RUN})
+ cpm_message(STATUS "${CPM_INDENT} Package ${PACKAGE} not fetched (dry run)")
+ return()
+ endif()
+
+ FetchContent_GetProperties(${PACKAGE})
+
+ string(TOLOWER "${PACKAGE}" lower_case_name)
+
+ if(NOT ${lower_case_name}_POPULATED)
+ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.30.3")
+ if(DOWNLOAD_ONLY)
+ # MakeAvailable will call add_subdirectory internally which is not what we want when
+ # DOWNLOAD_ONLY is set. Populate will only download the dependency without adding it to the
+ # build
+ FetchContent_Populate(
+ ${PACKAGE}
+ SOURCE_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-src"
+ BINARY_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build"
+ SUBBUILD_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild"
+ ${ARGN}
+ )
+ else()
+ FetchContent_MakeAvailable(${PACKAGE})
+ endif()
+ else()
+ FetchContent_Populate(${PACKAGE})
+ endif()
+ set(${populated}
+ TRUE
+ PARENT_SCOPE
+ )
+ endif()
+
+ cpm_store_fetch_properties(
+ ${CPM_ARGS_NAME} ${${lower_case_name}_SOURCE_DIR} ${${lower_case_name}_BINARY_DIR}
+ )
+
+ set(${PACKAGE}_SOURCE_DIR
+ ${${lower_case_name}_SOURCE_DIR}
+ PARENT_SCOPE
+ )
+ set(${PACKAGE}_BINARY_DIR
+ ${${lower_case_name}_BINARY_DIR}
+ PARENT_SCOPE
+ )
+endfunction()
+
+# splits a package option
+function(cpm_parse_option OPTION)
+ string(REGEX MATCH "^[^ ]+" OPTION_KEY "${OPTION}")
+ string(LENGTH "${OPTION}" OPTION_LENGTH)
+ string(LENGTH "${OPTION_KEY}" OPTION_KEY_LENGTH)
+ if(OPTION_KEY_LENGTH STREQUAL OPTION_LENGTH)
+ # no value for key provided, assume user wants to set option to "ON"
+ set(OPTION_VALUE "ON")
+ else()
+ math(EXPR OPTION_KEY_LENGTH "${OPTION_KEY_LENGTH}+1")
+ string(SUBSTRING "${OPTION}" "${OPTION_KEY_LENGTH}" "-1" OPTION_VALUE)
+ endif()
+ set(OPTION_KEY
+ "${OPTION_KEY}"
+ PARENT_SCOPE
+ )
+ set(OPTION_VALUE
+ "${OPTION_VALUE}"
+ PARENT_SCOPE
+ )
+endfunction()
+
+# guesses the package version from a git tag
+function(cpm_get_version_from_git_tag GIT_TAG RESULT)
+ string(LENGTH ${GIT_TAG} length)
+ if(length EQUAL 40)
+ # GIT_TAG is probably a git hash
+ set(${RESULT}
+ 0
+ PARENT_SCOPE
+ )
+ else()
+ string(REGEX MATCH "v?([0123456789.]*).*" _ ${GIT_TAG})
+ set(${RESULT}
+ ${CMAKE_MATCH_1}
+ PARENT_SCOPE
+ )
+ endif()
+endfunction()
+
+# guesses if the git tag is a commit hash or an actual tag or a branch name.
+function(cpm_is_git_tag_commit_hash GIT_TAG RESULT)
+ string(LENGTH "${GIT_TAG}" length)
+ # full hash has 40 characters, and short hash has at least 7 characters.
+ if(length LESS 7 OR length GREATER 40)
+ set(${RESULT}
+ 0
+ PARENT_SCOPE
+ )
+ else()
+ if(${GIT_TAG} MATCHES "^[a-fA-F0-9]+$")
+ set(${RESULT}
+ 1
+ PARENT_SCOPE
+ )
+ else()
+ set(${RESULT}
+ 0
+ PARENT_SCOPE
+ )
+ endif()
+ endif()
+endfunction()
+
+function(cpm_prettify_package_arguments OUT_VAR IS_IN_COMMENT)
+ set(oneValueArgs
+ NAME
+ FORCE
+ VERSION
+ GIT_TAG
+ DOWNLOAD_ONLY
+ GITHUB_REPOSITORY
+ GITLAB_REPOSITORY
+ BITBUCKET_REPOSITORY
+ GIT_REPOSITORY
+ SOURCE_DIR
+ FIND_PACKAGE_ARGUMENTS
+ NO_CACHE
+ SYSTEM
+ GIT_SHALLOW
+ EXCLUDE_FROM_ALL
+ SOURCE_SUBDIR
+ )
+ set(multiValueArgs URL OPTIONS DOWNLOAD_COMMAND)
+ cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ foreach(oneArgName ${oneValueArgs})
+ if(DEFINED CPM_ARGS_${oneArgName})
+ if(${IS_IN_COMMENT})
+ string(APPEND PRETTY_OUT_VAR "#")
+ endif()
+ if(${oneArgName} STREQUAL "SOURCE_DIR")
+ string(REPLACE ${CMAKE_SOURCE_DIR} "\${CMAKE_SOURCE_DIR}" CPM_ARGS_${oneArgName}
+ ${CPM_ARGS_${oneArgName}}
+ )
+ endif()
+ string(APPEND PRETTY_OUT_VAR " ${oneArgName} ${CPM_ARGS_${oneArgName}}\n")
+ endif()
+ endforeach()
+ foreach(multiArgName ${multiValueArgs})
+ if(DEFINED CPM_ARGS_${multiArgName})
+ if(${IS_IN_COMMENT})
+ string(APPEND PRETTY_OUT_VAR "#")
+ endif()
+ string(APPEND PRETTY_OUT_VAR " ${multiArgName}\n")
+ foreach(singleOption ${CPM_ARGS_${multiArgName}})
+ if(${IS_IN_COMMENT})
+ string(APPEND PRETTY_OUT_VAR "#")
+ endif()
+ string(APPEND PRETTY_OUT_VAR " \"${singleOption}\"\n")
+ endforeach()
+ endif()
+ endforeach()
+
+ if(NOT "${CPM_ARGS_UNPARSED_ARGUMENTS}" STREQUAL "")
+ if(${IS_IN_COMMENT})
+ string(APPEND PRETTY_OUT_VAR "#")
+ endif()
+ string(APPEND PRETTY_OUT_VAR " ")
+ foreach(CPM_ARGS_UNPARSED_ARGUMENT ${CPM_ARGS_UNPARSED_ARGUMENTS})
+ string(APPEND PRETTY_OUT_VAR " ${CPM_ARGS_UNPARSED_ARGUMENT}")
+ endforeach()
+ string(APPEND PRETTY_OUT_VAR "\n")
+ endif()
+
+ set(${OUT_VAR}
+ ${PRETTY_OUT_VAR}
+ PARENT_SCOPE
+ )
+
+endfunction()
=====================================
cmake/libmcfpConfig.cmake.in deleted
=====================================
@@ -1,11 +0,0 @@
- at PACKAGE_INIT@
-
-INCLUDE("${CMAKE_CURRENT_LIST_DIR}/libmcfpTargets.cmake")
-
-check_required_components(libmcfp)
-
-message(WARNING "Using find_package(libmcfp) is deprecated, please use find_package(mcfp) instead")
-
-# and add an alias
-add_library(libmcfp::libmcfp ALIAS libmcfp::mcfp)
-
=====================================
cmake/test-charconv.cpp
=====================================
@@ -0,0 +1,17 @@
+#include <charconv>
+#include <cassert>
+#include <cstring>
+
+int main()
+{
+ float v;
+ char s[] = "1.0";
+
+ auto r = std::from_chars(s, s + strlen(s), v);
+
+ assert(r.ec == std::errc{});
+ assert(r.ptr = s + strlen(s));
+ assert(v == 1.0f);
+
+ return 0;
+}
\ No newline at end of file
=====================================
debian/changelog
=====================================
@@ -1,3 +1,9 @@
+libmcfp (1.4.2-1) unstable; urgency=medium
+
+ * New upstream version 1.4.2
+
+ -- Maarten L. Hekkelman <maarten at hekkelman.com> Mon, 26 May 2025 10:39:21 +0200
+
libmcfp (1.3.5-2) unstable; urgency=medium
* changing type to all was not such a good idea after all
=====================================
debian/rules
=====================================
@@ -11,4 +11,4 @@ export LC_ALL
dh $@
override_dh_auto_configure:
- dh_auto_configure -- -DENABLE_TESTING=ON
+ dh_auto_configure -- -DENABLE_TESTING=ON -DCPM_USE_LOCAL_PACKAGES=ON
=====================================
docs/CMakeLists.txt
=====================================
@@ -40,4 +40,4 @@ add_custom_target("Sphinx-${PROJECT_NAME}" ALL
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Sphinx")
-install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sphinx/ DESTINATION ${CMAKE_INSTALL_DOCDIR} PATTERN .doctrees EXCLUDE)
+install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sphinx/ DESTINATION share/doc/mcfp PATTERN .doctrees EXCLUDE)
=====================================
examples/example.cpp
=====================================
@@ -7,6 +7,7 @@
int main(int argc, char * const argv[])
{
+ // config is a singleton
auto &config = mcfp::config::instance();
// Initialise the config object. This can be done more than once,
@@ -47,7 +48,7 @@ int main(int argc, char * const argv[])
config.parse(argc, argv, ec);
if (ec)
{
- std::cerr << "Error parsing arguments: " << ec.message() << std::endl;
+ std::cerr << "Error parsing argument " << std::quoted(config.get_last_option()) << ": " << ec.message() << std::endl;
exit(1);
}
@@ -67,7 +68,7 @@ int main(int argc, char * const argv[])
config.parse_config_file("config", "example.conf", { "." }, ec);
if (ec)
{
- std::cerr << "Error parsing config file: " << ec.message() << std::endl;
+ std::cerr << "Error parsing config file, option " << std::quoted(config.get_last_option()) << ": " << ec.message() << std::endl;
exit(1);
}
=====================================
include/mcfp/detail/charconv.hpp
=====================================
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2022 Maarten L. hekkelman
+ * Copyright (c) 2022-2025 Maarten L. hekkelman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -33,9 +33,9 @@
#include <vector>
#if __has_include(<experimental/type_traits>)
-#include <experimental/type_traits>
+# include <experimental/type_traits>
#else
-#include <type_traits>
+# include <type_traits>
#endif
namespace mcfp::detail
@@ -45,21 +45,22 @@ namespace mcfp::detail
// This code is copied from:
// https://ld2015.scusa.lsu.edu/cppreference/en/cpp/experimental/is_detected.html
-template< class... >
+template <class...>
using void_t = void;
namespace detail
{
template <class Default, class AlwaysVoid,
- template<class...> class Op, class... Args>
+ template <class...> class Op, class... Args>
struct detector
{
using value_t = std::false_type;
using type = Default;
};
-
- template <class Default, template<class...> class Op, class... Args>
- struct detector<Default, void_t<Op<Args...>>, Op, Args...> {
+
+ template <class Default, template <class...> class Op, class... Args>
+ struct detector<Default, void_t<Op<Args...>>, Op, Args...>
+ {
// Note that std::void_t is a c++17 feature
using value_t = std::true_type;
using type = Op<Args...>;
@@ -70,178 +71,73 @@ struct nonesuch
{
nonesuch() = delete;
~nonesuch() = delete;
- nonesuch(nonesuch const&) = delete;
- void operator=(nonesuch const&) = delete;
+ nonesuch(nonesuch const &) = delete;
+ void operator=(nonesuch const &) = delete;
};
-template <template<class...> class Op, class... Args>
+template <template <class...> class Op, class... Args>
using is_detected = typename detail::detector<nonesuch, void, Op, Args...>::value_t;
-template <template<class...> class Op, class... Args>
-constexpr inline bool is_detected_v = is_detected<Op,Args...>::value;
+template <template <class...> class Op, class... Args>
+constexpr inline bool is_detected_v = is_detected<Op, Args...>::value;
-template <template<class...> class Op, class... Args>
+template <template <class...> class Op, class... Args>
using detected_t = typename detail::detector<nonesuch, void, Op, Args...>::type;
-template <class Default, template<class...> class Op, class... Args>
+template <class Default, template <class...> class Op, class... Args>
using detected_or = detail::detector<Default, void, Op, Args...>;
template <class Expected, template <class...> class Op, class... Args>
using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
-template <class Expected, template<class...> class Op, class... Args>
+template <class Expected, template <class...> class Op, class... Args>
constexpr inline bool is_detected_exact_v = is_detected_exact<Expected, Op, Args...>::value;
#else
-template <template<class...> class Op, class... Args>
-constexpr inline bool is_detected_v = std::experimental::is_detected<Op,Args...>::value;
+template <template <class...> class Op, class... Args>
+constexpr inline bool is_detected_v = std::experimental::is_detected<Op, Args...>::value;
#endif
+// Unfortunately, the std library for clang does not support from_chars with float types
+// Now, this code is not very speed sensitive, so we work around this limitation using
+// std::stof/std::stod
+
template <typename T>
-struct my_charconv
-{
- using value_type = T;
+struct my_charconv;
- static std::from_chars_result from_chars(const char *first, const char *last, value_type &value)
+template <>
+struct my_charconv<float>
+{
+ static std::from_chars_result from_chars(const char *first, const char *last, float &value)
{
- std::from_chars_result result{ first, {} };
-
- enum State
- {
- IntegerSign,
- Integer,
- Fraction,
- ExponentSign,
- Exponent
- } state = IntegerSign;
- int sign = 1;
- unsigned long long vi = 0;
- long double f = 1;
- int exponent_sign = 1;
- int exponent = 0;
- bool done = false;
-
- while (not done and result.ec == std::errc())
+ try
{
- char ch = result.ptr != last ? *result.ptr : 0;
- ++result.ptr;
-
- switch (state)
- {
- case IntegerSign:
- if (ch == '-')
- {
- sign = -1;
- state = Integer;
- }
- else if (ch == '+')
- state = Integer;
- else if (ch >= '0' and ch <= '9')
- {
- vi = ch - '0';
- state = Integer;
- }
- else if (ch == '.')
- state = Fraction;
- else
- result.ec = std::errc::invalid_argument;
- break;
-
- case Integer:
- if (ch >= '0' and ch <= '9')
- vi = 10 * vi + (ch - '0');
- else if (ch == 'e' or ch == 'E')
- state = ExponentSign;
- else if (ch == '.')
- state = Fraction;
- else
- {
- done = true;
- --result.ptr;
- }
- break;
-
- case Fraction:
- if (ch >= '0' and ch <= '9')
- {
- vi = 10 * vi + (ch - '0');
- f /= 10;
- }
- else if (ch == 'e' or ch == 'E')
- state = ExponentSign;
- else
- {
- done = true;
- --result.ptr;
- }
- break;
-
- case ExponentSign:
- if (ch == '-')
- {
- exponent_sign = -1;
- state = Exponent;
- }
- else if (ch == '+')
- state = Exponent;
- else if (ch >= '0' and ch <= '9')
- {
- exponent = ch - '0';
- state = Exponent;
- }
- else
- result.ec = std::errc::invalid_argument;
- break;
-
- case Exponent:
- if (ch >= '0' and ch <= '9')
- exponent = 10 * exponent + (ch - '0');
- else
- {
- done = true;
- --result.ptr;
- }
- break;
- }
+ value = std::stof(std::string(first, last));
+ return { last, std::errc{} };
}
-
- if (result.ec == std::errc())
+ catch (const std::exception &e)
{
- long double v = f * vi * sign;
- if (exponent != 0)
- v *= std::pow(10, exponent * exponent_sign);
-
- if (std::isnan(v))
- result.ec = std::errc::invalid_argument;
- else if (std::abs(v) > std::numeric_limits<value_type>::max())
- result.ec = std::errc::result_out_of_range;
-
- value = static_cast<value_type>(v);
+ return { first, std::errc::invalid_argument };
}
-
- return result;
}
+};
- template <typename Iterator, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>
- static std::to_chars_result to_chars(Iterator first, Iterator last, const T &value)
+template <>
+struct my_charconv<double>
+{
+ static std::from_chars_result from_chars(const char *first, const char *last, double &value)
{
- int size = last - first;
- int r;
-
- if constexpr (std::is_same_v<T, long double>)
- r = snprintf(first, last - first, "%lg", value);
- else
- r = snprintf(first, last - first, "%g", value);
-
- std::to_chars_result result;
- if (r < 0 or r >= size)
- result = { first, std::errc::value_too_large };
- else
- result = { first + r, std::errc() };
-
- return result;
+ try
+ {
+ value = std::stod(std::string(first, last));
+ return { last, std::errc{} };
+ }
+ catch (const std::exception &e)
+ {
+ return { first, std::errc::invalid_argument };
+ }
}
};
@@ -252,18 +148,20 @@ struct std_charconv
{
return std::from_chars(a, b, d);
}
-
- template<typename Iterator>
- static std::to_chars_result to_chars(Iterator a, Iterator b, const T &value)
- {
- return std::to_chars(a, b, value);
- }
};
+// Make sure we only use our kludge when necessary.
+
template <typename T>
using from_chars_function = decltype(std::from_chars(std::declval<const char *>(), std::declval<const char *>(), std::declval<T &>()));
template <typename T>
using charconv = typename std::conditional_t<is_detected_v<from_chars_function, T>, std_charconv<T>, my_charconv<T>>;
-}
\ No newline at end of file
+template <typename T>
+constexpr auto from_chars(const char *s, const char *e, T &v)
+{
+ return charconv<T>::from_chars(s, e, v);
+}
+
+} // namespace mcfp::detail
\ No newline at end of file
=====================================
include/mcfp/detail/options.hpp
=====================================
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2022 Maarten L. hekkelman
+ * Copyright (c) 2022-2025 Maarten L. hekkelman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -93,7 +93,7 @@ struct option_traits<T, typename std::enable_if_t<std::is_arithmetic_v<T>>>
static value_type set_value(std::string_view argument, std::error_code &ec)
{
value_type value{};
- auto r = charconv<value_type>::from_chars(argument.data(), argument.data() + argument.length(), value);
+ auto r = from_chars(argument.data(), argument.data() + argument.length(), value);
if (r.ec != std::errc())
ec = std::make_error_code(r.ec);
return value;
@@ -102,7 +102,7 @@ struct option_traits<T, typename std::enable_if_t<std::is_arithmetic_v<T>>>
static std::string to_string(const T &value)
{
char b[32];
- auto r = charconv<value_type>::to_chars(b, b + sizeof(b), value);
+ auto r = std::to_chars(b, b + sizeof(b), value);
if (r.ec != std::errc())
throw std::system_error(std::make_error_code(r.ec));
return { b, r.ptr };
=====================================
include/mcfp/error.hpp
=====================================
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2022 Maarten L. Hekkelman
+ * Copyright (c) 2022-2025 Maarten L. hekkelman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
=====================================
include/mcfp/mcfp.hpp
=====================================
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2022 Maarten L. Hekkelman
+ * Copyright (c) 2022-2025 Maarten L. hekkelman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -113,6 +113,16 @@ class config
return *s_instance;
}
+ /**
+ * @brief Get the last option name, for use in error reporting
+ *
+ * @return std::string The last parsed or requested option
+ */
+ std::string get_last_option() const
+ {
+ return get_last_option_storage();
+ }
+
/**
* @brief Simply return true if the option with \a name has a value assigned
*
@@ -175,6 +185,9 @@ class config
{
using return_type = std::remove_cv_t<T>;
+ // store name for inspection later on
+ get_last_option_storage() = name;
+
return_type result{};
auto opt = m_impl->get_option(name);
@@ -420,6 +433,9 @@ class config
name.insert(name.end(), static_cast<char>(ch));
else if (is_eoln(ch))
{
+ // store name for inspection later on
+ get_last_option_storage() = name;
+
auto opt = m_impl->get_option(name);
if (opt == nullptr)
@@ -446,6 +462,9 @@ class config
state = State::VALUE_START;
else if (is_eoln(ch))
{
+ // store name for inspection later on
+ get_last_option_storage() = name;
+
auto opt = m_impl->get_option(name);
if (opt == nullptr)
@@ -468,6 +487,9 @@ class config
case State::VALUE:
if (is_eoln(ch))
{
+ // store name for inspection later on
+ get_last_option_storage() = name;
+
auto opt = m_impl->get_option(name);
if (opt == nullptr)
@@ -567,6 +589,9 @@ class config
s_arg = s_arg.substr(0, p);
}
+ // store name for inspection later on
+ get_last_option_storage() = s_arg;
+
opt = m_impl->get_option(s_arg);
if (opt == nullptr)
{
@@ -592,6 +617,8 @@ class config
while (*arg != 0 and not ec)
{
+ // store name for inspection later on
+ get_last_option_storage() = *arg;
opt = m_impl->get_option(*arg++);
if (opt == nullptr)
@@ -634,6 +661,12 @@ class config
/// @cond
+ static std::string &get_last_option_storage()
+ {
+ thread_local static std::string s_last_option;
+ return s_last_option;
+ }
+
struct config_impl_base
{
virtual ~config_impl_base() = default;
=====================================
include/mcfp/text.hpp
=====================================
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2022 Maarten L. hekkelman
+ * Copyright (c) 2022-2025 Maarten L. hekkelman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
=====================================
include/mcfp/utilities.hpp
=====================================
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2022 Maarten L. Hekkelman
+ * Copyright (c) 2022-2025 Maarten L. hekkelman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
=====================================
test/CMakeLists.txt
=====================================
@@ -1,18 +1,28 @@
-
-if(NOT(Catch2_FOUND OR TARGET Catch2))
- find_package(Catch2 3 QUIET)
-
- if(NOT Catch2_FOUND)
- include(FetchContent)
-
- FetchContent_Declare(
- Catch2
- GIT_REPOSITORY https://github.com/catchorg/Catch2.git
- GIT_TAG v3.8.0)
-
- FetchContent_MakeAvailable(Catch2)
- endif()
-endif()
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2025 Maarten L. Hekkelman
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+CPMAddPackage("gh:catchorg/Catch2 at 3.4.0")
add_executable(mcfp-unit-test ${CMAKE_CURRENT_SOURCE_DIR}/unit-test.cpp)
=====================================
test/unit-test.cpp
=====================================
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2022 Maarten L. Hekkelman
+ * Copyright (c) 2022-2025 Maarten L. hekkelman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -43,10 +43,10 @@ int main(int argc, char *argv[])
// Build a new parser on top of Catch2's
using namespace Catch::Clara;
- auto cli = session.cli() // Get Catch2's command line parser
- | Opt(gTestDir, "data-dir") // bind variable to a new option, with a hint string
- ["-D"]["--data-dir"] // the option names it will respond to
- ("The directory containing the data files"); // description string for the help output
+ auto cli = session.cli(); // Get Catch2's command line parser
+ cli |= Opt(gTestDir, "data-dir") // bind variable to a new option, with a hint string
+ ["-D"]["--data-dir"] // the option names it will respond to
+ ("The directory containing the data files"); // description string for the help output
// Now pass the new composite back to Catch2 so it uses that
session.cli(cli);
@@ -77,7 +77,7 @@ TEST_CASE("t_1, * utf::tolerance(0.001)")
mcfp::make_option("param_int_2", 1, ""),
mcfp::make_option<float>("param_float", ""),
mcfp::make_option("param_float_2", 3.14f, ""));
-
+
config.parse(argc, argv);
CHECK(config.has("flag"));
@@ -104,7 +104,7 @@ TEST_CASE("t_2")
config.init(
"test [options]",
mcfp::make_option("verbose,v", ""));
-
+
config.parse(argc, argv);
CHECK(config.count("verbose") == 5);
@@ -122,7 +122,7 @@ TEST_CASE("t_3")
config.init(
"test [options]",
mcfp::make_option<int>("param_int", ""));
-
+
config.parse(argc, argv);
CHECK(config.has("param_int"));
@@ -140,7 +140,7 @@ TEST_CASE("t_4")
config.init(
"test [options]",
mcfp::make_option<int>("param_int", ""));
-
+
config.parse(argc, argv);
CHECK(config.has("param_int"));
@@ -152,15 +152,15 @@ TEST_CASE("t_5")
const char *const argv[] = {
"test", "-i", "42", "-j43", nullptr
};
- int argc = sizeof(argv) / sizeof(char*);
-
+ int argc = sizeof(argv) / sizeof(char *);
+
auto &config = mcfp::config::instance();
config.init(
"test [options]",
mcfp::make_option<int>("nr1,i", ""),
mcfp::make_option<int>("nr2,j", ""));
-
+
config.parse(argc, argv);
CHECK(config.has("nr1"));
@@ -175,15 +175,15 @@ TEST_CASE("t_6")
const char *const argv[] = {
"test", "-i", "42", "-j43", "foo", "bar", nullptr
};
- int argc = sizeof(argv) / sizeof(char*);
-
+ int argc = sizeof(argv) / sizeof(char *);
+
auto &config = mcfp::config::instance();
config.init(
"test [options]",
mcfp::make_option<int>("nr1,i", ""),
mcfp::make_option<int>("nr2,j", ""));
-
+
config.parse(argc, argv);
CHECK(config.has("nr1"));
@@ -202,15 +202,15 @@ TEST_CASE("t_7")
const char *const argv[] = {
"test", "--", "-i", "42", "-j43", "foo", "bar", nullptr
};
- int argc = sizeof(argv) / sizeof(char*) - 1;
-
+ int argc = sizeof(argv) / sizeof(char *) - 1;
+
auto &config = mcfp::config::instance();
config.init(
"test [options]",
mcfp::make_option<int>("nr1,i", ""),
mcfp::make_option<int>("nr2,j", ""));
-
+
config.parse(argc, argv);
CHECK(not config.has("nr1"));
@@ -227,16 +227,16 @@ TEST_CASE("t_8")
const char *const argv[] = {
"test", "-i", "foo", "-jbar", nullptr
};
- int argc = sizeof(argv) / sizeof(char*) - 1;
-
+ int argc = sizeof(argv) / sizeof(char *) - 1;
+
auto &config = mcfp::config::instance();
config.init(
"test [options]",
- mcfp::make_option<const char*>("i", ""),
+ mcfp::make_option<const char *>("i", ""),
mcfp::make_option<std::string_view>("j", ""),
mcfp::make_option("k", "baz", ""));
-
+
config.parse(argc, argv);
CHECK(config.has("i"));
@@ -256,37 +256,37 @@ TEST_CASE("t_9")
config.init(
"test [options]",
- mcfp::make_option<const char*>("i", "First option"),
+ mcfp::make_option<const char *>("i", "First option"),
mcfp::make_option<std::string_view>("j", "This is the second option"),
mcfp::make_option("a-very-long-option-name,k", "baz", "And, you guessed it, this must be option three."));
-
-// std::stringstream ss;
-// int fd = open("/dev/null", O_RDWR);
-// dup2(fd, STDOUT_FILENO);
+ // std::stringstream ss;
-// ss << config << std::endl;
+ // int fd = open("/dev/null", O_RDWR);
+ // dup2(fd, STDOUT_FILENO);
-// const char kExpected[] = R"(usage: test [options]
-// -i arg First option
-// -j arg This is the second option
-// -k [ --a-very-long-option-name ] arg (=baz)
-// And, you guessed it, this must be
-// option three.
+ // ss << config << std::endl;
-// )";
+ // const char kExpected[] = R"(usage: test [options]
+ // -i arg First option
+ // -j arg This is the second option
+ // -k [ --a-very-long-option-name ] arg (=baz)
+ // And, you guessed it, this must be
+ // option three.
-// std::cerr << '>' << kExpected << '<' << std::endl;
-// std::cerr << '>' << ss.str() << '<' << std::endl;
+ // )";
-// CHECK_EQUAL(ss.str(), kExpected);
+ // std::cerr << '>' << kExpected << '<' << std::endl;
+ // std::cerr << '>' << ss.str() << '<' << std::endl;
+
+ // CHECK_EQUAL(ss.str(), kExpected);
}
TEST_CASE("t_10")
{
std::string s1 = R"(SPDX-License-Identifier: BSD-2-Clause
-Copyright (c) 2022 Maarten L. Hekkelman
+Copyright (c) 2022-2025 Maarten L. hekkelman
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -302,10 +302,10 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
for (auto line : ww)
os << line << std::endl;
-
+
CHECK(os.str() == R"(SPDX-License-Identifier: BSD-2-Clause
-Copyright (c) 2022 Maarten L. Hekkelman
+Copyright (c) 2022-2025 Maarten L. hekkelman
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
@@ -335,18 +335,18 @@ TEST_CASE("t_11")
const char *const argv[] = {
"test", "-faap", "-fnoot", "-fmies", nullptr
};
- int argc = sizeof(argv) / sizeof(char*) - 1;
+ int argc = sizeof(argv) / sizeof(char *) - 1;
auto &config = mcfp::config::instance();
config.init(
"test [options]",
mcfp::make_option<std::vector<std::string>>("file,f", ""));
-
+
config.parse(argc, argv);
CHECK(config.count("file") == 3);
-
+
std::vector<std::string> files = config.get<std::vector<std::string>>("file");
CHECK(files.size() == 3);
CHECK(files[0] == "aap");
@@ -359,14 +359,14 @@ TEST_CASE("t_12")
const char *const argv[] = {
"test", "--aap", nullptr
};
- int argc = sizeof(argv) / sizeof(char*) - 1;
+ int argc = sizeof(argv) / sizeof(char *) - 1;
auto &config = mcfp::config::instance();
config.init(
"test [options]",
mcfp::make_option<std::vector<std::string>>("file,f", ""));
-
+
std::error_code ec;
config.parse(argc, argv, ec);
CHECK(ec == mcfp::config_error::unknown_option);
@@ -383,14 +383,14 @@ TEST_CASE("t_13")
const char *const argv[] = {
"test", "--test=bla", nullptr
};
- int argc = sizeof(argv) / sizeof(char*) - 1;
+ int argc = sizeof(argv) / sizeof(char *) - 1;
auto &config = mcfp::config::instance();
config.init(
"test [options]",
mcfp::make_option<std::string>("test", ""));
-
+
CHECK_NOTHROW(config.parse(argc, argv));
CHECK(config.has("test"));
@@ -402,14 +402,14 @@ TEST_CASE("t_14")
const char *const argv[] = {
"test", "-test=bla", nullptr
};
- int argc = sizeof(argv) / sizeof(char*) - 1;
+ int argc = sizeof(argv) / sizeof(char *) - 1;
auto &config = mcfp::config::instance();
config.init(
"test [options]",
mcfp::make_option<std::string>("test", ""));
-
+
CHECK_THROWS_AS(config.parse(argc, argv), std::system_error);
}
@@ -429,7 +429,7 @@ verbose
struct membuf : public std::streambuf
{
- membuf(char * text, size_t length)
+ membuf(char *text, size_t length)
{
this->setg(text, text, text + length);
}
@@ -441,13 +441,13 @@ verbose
config.init(
"test [options]",
- mcfp::make_option<const char*>("aap", ""),
+ mcfp::make_option<const char *>("aap", ""),
mcfp::make_option<int>("noot", ""),
mcfp::make_option<std::string>("mies", ""),
mcfp::make_option<float>("pi", ""),
mcfp::make_option<std::string>("s", ""),
mcfp::make_option("verbose,v", ""));
-
+
std::error_code ec;
config.parse_config_file(is, ec);
@@ -473,19 +473,19 @@ TEST_CASE("file_2")
{
auto &config = mcfp::config::instance();
- std::tuple<std::string_view,std::string_view,std::error_code> tests[] = {
+ std::tuple<std::string_view, std::string_view, std::error_code> tests[] = {
{ "aap !", "aap", make_error_code(mcfp::config_error::invalid_config_file) },
{ "aap=aap", "aap", {} },
{ "aap", "aap", make_error_code(mcfp::config_error::missing_argument_for_option) },
{ "verbose=1", "verbose", make_error_code(mcfp::config_error::option_does_not_accept_argument) },
-
+
};
for (const auto &[config_file, option, err] : tests)
{
struct membuf : public std::streambuf
{
- membuf(char * text, size_t length)
+ membuf(char *text, size_t length)
{
this->setg(text, text, text + length);
}
@@ -496,12 +496,12 @@ TEST_CASE("file_2")
std::error_code ec;
config.init(
"test [options]",
- mcfp::make_option<const char*>("aap", ""),
+ mcfp::make_option<const char *>("aap", ""),
mcfp::make_option<int>("noot", ""),
mcfp::make_option<float>("pi", ""),
mcfp::make_option<std::string>("s", ""),
mcfp::make_option("verbose,v", ""));
-
+
config.parse_config_file(is, ec);
CHECK(ec == err);
@@ -517,16 +517,16 @@ TEST_CASE("file_3")
config.init(
"test [options]",
- mcfp::make_option<const char*>("aap", ""),
+ mcfp::make_option<const char *>("aap", ""),
mcfp::make_option<int>("noot", ""),
mcfp::make_option<std::string>("config", ""));
-
+
std::error_code ec;
const char *const argv[] = {
"test", "--aap=aap", "--noot=42", "--config=unit-test.conf", nullptr
};
- int argc = sizeof(argv) / sizeof(char*) - 1;
+ int argc = sizeof(argv) / sizeof(char *) - 1;
config.parse(argc, argv);
@@ -541,22 +541,22 @@ TEST_CASE("file_3")
CHECK(config.get<int>("noot") == 42);
}
- TEST_CASE("file_4")
+TEST_CASE("file_4")
{
auto &config = mcfp::config::instance();
config.init(
"test [options]",
- mcfp::make_option<const char*>("aap", ""),
+ mcfp::make_option<const char *>("aap", ""),
mcfp::make_option<int>("noot", ""),
mcfp::make_option<std::string>("config", ""));
-
+
std::error_code ec;
const char *const argv[] = {
"test", "--aap=aap", nullptr
};
- int argc = sizeof(argv) / sizeof(char*) - 1;
+ int argc = sizeof(argv) / sizeof(char *) - 1;
config.parse(argc, argv);
View it on GitLab: https://salsa.debian.org/med-team/libmcfp/-/compare/5fe474cbc642ddfe419d45f540252f81e9276c20...5361de6d37e36fdbce508feb918ea129fd7e5db8
--
View it on GitLab: https://salsa.debian.org/med-team/libmcfp/-/compare/5fe474cbc642ddfe419d45f540252f81e9276c20...5361de6d37e36fdbce508feb918ea129fd7e5db8
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20250526/8090d062/attachment-0001.htm>
More information about the debian-med-commit
mailing list