Skip to content

Conversation

perazz
Copy link
Member

@perazz perazz commented Sep 9, 2025

With the introduction of features and profiles, it will be nearly impossible to avoid parsing preprocessor macro-guarded
module inclusions. This PR introduces the conditional block detection logic to properly handle nested simple conditional blocks and (case-sensitive) macro matching with the cpp preprocessor.

  • Supported syntax examples
  #ifdef FEATURE_DEBUG
      use debug_module
  #endif

  #ifndef FEATURE_RELEASE
      use development_module
  #endif

  #if defined(MY_FEATURE)
      use feature_module
  #endif

  #if !defined(OTHER_FEATURE)
      use fallback_module
      #ifdef NESTED_FEATURE
          use nested_module
      #endif
  #endif

Tests and example packages added. Closes #469.

@perazz perazz requested a review from Copilot September 9, 2025 09:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces support for parsing C preprocessor (CPP) conditional compilation directives in Fortran source files. This enables proper handling of macro-guarded module dependencies when features and profiles are used, preventing build failures when optional modules are conditionally included.

Key changes include:

  • Addition of conditional compilation parsing logic to handle nested #ifdef, #ifndef, #if defined(), and related directives
  • Integration of preprocessor configuration into source parsing routines throughout the codebase
  • Comprehensive test coverage for various conditional compilation scenarios

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/fpm_test/test_source_parsing.f90 Adds comprehensive test cases for conditional compilation parsing with both simple and complex macro scenarios
src/fpm_source_parsing.f90 Implements core CPP conditional parsing logic with nested block tracking and macro evaluation
src/fpm_sources.f90 Updates source discovery functions to accept and pass through preprocessor configuration
src/fpm.f90 Integrates preprocessor configuration into all source parsing calls throughout the build system
example_packages/program_with_cpp_guarded_module/ Provides example package demonstrating CPP conditional compilation usage
ci/run_tests.sh Adds testing of the new example package to the CI pipeline

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@perazz perazz merged commit 77bf0bb into fortran-lang:main Sep 9, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

source pre-processing prior to determining dependencies
1 participant