Skip to content

Commit

Permalink
write C++ modules summary
Browse files Browse the repository at this point in the history
  • Loading branch information
bkietz committed Nov 15, 2024
1 parent 3b4282c commit 58d0759
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 148 deletions.
46 changes: 0 additions & 46 deletions build.rst

This file was deleted.

23 changes: 15 additions & 8 deletions cmake_modules/Maud.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,12 @@ function(_maud_scan source_file)
message(VERBOSE " attaching to ${target_name}")

set_property(TARGET ${target_name} APPEND PROPERTY MAUD_IMPORTS "${imports}")
set_target_properties(${target_name} PROPERTIES MAUD_SCANNED ON)
set_target_properties(
${target_name}
PROPERTIES
MAUD_SCANNED ON
MAUD_MODULE "${module}"
)
target_compile_features(
${target_name}
PUBLIC
Expand Down Expand Up @@ -533,7 +538,7 @@ function(_maud_add_test source_file out_target_name)
add_test(NAME test_.${name} COMMAND $<TARGET_FILE:test_.${name}> --gtest_brief=1)
target_sources(
test_.${name}
PRIVATE
PUBLIC
FILE_SET module_providers
TYPE CXX_MODULES
${_MAUD_BASE_DIRS}
Expand All @@ -542,7 +547,6 @@ function(_maud_add_test source_file out_target_name)
set_target_properties(
test_.${name}
PROPERTIES
MAUD_INTERFACE "${_MAUD_SELF_DIR}/test_.cxx"
COMPILE_OPTIONS "${_MAUD_INCLUDE} ${_MAUD_SELF_DIR}/test_.hxx"
)
endfunction()
Expand Down Expand Up @@ -611,6 +615,10 @@ function(_maud_finalize_targets)
if(NOT imports)
set(imports "")
endif()
get_target_property(module ${target} MAUD_MODULE)
if(module AND target_type STREQUAL "EXECUTABLE")
list(APPEND imports "${module}")
endif()
message(VERBOSE " IMPORTS: ${imports}")

# Link targets to imported modules
Expand All @@ -629,10 +637,9 @@ function(_maud_finalize_targets)
endforeach()

get_target_property(interface ${target} MAUD_INTERFACE)
if(NOT interface)
if(NOT interface AND NOT TEST ${target})
if(target_type STREQUAL "EXECUTABLE")
set(interface "${_MAUD_SELF_DIR}/executable.cxx")
set(source_access PRIVATE)
else()
get_target_property(src ${target} MAUD_INTERFACE_PARTITIONS)
set(interface "${MAUD_DIR}/injected/${target}.cxx")
Expand All @@ -644,18 +651,18 @@ function(_maud_finalize_targets)
PROPERTIES
MAUD_TYPE INTERFACE
)
set(source_access PUBLIC)
message(VERBOSE " No primary interface supplied, injecting ${interface}")
endif()
target_sources(
${target}
${source_access}
PUBLIC
FILE_SET module_providers
TYPE CXX_MODULES
${_MAUD_BASE_DIRS}
FILES "${interface}"
)
endif()

print_target_sources(${target})

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

target_sources(
${target}
PRIVATE
PUBLIC
FILE_SET module_providers
TYPE CXX_MODULES
BASE_DIRS ${_MAUD_BASE_DIRS}
Expand Down
69 changes: 0 additions & 69 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,75 +68,6 @@ configuration options:
Read more about :ref:`options`.

Preprocessing
-------------

By default, maud uses a custom module scanner which ignores preprocessing
for efficiency and stops reading source files after the import declarations.
This works in the most common case where the preprocessor only encounters
``#include`` directives and an occasional ``#define``, which leaves
the module dependency graph unaffected. However it is possible for the
preprocessor to affect module and import declarations. For example:

- an import declaration could be inside a conditional preprocessing block

.. code-block:: cpp
module foo;
#if BAR_VERSION >= 3
import bar;
#endif
- a set of import declarations could be included

.. code-block:: cpp
module foo;
#include "common_imports.hxx"
- a macro could expand to a pragma directive which modifies an ``#include``

.. code-block:: cpp
module;
#include "macros.hxx"
PUSH_INGORED_WARNING(-Wunused-variable);
#include "dodgy.hxx"
POP_INGORED_WARNING();
module foo;
- a macro could be used to derive the name of the module

.. code-block:: cpp
module;
#include "macros.hxx"
module PP_CAT(foo_, FOO_VERSION);
(I'm actually not sure that the last two are even legal since a global
module fragment should exclusively contain preprocessing directives
:cxx20:`module.global.frag#1`, however clang allows both.)

IMHO, it is not desirable to write interface blocks which depend on preprocessing.
Moreover C++26 will restrict usage of the preprocessor severely in module declarations
as described in `P3034R1 <https://isocpp.org/files/papers/P3034R1.html>`_.

.. _maud-preprocessing-scan-options:

For source files which require it, the property ``MAUD_PREPROCESSING_SCAN_OPTIONS``
can be set in cmake. This property should contain all compile options
necessary to correctly preprocess the source file, for example
``-I /home/i/foo/include -isystem /home/i/boost/include -DFOO_ENABLE_BAR=1``.

Note that the output of these tools is in the JSON format described by `p1689
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1689r5.html>`_
and does not distinguish between a module implementation unit of ``foo`` from a
source file which happens to import ``foo``. Without information about which module
an implementation unit is associated with, it cannot be automatically added to
the corresponding target. As a workaround if you must have a preprocessing scan
of an implementation unit, you can split the implementation unit into partitions
whose primary module is exposed.

Built-in support for generated files
------------------------------------

Expand Down
Loading

0 comments on commit 58d0759

Please sign in to comment.