Skip to content

Commit 58d0759

Browse files
committed
write C++ modules summary
1 parent 3b4282c commit 58d0759

File tree

7 files changed

+248
-148
lines changed

7 files changed

+248
-148
lines changed

build.rst

Lines changed: 0 additions & 46 deletions
This file was deleted.

cmake_modules/Maud.cmake

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,12 @@ function(_maud_scan source_file)
456456
message(VERBOSE " attaching to ${target_name}")
457457

458458
set_property(TARGET ${target_name} APPEND PROPERTY MAUD_IMPORTS "${imports}")
459-
set_target_properties(${target_name} PROPERTIES MAUD_SCANNED ON)
459+
set_target_properties(
460+
${target_name}
461+
PROPERTIES
462+
MAUD_SCANNED ON
463+
MAUD_MODULE "${module}"
464+
)
460465
target_compile_features(
461466
${target_name}
462467
PUBLIC
@@ -533,7 +538,7 @@ function(_maud_add_test source_file out_target_name)
533538
add_test(NAME test_.${name} COMMAND $<TARGET_FILE:test_.${name}> --gtest_brief=1)
534539
target_sources(
535540
test_.${name}
536-
PRIVATE
541+
PUBLIC
537542
FILE_SET module_providers
538543
TYPE CXX_MODULES
539544
${_MAUD_BASE_DIRS}
@@ -542,7 +547,6 @@ function(_maud_add_test source_file out_target_name)
542547
set_target_properties(
543548
test_.${name}
544549
PROPERTIES
545-
MAUD_INTERFACE "${_MAUD_SELF_DIR}/test_.cxx"
546550
COMPILE_OPTIONS "${_MAUD_INCLUDE} ${_MAUD_SELF_DIR}/test_.hxx"
547551
)
548552
endfunction()
@@ -611,6 +615,10 @@ function(_maud_finalize_targets)
611615
if(NOT imports)
612616
set(imports "")
613617
endif()
618+
get_target_property(module ${target} MAUD_MODULE)
619+
if(module AND target_type STREQUAL "EXECUTABLE")
620+
list(APPEND imports "${module}")
621+
endif()
614622
message(VERBOSE " IMPORTS: ${imports}")
615623

616624
# Link targets to imported modules
@@ -629,10 +637,9 @@ function(_maud_finalize_targets)
629637
endforeach()
630638

631639
get_target_property(interface ${target} MAUD_INTERFACE)
632-
if(NOT interface)
640+
if(NOT interface AND NOT TEST ${target})
633641
if(target_type STREQUAL "EXECUTABLE")
634642
set(interface "${_MAUD_SELF_DIR}/executable.cxx")
635-
set(source_access PRIVATE)
636643
else()
637644
get_target_property(src ${target} MAUD_INTERFACE_PARTITIONS)
638645
set(interface "${MAUD_DIR}/injected/${target}.cxx")
@@ -644,18 +651,18 @@ function(_maud_finalize_targets)
644651
PROPERTIES
645652
MAUD_TYPE INTERFACE
646653
)
647-
set(source_access PUBLIC)
648654
message(VERBOSE " No primary interface supplied, injecting ${interface}")
649655
endif()
650656
target_sources(
651657
${target}
652-
${source_access}
658+
PUBLIC
653659
FILE_SET module_providers
654660
TYPE CXX_MODULES
655661
${_MAUD_BASE_DIRS}
656662
FILES "${interface}"
657663
)
658664
endif()
665+
659666
print_target_sources(${target})
660667

661668
if(TEST ${target} AND NOT COMMAND "maud_add_test")
@@ -669,7 +676,7 @@ function(_maud_finalize_targets)
669676

670677
target_sources(
671678
${target}
672-
PRIVATE
679+
PUBLIC
673680
FILE_SET module_providers
674681
TYPE CXX_MODULES
675682
BASE_DIRS ${_MAUD_BASE_DIRS}

index.rst

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -68,75 +68,6 @@ configuration options:
6868
6969
Read more about :ref:`options`.
7070

71-
Preprocessing
72-
-------------
73-
74-
By default, maud uses a custom module scanner which ignores preprocessing
75-
for efficiency and stops reading source files after the import declarations.
76-
This works in the most common case where the preprocessor only encounters
77-
``#include`` directives and an occasional ``#define``, which leaves
78-
the module dependency graph unaffected. However it is possible for the
79-
preprocessor to affect module and import declarations. For example:
80-
81-
- an import declaration could be inside a conditional preprocessing block
82-
83-
.. code-block:: cpp
84-
85-
module foo;
86-
#if BAR_VERSION >= 3
87-
import bar;
88-
#endif
89-
90-
- a set of import declarations could be included
91-
92-
.. code-block:: cpp
93-
94-
module foo;
95-
#include "common_imports.hxx"
96-
97-
- a macro could expand to a pragma directive which modifies an ``#include``
98-
99-
.. code-block:: cpp
100-
101-
module;
102-
#include "macros.hxx"
103-
PUSH_INGORED_WARNING(-Wunused-variable);
104-
#include "dodgy.hxx"
105-
POP_INGORED_WARNING();
106-
module foo;
107-
108-
- a macro could be used to derive the name of the module
109-
110-
.. code-block:: cpp
111-
112-
module;
113-
#include "macros.hxx"
114-
module PP_CAT(foo_, FOO_VERSION);
115-
116-
(I'm actually not sure that the last two are even legal since a global
117-
module fragment should exclusively contain preprocessing directives
118-
:cxx20:`module.global.frag#1`, however clang allows both.)
119-
120-
IMHO, it is not desirable to write interface blocks which depend on preprocessing.
121-
Moreover C++26 will restrict usage of the preprocessor severely in module declarations
122-
as described in `P3034R1 <https://isocpp.org/files/papers/P3034R1.html>`_.
123-
124-
.. _maud-preprocessing-scan-options:
125-
126-
For source files which require it, the property ``MAUD_PREPROCESSING_SCAN_OPTIONS``
127-
can be set in cmake. This property should contain all compile options
128-
necessary to correctly preprocess the source file, for example
129-
``-I /home/i/foo/include -isystem /home/i/boost/include -DFOO_ENABLE_BAR=1``.
130-
131-
Note that the output of these tools is in the JSON format described by `p1689
132-
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1689r5.html>`_
133-
and does not distinguish between a module implementation unit of ``foo`` from a
134-
source file which happens to import ``foo``. Without information about which module
135-
an implementation unit is associated with, it cannot be automatically added to
136-
the corresponding target. As a workaround if you must have a preprocessing scan
137-
of an implementation unit, you can split the implementation unit into partitions
138-
whose primary module is exposed.
139-
14071
Built-in support for generated files
14172
------------------------------------
14273

0 commit comments

Comments
 (0)