├── header-units ├── internal │ ├── module.h │ ├── module.mpp │ └── CMakeLists.txt ├── external │ ├── module.mpp │ └── CMakeLists.txt └── CMakeLists.txt ├── good-scanner ├── import.mpp ├── export.mpp ├── header-import.mpp ├── macro-messiness.mpp ├── import-define.mpp ├── mod.mpp ├── other.mpp ├── define.mpp ├── export-define.mpp └── CMakeLists.txt ├── partitions ├── partb.mpp ├── impl.mpp ├── parta.mpp ├── module.mpp └── CMakeLists.txt ├── generated ├── gen-import.mpp.in ├── gen-export.mpp.in ├── use.mpp └── CMakeLists.txt ├── link-use ├── use.mpp └── CMakeLists.txt ├── duplicates-same-dir ├── duplicate.mpp └── CMakeLists.txt ├── link-use-mask ├── use.mpp └── CMakeLists.txt ├── named ├── clean.bash ├── depmodule1.cpp ├── depmodule2.cpp ├── mymodule_impl.cpp ├── main.cpp ├── mymodule_part.cpp ├── mymodule_part_internal.cpp ├── mymodule_part_impl.cpp ├── mymodule.cpp ├── build-msvc.bash ├── build-gnu.bash ├── CMakeLists.txt ├── build-msvc-moddir.bash ├── build-gnu-moddir.bash ├── scan-msvc.bash └── build-msvc-explicit.bash ├── simple ├── use.mpp ├── another.mpp ├── duplicate.mpp └── CMakeLists.txt ├── duplicates ├── duplicate.mpp └── CMakeLists.txt ├── README.md ├── CMakeLists.txt ├── .github ├── ci │ └── cmake.ps1 └── workflows │ └── cmake.yml └── LICENSE /header-units/internal/module.h: -------------------------------------------------------------------------------- 1 | int somedecl(); 2 | -------------------------------------------------------------------------------- /good-scanner/import.mpp: -------------------------------------------------------------------------------- 1 | const char* import = "\ 2 | import nonexistent; \ 3 | "; 4 | -------------------------------------------------------------------------------- /partitions/partb.mpp: -------------------------------------------------------------------------------- 1 | module module:partb; 2 | 3 | int b() { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /good-scanner/export.mpp: -------------------------------------------------------------------------------- 1 | const char* export_ = "\ 2 | export module nonexistent; \ 3 | "; 4 | -------------------------------------------------------------------------------- /good-scanner/header-import.mpp: -------------------------------------------------------------------------------- 1 | const char* header = "\ 2 | #include \ 3 | "; 4 | -------------------------------------------------------------------------------- /partitions/impl.mpp: -------------------------------------------------------------------------------- 1 | module module:impl; 2 | 3 | int impl() { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /generated/gen-import.mpp.in: -------------------------------------------------------------------------------- 1 | import gen; 2 | 3 | int genimport() { 4 | return gen(); 5 | } 6 | -------------------------------------------------------------------------------- /good-scanner/macro-messiness.mpp: -------------------------------------------------------------------------------- 1 | #define eat(x) 2 | eat( 3 | import module nonexistent; 4 | ) 5 | -------------------------------------------------------------------------------- /generated/gen-export.mpp.in: -------------------------------------------------------------------------------- 1 | export module gen; 2 | 3 | export int gen() { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /partitions/parta.mpp: -------------------------------------------------------------------------------- 1 | export module module:parta; 2 | 3 | export int a() { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /good-scanner/import-define.mpp: -------------------------------------------------------------------------------- 1 | import DEFINE; 2 | 3 | int importfunc() { 4 | return func(); 5 | } 6 | -------------------------------------------------------------------------------- /header-units/internal/module.mpp: -------------------------------------------------------------------------------- 1 | #include "module.h" 2 | 3 | int somedecl() { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /link-use/use.mpp: -------------------------------------------------------------------------------- 1 | import duplicate; 2 | 3 | int main(int argc, char* argv[]) { 4 | return m(); 5 | } 6 | -------------------------------------------------------------------------------- /duplicates-same-dir/duplicate.mpp: -------------------------------------------------------------------------------- 1 | export module duplicate; 2 | 3 | export int m() { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /link-use-mask/use.mpp: -------------------------------------------------------------------------------- 1 | import duplicate; 2 | 3 | int main(int argc, char* argv[]) { 4 | return m(); 5 | } 6 | -------------------------------------------------------------------------------- /named/clean.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | rm -rf *.exe gcm.cache *.ifc *.json main mod *.modmap.txt *.o *.obj 3 | -------------------------------------------------------------------------------- /simple/use.mpp: -------------------------------------------------------------------------------- 1 | import duplicate; 2 | import another; 3 | 4 | int lib() { 5 | return m() + i(); 6 | } 7 | -------------------------------------------------------------------------------- /named/depmodule1.cpp: -------------------------------------------------------------------------------- 1 | // Module Interface Unit 2 | export module DepModule1; 3 | 4 | export void depmod1_f() {} 5 | -------------------------------------------------------------------------------- /named/depmodule2.cpp: -------------------------------------------------------------------------------- 1 | // Module Interface Unit 2 | export module DepModule2; 3 | 4 | export void depmod2_f() {} 5 | -------------------------------------------------------------------------------- /simple/another.mpp: -------------------------------------------------------------------------------- 1 | export module another; 2 | import duplicate; 3 | 4 | export int i() { 5 | return m(); 6 | } 7 | -------------------------------------------------------------------------------- /header-units/external/module.mpp: -------------------------------------------------------------------------------- 1 | import ; 2 | import extmod; 3 | 4 | int m() { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /link-use/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(link-use 2 | use.mpp) 3 | target_link_libraries(link-use 4 | PRIVATE 5 | simple) 6 | -------------------------------------------------------------------------------- /simple/duplicate.mpp: -------------------------------------------------------------------------------- 1 | export module duplicate; 2 | 3 | #include "simple_export.h" 4 | 5 | export SIMPLE_EXPORT int m() { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /duplicates/duplicate.mpp: -------------------------------------------------------------------------------- 1 | export module duplicate; 2 | 3 | #include "duplicates_export.h" 4 | 5 | export DUPLICATES_EXPORT int m() { 6 | return 1; 7 | } 8 | -------------------------------------------------------------------------------- /good-scanner/mod.mpp: -------------------------------------------------------------------------------- 1 | export module mod; 2 | 3 | #include "good-scanner_export.h" 4 | 5 | export GOOD_SCANNER_EXPORT int modfunc() { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /good-scanner/other.mpp: -------------------------------------------------------------------------------- 1 | export module other; 2 | 3 | #include "good-scanner_export.h" 4 | 5 | export GOOD_SCANNER_EXPORT int otherfunc() { 6 | return 1; 7 | } 8 | -------------------------------------------------------------------------------- /generated/use.mpp: -------------------------------------------------------------------------------- 1 | import gen; 2 | 3 | extern int genimport(); 4 | 5 | int main(int argc, char* argv[]) { 6 | (void)argc; 7 | (void)argv; 8 | 9 | return gen() + genimport(); 10 | } 11 | -------------------------------------------------------------------------------- /good-scanner/define.mpp: -------------------------------------------------------------------------------- 1 | import DEFINE; 2 | 3 | int main(int argc, char* argv[]) { 4 | (void)argc; 5 | (void)argv; 6 | #ifdef USE_MOD 7 | return modfunc(); 8 | #else 9 | return otherfunc(); 10 | #endif 11 | } 12 | -------------------------------------------------------------------------------- /named/mymodule_impl.cpp: -------------------------------------------------------------------------------- 1 | // Module Implementation Unit 2 | module MyModule; 3 | 4 | // Implement a function declared in the module interface unit. 5 | void mod_g() {} 6 | 7 | // Implement a function declared in a module partition. 8 | void part_g() {} 9 | -------------------------------------------------------------------------------- /named/main.cpp: -------------------------------------------------------------------------------- 1 | // Module consumer. 2 | import MyModule; 3 | 4 | // Use functions exported by the module interface unit. 5 | int main() { 6 | mod_f(); 7 | mod_g(); 8 | part_f(); 9 | part_g(); 10 | part_g_impl(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /header-units/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This subdirectory uses proposed CMake APIs. They are not yet implemented. 2 | 3 | # Declare header units for internal targets. 4 | add_subdirectory(internal) 5 | 6 | # Declare modules for external dependencies. 7 | add_subdirectory(external) 8 | -------------------------------------------------------------------------------- /partitions/module.mpp: -------------------------------------------------------------------------------- 1 | export module module; 2 | export import :parta; 3 | import :partb; 4 | import :impl; 5 | 6 | export int useparta() { 7 | return a(); 8 | } 9 | 10 | export int usepartb() { 11 | return b(); 12 | } 13 | 14 | export int useimpl() { 15 | return impl(); 16 | } 17 | -------------------------------------------------------------------------------- /named/mymodule_part.cpp: -------------------------------------------------------------------------------- 1 | // Module Partition 2 | export module MyModule:part; 3 | 4 | // Export a function from this module partition. Implement it here. 5 | export void part_f() {} 6 | 7 | // Export functions from this module partition. Implemented elsewhere. 8 | export void part_g(); 9 | export void part_g_impl(); 10 | -------------------------------------------------------------------------------- /partitions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(partitions) 2 | target_sources(partitions 3 | PUBLIC 4 | FILE_SET cxx_modules TYPE CXX_MODULES FILES 5 | module.mpp 6 | parta.mpp 7 | FILE_SET cxx_module_internal_partitions TYPE CXX_MODULE_INTERNAL_PARTITIONS FILES 8 | partb.mpp 9 | impl.mpp) 10 | -------------------------------------------------------------------------------- /good-scanner/export-define.mpp: -------------------------------------------------------------------------------- 1 | export module DEFINE; 2 | 3 | #ifdef IS_X 4 | #include "export-define-x_export.h" 5 | #define library_export_macro EXPORT_DEFINE_X_EXPORT 6 | #else 7 | #include "export-define-y_export.h" 8 | #define library_export_macro EXPORT_DEFINE_Y_EXPORT 9 | #endif 10 | 11 | export library_export_macro int func() { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /duplicates-same-dir/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(duplicates-same-dir-1) 2 | target_sources(duplicates-same-dir-1 3 | PUBLIC 4 | FILE_SET cxx_modules TYPE CXX_MODULES FILES 5 | duplicate.mpp) 6 | add_library(duplicates-same-dir-2) 7 | target_sources(duplicates-same-dir-2 8 | PUBLIC 9 | FILE_SET cxx_modules TYPE CXX_MODULES FILES 10 | duplicate.mpp) 11 | -------------------------------------------------------------------------------- /duplicates/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(duplicates) 2 | generate_export_header(duplicates) 3 | target_sources(duplicates 4 | PUBLIC 5 | FILE_SET headers TYPE HEADERS 6 | BASE_DIRS 7 | "${CMAKE_CURRENT_BINARY_DIR}" 8 | FILES 9 | "${CMAKE_CURRENT_BINARY_DIR}/duplicates_export.h" 10 | FILE_SET cxx_modules TYPE CXX_MODULES FILES 11 | duplicate.mpp) 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cxx-modules-sandbox 2 | 3 | This repository is intended to host various corner cases with C++20's modules 4 | and how to build them with various build systems. 5 | 6 | Is your build system not represented here? Please submit a PR to add its build 7 | configuration and it'd be great if it could be added to the CI configuration. 8 | The `Dockerfile` for the CI run is stored on the `docker` branch of this 9 | repository. 10 | -------------------------------------------------------------------------------- /simple/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(simple) 2 | generate_export_header(simple) 3 | target_sources(simple 4 | PRIVATE 5 | use.mpp 6 | PRIVATE 7 | FILE_SET headers TYPE HEADERS 8 | BASE_DIRS 9 | "${CMAKE_CURRENT_BINARY_DIR}" 10 | FILES 11 | "${CMAKE_CURRENT_BINARY_DIR}/simple_export.h" 12 | FILE_SET cxx_modules TYPE CXX_MODULES FILES 13 | duplicate.mpp 14 | another.mpp) 15 | -------------------------------------------------------------------------------- /named/mymodule_part_internal.cpp: -------------------------------------------------------------------------------- 1 | // Module Partition (internal) 2 | module MyModule:part_internal; 3 | 4 | // This is an internal module partition. 5 | // It is a module partition that can be imported 6 | // within the module itself, but not exported from it. 7 | // With MSVC, compile this using `-internalPartition`. 8 | 9 | // Define a function usable elsewhere in the module implementation. 10 | // This is not exported from the module. 11 | void part_internal_f() {} 12 | -------------------------------------------------------------------------------- /named/mymodule_part_impl.cpp: -------------------------------------------------------------------------------- 1 | #ifdef USE_IMPL_PARTITION 2 | // Module Implementation Partition (MSVC-specific) 3 | // In the C++ standard, module partitions are not supposed to 4 | // have separate implementation sources like this. 5 | // Compile this with MSVC *without* using `-internalPartition`. 6 | module MyModule:part; 7 | #else 8 | // Module Implementation Unit 9 | // Implements functions from the module interface or module partition. 10 | module MyModule; 11 | #endif 12 | 13 | // Implement a function declared in a module partition. 14 | void part_g_impl() {} 15 | -------------------------------------------------------------------------------- /named/mymodule.cpp: -------------------------------------------------------------------------------- 1 | // Module Interface Unit 2 | export module MyModule; 3 | 4 | // Import and re-export a module partition. 5 | export import :part; 6 | 7 | // Import an internal module partition. 8 | import :part_internal; 9 | 10 | // Export a function from this module. Implement it here. 11 | export void mod_f() 12 | { 13 | // The implementation can use internal module partition 14 | // functions even though they are not exported. 15 | part_internal_f(); 16 | } 17 | 18 | // Export a function from this module. Implemented elsewhere. 19 | export void mod_g(); 20 | -------------------------------------------------------------------------------- /link-use-mask/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(link-use-mask 2 | use.mpp) 3 | # Should use "simple"'s `M` module since it is first in the link list. 4 | target_link_libraries(link-use-mask 5 | PRIVATE 6 | simple 7 | duplicates) 8 | add_test(NAME link-use-mask COMMAND link-use-mask) 9 | 10 | add_executable(link-use-mask-reverse 11 | use.mpp) 12 | # Should use "duplicate"'s `M` module since it is first in the link list. 13 | target_link_libraries(link-use-mask-reverse 14 | PRIVATE 15 | duplicates 16 | simple) 17 | add_test(NAME link-use-mask-reverse COMMAND link-use-mask-reverse) 18 | set_tests_properties(link-use-mask-reverse 19 | PROPERTIES 20 | WILL_FAIL TRUE) 21 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14 FATAL_ERROR) 2 | project(cxxmodules CXX) 3 | 4 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 5 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 6 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 7 | 8 | set(CMAKE_CXX_STANDARD 20) 9 | # See #10. 10 | # set(CMAKE_CXX_VISIBILITY_PRESET hidden) 11 | 12 | include(GenerateExportHeader) 13 | include(CTest) 14 | 15 | add_subdirectory(simple) 16 | add_subdirectory(duplicates) 17 | add_subdirectory(duplicates-same-dir) 18 | add_subdirectory(link-use) 19 | add_subdirectory(link-use-mask) 20 | add_subdirectory(good-scanner) 21 | add_subdirectory(generated) 22 | 23 | add_subdirectory(partitions) 24 | 25 | # The CMake APIs used here are not yet implemented. 26 | #add_subdirectory(header-units) 27 | -------------------------------------------------------------------------------- /.github/ci/cmake.ps1: -------------------------------------------------------------------------------- 1 | $erroractionpreference = "stop" 2 | 3 | $version = "cpp-modules-20220419.0" 4 | $sha256sum = "9b47636fa03b8c61c3b30eaae629a813dc149eae924778dc582cb2bcc6b74eb3" 5 | $filename = "cmake-$version-win64" 6 | $tarball = "$filename.zip" 7 | 8 | $outdir = $pwd.Path 9 | $outdir = "$outdir\.github" 10 | $ProgressPreference = 'SilentlyContinue' 11 | Invoke-WebRequest -Uri "https://gitlab.kitware.com/api/v4/projects/649/packages/generic/cmake/$version/$tarball" -OutFile "$outdir\$tarball" 12 | $hash = Get-FileHash "$outdir\$tarball" -Algorithm SHA256 13 | if ($hash.Hash -ne $sha256sum) { 14 | exit 1 15 | } 16 | 17 | Add-Type -AssemblyName System.IO.Compression.FileSystem 18 | [System.IO.Compression.ZipFile]::ExtractToDirectory("$outdir\$tarball", "$outdir") 19 | Move-Item -Path "$outdir\$filename" -Destination "$outdir\cmake" 20 | -------------------------------------------------------------------------------- /generated/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | function (generate name) 2 | add_custom_command( 3 | OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}" 4 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${name}.in" 5 | COMMAND "${CMAKE_COMMAND}" 6 | -E copy_if_different 7 | "${CMAKE_CURRENT_SOURCE_DIR}/${name}.in" 8 | "${CMAKE_CURRENT_BINARY_DIR}/${name}" 9 | COMMENT "Copying ${name}") 10 | endfunction () 11 | 12 | generate(gen-export.mpp) 13 | generate(gen-import.mpp) 14 | 15 | add_executable(generated) 16 | target_sources(generated 17 | PRIVATE 18 | "${CMAKE_CURRENT_BINARY_DIR}/gen-import.mpp" 19 | use.mpp 20 | PRIVATE 21 | FILE_SET cxx_modules TYPE CXX_MODULES 22 | BASE_DIRS 23 | "${CMAKE_CURRENT_BINARY_DIR}" 24 | FILES 25 | "${CMAKE_CURRENT_BINARY_DIR}/gen-export.mpp") 26 | add_test(NAME generated COMMAND generated) 27 | -------------------------------------------------------------------------------- /header-units/internal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(GNUInstallDirs) 2 | 3 | # The scanning of this step will add dynamic dependencies to the modules 4 | # declared in the referenced targets. Without this, the above modules would 5 | # *not* have BMIs created there are no references to them. 6 | add_library(has-header-units SHARED 7 | module.mpp) 8 | target_include_directories(has-header-units 9 | PUBLIC 10 | # Make the header available during the build. 11 | "$" 12 | # Install the header for external consumers. 13 | "$" 18 | # Once installed, `import ;` is required. Note that this is 19 | # (likely) a relative path, so CMake will have to prefix this with 20 | # `${CMAKE_INSTALL_PREFIX}` if so. 21 | "$") 22 | 23 | # Install the target. 24 | install( 25 | TARGETS has-header-units 26 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 27 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") 28 | 29 | # Install the header. 30 | install( 31 | FILES module.h 32 | DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") 33 | -------------------------------------------------------------------------------- /named/build-msvc.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -x 5 | 6 | "${BASH_SOURCE%/*}/clean.bash" 7 | 8 | # https://devblogs.microsoft.com/cppblog/using-cpp-modules-in-msvc-from-the-command-line-part-1/ 9 | 10 | # Set to 'true' to try "module implementation partition" offered by MSVC but not in the standard. 11 | USE_IMPL_PARTITION=false 12 | 13 | # Module partition. 14 | # Writes 'MyModule-part.ifc'. 15 | cl -std:c++20 -interface -c mymodule_part.cpp 16 | 17 | # Module implementation partition. 18 | # Reads 'MyModule-part.ifc'. 19 | if $USE_IMPL_PARTITION; then 20 | cl -std:c++20 -c mymodule_part_impl.cpp -DUSE_IMPL_PARTITION 21 | fi 22 | 23 | # Module partition (internal). 24 | # Writes 'MyModule-part_internal.ifc' 25 | cl -std:c++20 -internalPartition -c mymodule_part_internal.cpp 26 | 27 | # Module interface unit. 28 | # Reads 'MyModule-part.ifc'. 29 | # Reads 'MyModule-part_internal.ifc'. 30 | # Writes 'MyModule.ifc'. 31 | cl -std:c++20 -interface -c mymodule.cpp 32 | 33 | # Module implementation unit. 34 | # Reads 'MyModule.ifc'. 35 | cl -std:c++20 -c mymodule_impl.cpp 36 | 37 | if ! $USE_IMPL_PARTITION; then 38 | # Module implementation unit (for partition symbols). 39 | # Reads 'MyModule.ifc'. 40 | cl -std:c++20 -c mymodule_part_impl.cpp 41 | fi 42 | 43 | # Module consumer. 44 | # Reads 'MyModule.ifc'. 45 | cl -std:c++20 -c main.cpp 46 | 47 | # Link the executable. It only needs the object files. 48 | link -out:main.exe \ 49 | mymodule.obj \ 50 | mymodule_impl.obj \ 51 | mymodule_part.obj \ 52 | mymodule_part_impl.obj \ 53 | mymodule_part_internal.obj \ 54 | main.obj 55 | -------------------------------------------------------------------------------- /header-units/external/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Add an interface library which declares an importable header. 2 | add_library(exthdrs INTERFACE) 3 | target_cxx_modules(exthdrs 4 | INTERFACE 5 | # The `extlib/header.hpp` header is importable via `import 6 | # ;` or `import "extlib/header.hpp";` 7 | "/usr/include/extlib/header.hpp=,\"extlib/header.hpp\"") 8 | # XXX: This is currently not supported by CMake since `INTERFACE` libraries may 9 | # only have `INTERFACE` properties. However, with modules, CMake may need to 10 | # add rules to imported and/or interface targets, so non-`INTERFACE` properties 11 | # now have a use case. 12 | target_compile_definitions(exthdrs 13 | PRIVATE 14 | # Compiling these header units should use this preprocessor definition. 15 | EXTLIB_AS_MODULE) 16 | 17 | # Add an interface library which has modules associated with it. 18 | add_library(extmods IMPORTED INTERFACE) 19 | target_cxx_modules(extmods 20 | INTERFACE 21 | # The `extmod` module is importable. It is created from the module 22 | # interface unit `extmod.miu`. 23 | "/usr/lib/cxx-modules/extmod/extmod.miu=extmod" 24 | # This module is available, but not used, so a BMI should not be 25 | # created. 26 | "/usr/lib/cxx-modules/extmod/notused.miu=notused") 27 | 28 | # The scanning of this step will add dynamic dependencies to the modules 29 | # declared in the referenced targets. Without this, the above modules would 30 | # *not* have BMIs created there are no references to them. 31 | add_library(use-ext-mods SHARED 32 | module.mpp) 33 | target_link_libraries(use-ext-mods 34 | PRIVATE 35 | exthdrs 36 | extmods) 37 | -------------------------------------------------------------------------------- /named/build-gnu.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -x 5 | 6 | "${BASH_SOURCE%/*}/clean.bash" 7 | 8 | # https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Modules.html 9 | # A project-specific mapper is expected to be provided by the build system that invokes the compiler. 10 | # The default mapper generates CMI files in a `gcm.cache` directory. CMI files have a `.gcm` suffix. 11 | # 12 | # -fmodule-mapper= 13 | # A mapping file consisting of space-separated module-name, filename pairs, one per line. 14 | 15 | # Module partition. 16 | # Writes 'gcm.cache/MyModule-part.gcm'. 17 | g++-11 -x c++ -std=c++20 -fmodules-ts -c mymodule_part.cpp 18 | 19 | # Module partition (internal). 20 | # Reads 'gcm.cache/MyModule-part.gcm'. 21 | # Writes 'gcm.cache/MyModule-part_internal.gcm' even with no exports. 22 | g++-11 -x c++ -std=c++20 -fmodules-ts -c mymodule_part_internal.cpp 23 | 24 | # Module interface unit. 25 | # Reads 'gcm.cache/MyModule-part.gcm'. 26 | # Reads 'gcm.cache/MyModule-part_internal.gcm'. 27 | # Writes 'gcm.cache/MyModule.gcm'. 28 | g++-11 -x c++ -std=c++20 -fmodules-ts -c mymodule.cpp 29 | 30 | # Module implementation unit. 31 | # Reads 'gcm.cache/MyModule.gcm'. 32 | g++-11 -x c++ -std=c++20 -fmodules-ts -c mymodule_impl.cpp 33 | 34 | # Module implementation unit (for partition symbols). 35 | # Reads 'gcm.cache/MyModule.gcm'. 36 | g++-11 -x c++ -std=c++20 -fmodules-ts -c mymodule_part_impl.cpp 37 | 38 | # Module consumer. 39 | # Reads 'gcm.cache/MyModule.gcm'. 40 | g++-11 -x c++ -std=c++20 -fmodules-ts -c main.cpp 41 | 42 | # Link the executable. It only needs the object files. 43 | g++-11 -o main \ 44 | mymodule.o \ 45 | mymodule_impl.o \ 46 | mymodule_part.o \ 47 | mymodule_part_impl.o \ 48 | mymodule_part_internal.o \ 49 | main.o 50 | -------------------------------------------------------------------------------- /named/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.23) 2 | project(cxx-modules-examples CXX) 3 | 4 | set(CMAKE_CXX_STANDARD 20) 5 | 6 | add_library(with_named_modules) 7 | target_sources(with_named_modules 8 | PRIVATE 9 | mymodule_impl.cpp 10 | mymodule_part_impl.cpp 11 | main.cpp 12 | PUBLIC 13 | FILE_SET cxx_modules TYPE CXX_MODULES FILES 14 | mymodule_part.cpp 15 | mymodule.cpp 16 | FILE_SET cxx_modules_internals TYPE CXX_MODULE_INTERNAL_PARTITIONS FILES 17 | mymodule_part_internal.cpp) 18 | 19 | install(TARGETS with_named_modules 20 | EXPORT with_named_modules 21 | RUNTIME 22 | DESTINATION "bin" 23 | COMPONENT "runtime" 24 | ARCHIVE 25 | DESTINATION "lib" 26 | COMPONENT "development" 27 | LIBRARY 28 | DESTINATION "lib" 29 | COMPONENT "runtime" 30 | NAMELINK_COMPONENT "development" 31 | FILE_SET cxx_modules 32 | DESTINATION "include/cxx/cxx-modules-examples" 33 | COMPONENT "development" 34 | FILE_SET cxx_modules_internals 35 | DESTINATION "include/cxx/cxx-modules-examples" 36 | COMPONENT "development" 37 | CXX_MODULES_BMI 38 | DESTINATION "lib/${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}/$" 39 | COMPONENT "development") 40 | 41 | export( 42 | EXPORT with_named_modules 43 | NAMESPACE NS:: 44 | FILE "${CMAKE_BINARY_DIR}/lib/cmake/cxx-modules-examples/with_named_modules-targets.cmake" 45 | CXX_MODULES_DIRECTORY "with_named_modules-cxx-modules") 46 | install( 47 | EXPORT with_named_modules 48 | NAMESPACE NS:: 49 | DESTINATION "lib/cmake/cxx-modules-examples" 50 | FILE "with_named_modules-targets.cmake" 51 | CXX_MODULES_DIRECTORY "with_named_modules-cxx-modules" 52 | COMPONENT "development") 53 | -------------------------------------------------------------------------------- /.github/workflows/cmake.yml: -------------------------------------------------------------------------------- 1 | name: CMake 2 | on: 3 | push: 4 | branches: master 5 | pull_request: 6 | types: [opened, reopened, synchronize] 7 | jobs: 8 | gcc: 9 | runs-on: ubuntu-20.04 10 | container: 11 | image: benboeckel/cxx-modules-sandbox:20220419.0 12 | # Apparently the `checkout` action assumes root access. 13 | options: --user root 14 | strategy: 15 | matrix: 16 | shared: [ON, OFF] 17 | steps: 18 | - name: checkout 19 | uses: actions/checkout@v3 20 | - name: configure 21 | run: /home/modules/misc/root/cmake/bin/cmake -GNinja -DBUILD_SHARED_LIBS:BOOL=${{ matrix.shared }} -DCMAKE_MAKE_PROGRAM:FILEPATH=/home/modules/misc/root/cmake/bin/ninja -S. -Bbuild 22 | env: 23 | CC: /home/modules/misc/root/gcc/bin/gcc 24 | CXX: /home/modules/misc/root/gcc/bin/g++ 25 | - name: build 26 | run: /home/modules/misc/root/cmake/bin/cmake --build build 27 | - name: test 28 | run: /home/modules/misc/root/cmake/bin/ctest --test-dir build 29 | msvc2022: 30 | runs-on: windows-2022 31 | strategy: 32 | matrix: 33 | shared: [ON, OFF] 34 | steps: 35 | - name: checkout 36 | uses: actions/checkout@v3 37 | - name: download/cmake 38 | run: powershell -ExecutionPolicy Bypass -File ${{ github.workspace }}/.github/ci/cmake.ps1 39 | - name: Visual Studio toolchain environment 40 | uses: TheMrMilchmann/setup-msvc-dev@v1 41 | with: 42 | arch: x64 43 | - name: configure 44 | run: ${{ github.workspace }}/.github/cmake/bin/cmake -GNinja -DBUILD_SHARED_LIBS:BOOL=${{ matrix.shared }} -S. -Bbuild 45 | - name: build 46 | run: ${{ github.workspace }}/.github/cmake/bin/cmake --build build 47 | - name: test 48 | run: ${{ github.workspace }}/.github/cmake/bin/ctest --test-dir build 49 | -------------------------------------------------------------------------------- /named/build-msvc-moddir.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -x 5 | 6 | "${BASH_SOURCE%/*}/clean.bash" 7 | 8 | # https://devblogs.microsoft.com/cppblog/using-cpp-modules-in-msvc-from-the-command-line-part-1/ 9 | 10 | mkdir mod 11 | 12 | # Try again with explicit module directory. 13 | # The `-ifcOutput` flag can take a directory or a file path like `dir/filename.ifc`. 14 | 15 | # Set to 'true' to try "module implementation partition" offered by MSVC but not in the standard. 16 | USE_IMPL_PARTITION=false 17 | 18 | # Module partition. 19 | # Writes 'mod/MyModule-part.ifc'. 20 | cl -std:c++20 -interface -ifcOutput mod/ -c mymodule_part.cpp 21 | 22 | # Module implementation partition. 23 | # Reads 'mod/MyModule-part.ifc'. 24 | if $USE_IMPL_PARTITION; then 25 | cl -std:c++20 -ifcSearchDir mod/ -c mymodule_part_impl.cpp -DUSE_IMPL_PARTITION 26 | fi 27 | 28 | # Module partition (internal). 29 | # Writes 'mod/MyModule-part_internal.ifc' 30 | cl -std:c++20 -internalPartition -ifcOutput mod/ -c mymodule_part_internal.cpp 31 | 32 | # Module interface unit. 33 | # Reads 'mod/MyModule-part.ifc'. 34 | # Reads 'mod/MyModule-part_internal.ifc'. 35 | # Writes 'mod/MyModule.ifc'. 36 | cl -std:c++20 -ifcSearchDir mod/ -ifcOutput mod/ -interface -c mymodule.cpp 37 | 38 | # Module implementation unit. 39 | # Reads 'mod/MyModule.ifc'. 40 | cl -std:c++20 -ifcSearchDir mod/ -c mymodule_impl.cpp 41 | 42 | if ! $USE_IMPL_PARTITION; then 43 | # Module implementation unit (for partition symbols). 44 | # Reads 'mod/MyModule.ifc'. 45 | cl -std:c++20 -ifcSearchDir mod/ -c mymodule_part_impl.cpp 46 | fi 47 | 48 | # Module consumer. 49 | # Reads 'mod/MyModule.ifc'. 50 | cl -std:c++20 -ifcSearchDir mod/ -c main.cpp 51 | 52 | # Link the executable. It only needs the object files. 53 | link -out:main.exe \ 54 | mymodule.obj \ 55 | mymodule_impl.obj \ 56 | mymodule_part.obj \ 57 | mymodule_part_impl.obj \ 58 | mymodule_part_internal.obj \ 59 | main.obj 60 | 61 | # The -reference argument can be repeated, and forms a module map. 62 | # For example: `-reference m=m.ifc -reference m:part=m-part.ifc` 63 | -------------------------------------------------------------------------------- /named/build-gnu-moddir.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -x 5 | 6 | "${BASH_SOURCE%/*}/clean.bash" 7 | 8 | # https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Modules.html 9 | # A project-specific mapper is expected to be provided by the build system that invokes the compiler. 10 | # The default mapper generates CMI files in a `gcm.cache` directory. CMI files have a `.gcm` suffix. 11 | # 12 | # -fmodule-mapper= 13 | # A mapping file consisting of space-separated module-name, filename pairs, one per line. 14 | 15 | mkdir mod 16 | 17 | # Try again with explicit module map file. 18 | echo " 19 | MyModule mod/MyModule.gcm 20 | MyModule:part mod/MyModule-part.gcm 21 | MyModule:part_internal mod/MyModule-part_internal.gcm 22 | "> module.modmap.txt 23 | 24 | # Module partition. 25 | # Writes 'mod/MyModule-part.gcm'. 26 | g++-11 -x c++ -std=c++20 -fmodules-ts -fmodule-mapper=module.modmap.txt -c mymodule_part.cpp 27 | 28 | # Module partition (internal). 29 | # Reads 'mod/MyModule-part.gcm'. 30 | # Writes 'mod/MyModule-part_internal.gcm' even with no exports. 31 | g++-11 -x c++ -std=c++20 -fmodules-ts -fmodule-mapper=module.modmap.txt -c mymodule_part_internal.cpp 32 | 33 | 34 | # Module interface unit. 35 | # Reads 'mod/MyModule-part.gcm'. 36 | # Reads 'mod/MyModule-part_internal.gcm'. 37 | # Writes 'mod/MyModule.gcm'. 38 | g++-11 -x c++ -std=c++20 -fmodules-ts -fmodule-mapper=module.modmap.txt -c mymodule.cpp 39 | 40 | # Module implementation unit. 41 | # Reads 'mod/MyModule.gcm'. 42 | g++-11 -x c++ -std=c++20 -fmodules-ts -fmodule-mapper=module.modmap.txt -c mymodule_impl.cpp 43 | 44 | # Module implementation unit (for partition symbols). 45 | # Reads 'mod/MyModule.gcm'. 46 | g++-11 -x c++ -std=c++20 -fmodules-ts -fmodule-mapper=module.modmap.txt -c mymodule_part_impl.cpp 47 | 48 | # Module consumer. 49 | # Reads 'mod/MyModule.gcm'. 50 | g++-11 -x c++ -std=c++20 -fmodules-ts -fmodule-mapper=module.modmap.txt -c main.cpp 51 | 52 | # Link the executable. It only needs the object files. 53 | g++-11 -o main \ 54 | mymodule.o \ 55 | mymodule_impl.o \ 56 | mymodule_part.o \ 57 | mymodule_part_impl.o \ 58 | mymodule_part_internal.o \ 59 | main.o 60 | -------------------------------------------------------------------------------- /named/scan-msvc.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -x 5 | 6 | "${BASH_SOURCE%/*}/clean.bash" 7 | 8 | # Set to 'true' to try "module implementation partition" offered by MSVC but not in the standard. 9 | USE_IMPL_PARTITION=false 10 | 11 | # Module partition. 12 | # primary-output: mymodule_part.obj 13 | # outputs: MyModule-part.ifc 14 | # provides: MyModule:part 15 | cl -std:c++20 -scanDependencies mymodule_part-default.json -c mymodule_part.cpp 16 | cl -std:c++20 -interface -scanDependencies mymodule_part-interface.json -c mymodule_part.cpp 17 | 18 | # Module implementation partition. 19 | # primary-output: mymodule_part_impl.obj 20 | # outputs: MyModule-part.ifc 21 | # provides: MyModule:part 22 | # The json file cannot be distinguished from the main module partition in 'mymodule_part.cpp'. 23 | # It should look more like the result for a module implementation unit (mymodule_impl.cpp): 24 | # primary-output: mymodule_part_impl.obj 25 | # requires: MyModule:part 26 | if $USE_IMPL_PARTITION; then 27 | cl -std:c++20 -scanDependencies mymodule_part_impl-default.json -c mymodule_part_impl.cpp -DUSE_IMPL_PARTITION 28 | fi 29 | 30 | # Module partition (internal). 31 | # primary-output: mymodule_part_internal.obj 32 | # outputs: MyModule-part_internal.ifc 33 | # provides: MyModule:part_internal 34 | cl -std:c++20 -scanDependencies mymodule_part_internal-default.json -c mymodule_part_internal.cpp 35 | cl -std:c++20 -scanDependencies mymodule_part_internal-internalPartition.json -internalPartition -c mymodule_part_internal.cpp 36 | 37 | # Module interface unit. 38 | # primary-output: mymodule.obj 39 | # outputs: MyModule.ifc 40 | # provides: MyModule 41 | # requires: MyModule:part MyModule:part_internal 42 | cl -std:c++20 -scanDependencies mymodule-default.json -c mymodule.cpp 43 | cl -std:c++20 -scanDependencies mymodule-interface.json -interface -c mymodule.cpp 44 | 45 | # Module implementation unit. 46 | # primary-output: mymodule_impl.obj 47 | # requires: MyModule 48 | cl -std:c++20 -scanDependencies mymodule_impl-default.json -c mymodule_impl.cpp 49 | 50 | if ! $USE_IMPL_PARTITION; then 51 | cl -std:c++20 -scanDependencies mymodule_part_impl-default.json -c mymodule_part_impl.cpp 52 | fi 53 | 54 | # Module consumer. 55 | # primary-output: main.obj 56 | # requires: MyModule 57 | cl -std:c++20 -scanDependencies main-default.json -c main.cpp 58 | -------------------------------------------------------------------------------- /good-scanner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(good-scanner) 2 | generate_export_header(good-scanner) 3 | target_sources(good-scanner 4 | PRIVATE 5 | # These should trip up `sed`-level scanners. 6 | header-import.mpp 7 | macro-messiness.mpp 8 | import.mpp 9 | export.mpp 10 | PUBLIC 11 | FILE_SET headers TYPE HEADERS 12 | BASE_DIRS 13 | "${CMAKE_CURRENT_BINARY_DIR}" 14 | FILES 15 | "${CMAKE_CURRENT_BINARY_DIR}/good-scanner_export.h" 16 | FILE_SET cxx_modules TYPE CXX_MODULES FILES 17 | # Simple modules for use in other sources. 18 | mod.mpp 19 | other.mpp) 20 | 21 | add_executable(define-mod 22 | define.mpp) 23 | target_compile_definitions(define-mod 24 | PRIVATE 25 | DEFINE=mod 26 | USE_MOD) 27 | target_link_libraries(define-mod 28 | PRIVATE 29 | good-scanner) 30 | add_test(NAME define-mod COMMAND define-mod) 31 | 32 | add_executable(define-other 33 | define.mpp) 34 | target_compile_definitions(define-other 35 | PRIVATE 36 | DEFINE=other) 37 | target_link_libraries(define-other 38 | PRIVATE 39 | good-scanner) 40 | add_test(NAME define-other COMMAND define-other) 41 | set_tests_properties(define-other 42 | PROPERTIES 43 | WILL_FAIL TRUE) 44 | 45 | add_library(export-define-x) 46 | generate_export_header(export-define-x) 47 | target_sources(export-define-x 48 | PRIVATE 49 | import-define.mpp 50 | PUBLIC 51 | FILE_SET headers TYPE HEADERS 52 | BASE_DIRS 53 | "${CMAKE_CURRENT_BINARY_DIR}" 54 | FILES 55 | "${CMAKE_CURRENT_BINARY_DIR}/export-define-x_export.h" 56 | FILE_SET cxx_modules TYPE CXX_MODULES FILES 57 | export-define.mpp) 58 | target_compile_definitions(export-define-x 59 | PUBLIC 60 | IS_X 61 | PRIVATE 62 | DEFINE=x) 63 | 64 | add_library(export-define-y) 65 | generate_export_header(export-define-y) 66 | target_sources(export-define-y 67 | PRIVATE 68 | import-define.mpp 69 | PUBLIC 70 | FILE_SET headers TYPE HEADERS 71 | BASE_DIRS 72 | "${CMAKE_CURRENT_BINARY_DIR}" 73 | FILES 74 | "${CMAKE_CURRENT_BINARY_DIR}/export-define-y_export.h" 75 | FILE_SET cxx_modules TYPE CXX_MODULES FILES 76 | export-define.mpp) 77 | target_compile_definitions(export-define-y 78 | PRIVATE 79 | DEFINE=y) 80 | -------------------------------------------------------------------------------- /named/build-msvc-explicit.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | set -x 4 | 5 | "${BASH_SOURCE%/*}/clean.bash" 6 | 7 | # https://devblogs.microsoft.com/cppblog/using-cpp-modules-in-msvc-from-the-command-line-part-1/ 8 | 9 | # Set to 'true' to try "module implementation partition" offered by MSVC but not in the standard. 10 | USE_IMPL_PARTITION=false 11 | 12 | mkdir mod 13 | 14 | # Module partition. 15 | # Writes 'mod/MyModule-part.ifc'. 16 | cl -std:c++20 -interface -c mymodule_part.cpp \ 17 | -ifcOutput mod/MyModule-part.ifc 18 | 19 | if $USE_IMPL_PARTITION; then 20 | # Module implementation partition (MSVC-specific). 21 | # Reads 'mod/MyModule-part.ifc'. 22 | cl -std:c++20 -c mymodule_part_impl.cpp -DUSE_IMPL_PARTITION \ 23 | -reference MyModule:part=mod/MyModule-part.ifc 24 | fi 25 | 26 | # Module partition (internal). 27 | # Writes 'mod/MyModule-part_internal.ifc' 28 | cl -std:c++20 -internalPartition -c mymodule_part_internal.cpp \ 29 | -ifcOutput mod/MyModule-part_internal.ifc 30 | 31 | # Module interface unit. 32 | # Writes 'mod/DepModule1.ifc'. 33 | cl -std:c++20 -interface -c depmodule1.cpp \ 34 | -ifcOutput mod/DepModule1.ifc 35 | 36 | # Module interface unit. 37 | # Writes 'mod/DepModule2.ifc'. 38 | cl -std:c++20 -interface -c depmodule2.cpp \ 39 | -ifcOutput mod/DepModule2.ifc 40 | 41 | # Module interface unit. 42 | # Reads 'mod/MyModule-part.ifc'. 43 | # Reads 'mod/MyModule-part_internal.ifc'. 44 | # Reads 'mod/DepModule1.ifc'. 45 | # Reads 'mod/DepModule2.ifc'. 46 | # Writes 'mod/MyModule.ifc'. 47 | cl -std:c++20 -interface -c mymodule.cpp \ 48 | -reference MyModule:part=mod/MyModule-part.ifc \ 49 | -reference MyModule:part_internal=mod/MyModule-part_internal.ifc \ 50 | -reference DepModule1=mod/DepModule1.ifc \ 51 | -reference DepModule2=mod/DepModule2.ifc \ 52 | -ifcOutput mod/MyModule.ifc 53 | 54 | # Module implementation unit. 55 | # Reads 'mod/MyModule.ifc'. 56 | # Reads 'mod/MyModule-part.ifc' (due to MSVC by-reference model to). 57 | # Reads 'mod/MyModule-part_internal.ifc' (due to MSVC by-reference model to). 58 | # Reads 'mod/DepModule1.ifc'. 59 | # Reads 'mod/DepModule2.ifc'. 60 | cl -std:c++20 -c mymodule_impl.cpp \ 61 | -reference MyModule=mod/MyModule.ifc \ 62 | -reference MyModule:part=mod/MyModule-part.ifc \ 63 | -reference MyModule:part_internal=mod/MyModule-part_internal.ifc \ 64 | -reference DepModule1=mod/DepModule1.ifc \ 65 | -reference DepModule2=mod/DepModule2.ifc 66 | 67 | if ! $USE_IMPL_PARTITION; then 68 | # Module implementation unit (for partition symbols). 69 | # Reads 'mod/MyModule.ifc'. 70 | # Reads 'mod/MyModule-part.ifc' (due to MSVC by-reference model to). 71 | # Reads 'mod/MyModule-part_internal.ifc' (due to MSVC by-reference model to). 72 | # Reads 'mod/DepModule1.ifc'. 73 | # Reads 'mod/DepModule2.ifc'. 74 | cl -std:c++20 -c mymodule_part_impl.cpp \ 75 | -reference MyModule=mod/MyModule.ifc \ 76 | -reference MyModule:part=mod/MyModule-part.ifc \ 77 | -reference MyModule:part_internal=mod/MyModule-part_internal.ifc \ 78 | -reference DepModule1=mod/DepModule1.ifc \ 79 | -reference DepModule2=mod/DepModule2.ifc 80 | fi 81 | 82 | # Module consumer. 83 | # Reads 'mod/MyModule.ifc'. 84 | # Reads 'mod/MyModule-part.ifc' (due to MSVC by-reference model to). 85 | # Reads 'mod/DepModule1.ifc'. 86 | # Does not read 'mod/DepModule2.ifc' (unlike GCC, which does read it). 87 | cl -std:c++20 -c main.cpp \ 88 | -reference MyModule=mod/MyModule.ifc \ 89 | -reference MyModule:part=mod/MyModule-part.ifc \ 90 | -reference DepModule1=mod/DepModule1.ifc 91 | 92 | # Link the executable. It only needs the object files. 93 | link -out:main.exe \ 94 | mymodule.obj \ 95 | mymodule_impl.obj \ 96 | mymodule_part.obj \ 97 | mymodule_part_impl.obj \ 98 | mymodule_part_internal.obj \ 99 | depmodule1.obj \ 100 | depmodule2.obj \ 101 | main.obj 102 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------