From d4d5de473425db32d2e96e76472475ce537c1e63 Mon Sep 17 00:00:00 2001 From: Mikhail Kolyadin Date: Wed, 22 Jul 2026 02:18:13 +0300 Subject: [PATCH 1/2] Added a CMake target for C++20 modules, to allow adding argparse.cppm to projects using CMake. This follows the approach used by tomlplusplus and nlohmann/json --- module/CMakeLists.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 module/CMakeLists.txt diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt new file mode 100644 index 00000000..7e6014bc --- /dev/null +++ b/module/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.28) + +add_library(argparse_modules) + +add_library(argparse::modules ALIAS argparse_modules) + +target_sources( + argparse_modules PUBLIC FILE_SET CXX_MODULES FILES + argparse.cppm) + +target_link_libraries(argparse_modules PRIVATE argparse::argparse) + +if(ARGPARSE_MODULE_USE_STD_MODULE) + target_compile_definitions(argparse_modules + PRIVATE -DARGPARSE_MODULE_USE_STD_MODULE=1) + + target_compile_features(argparse_modules PUBLIC cxx_std_23) +else() + target_compile_features(argparse_modules PUBLIC cxx_std_20) +endif() From 55f8c677d3569fb94f0c5ce4fa0a9edbd9e2cb2e Mon Sep 17 00:00:00 2001 From: Mikhail Kolyadin Date: Wed, 22 Jul 2026 02:18:36 +0300 Subject: [PATCH 2/2] Added a CMake target for C++20 modules, to allow adding argparse.cppm to projects using CMake. This follows the approach used by tomlplusplus and nlohmann/json --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ddb4bc6f..ccd9ae23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,8 @@ project(argparse option(ARGPARSE_INSTALL "Include an install target" ${ARGPARSE_IS_TOP_LEVEL}) option(ARGPARSE_BUILD_TESTS "Build tests" ${ARGPARSE_IS_TOP_LEVEL}) option(ARGPARSE_BUILD_SAMPLES "Build samples" OFF) +option(ARGPARSE_BUILD_MODULES "Build C++ modules support" OFF) +option(ARGPARSE_MODULE_USE_STD_MODULE "Build with modules C++ import std" OFF) include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -28,6 +30,10 @@ target_include_directories(argparse INTERFACE $ $) +if(ARGPARSE_BUILD_MODULES) + add_subdirectory(module) +endif() + if(ARGPARSE_BUILD_SAMPLES) add_subdirectory(samples) endif()