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() 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()