Skip to content

Use out-of-source directory for .mod files by default #231

Closed
@apthorpe

Description

@apthorpe

This is an enhancement request related to both #176 and #187

By default the linter runs gfortran against source code in the directory where it is found, generating .mod files in those directories. This works fine until you use an out-of-source build system like CMake. The .mod files written by the linter into the source tree interfere with compilation and linking under CMake and complicate version control.

The workaround is to manually tell the linter to write .mod files to a separate out-of-source directory and to include that directory for the linter's use.

An example: For a project with the base directory C:/Users/me/Documents/git_projects/my_project, I will create the directory .fmod under the project root (C:/Users/me/Documents/git_projects/my_project/.fmod). I then modify the workspace's settings.json to add:

    "fortran.linterExtraArgs": [
        "-JC:/Users/me/Documents/git_projects/my_project/.fmod"
    ],
    "fortran.includePaths": [
        "C:/Users/me/Documents/git_projects/my_project/.fmod"
    ],

This gives me the benefit of linting and syntax checking while keeping temporary files out of my source directory.

The big problem is that I have to manually configure every project like this if I want to use both CMake and Fortran linting.

It seems like this could be easily solved by setting the default configuration to something like:

    "fortran.linterExtraArgs": [
        "-J${workspaceFolder}/.fmod"
    ],
    "fortran.includePaths": [
        "${workspaceFolder}/.fmod"
    ],

The directory .fmod needs to be created. There may be issues using a single directory to store files generated from a source tree if the source tree contains multiple files with the same name. In that case, replicate the source directory structure under .fmod. That is, for the source directory ${workspaceFolder}/.fmod/src/tree, set the include path and -J path to ${workspaceFolder}/.fmod/src/tree. This is slightly more complex but would solve the problem for projects with multilevel source directories, the sort of complex projects CMake was designed to manage.

If #176 adds ${workspaceFolder} support, this change would be an invisible resolution of #187.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions