# Curious problem with CMake - related to the Feq-parse project

**URL:** <https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915>\
**Category:** Help\
**Created:** [December 4, 2023, 9:17am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915 "2023-12-04T09:17:34Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [December 4, 2023, 9:17am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/1 "2023-12-04T09:17:34Z")

</div>

I have been experimenting with the feq-parse project by @fluidnumerics_joe and stumbled on some peculiarities. One of them is that the Visual Studio solution that I created via CMake fails to build in one go. The first time the compiler complains about four source files in the test directory whereas it is happy with all the others there. The complaint is that the module file for FEQparse is not found. But it is apparently found for all the others. After building a second time it works fine.

The problem is: all the options are equal for all the files in the test directory. I can find no reason whatsoever for that behaviour wrt the four files. I suspected first something regarding parallel builds and race conditions, but as the set of files about which the compiler complains is always the same, I very much doubt this is the cause.

Does anyone have any idea where to look for the problem (or rather the solution)?

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 4, 2023, 9:33am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/2 "2023-12-04T09:33:44Z")

</div>

> [@Arjen](#):
>
> After building a second time it works fine.

Same problem with `fpm test`:

```bash
$ fpm test
 + mkdir -p build/dependencies
FEQParse_Functions.F90 done.
FEQParse_FloatStacks.F90 done.
FEQParse_TokenStack.F90 done.
test.f90 failed.
[2%] Compiling...
abs_r1fp32.f90:3:7:

Fatal Error: Cannot open module file ‘feqparse.mod’ for reading at (1): Aucun fichier ou dossier de ce type
compilation terminated.
<ERROR> Compilation failed for object " test_test.f90.o "
<ERROR> stopping due to failed compilation
STOP 1
$ fpm test
FEQParse.F90 done.
test.f90 done.
libfeq-parse.a done.
linear_r2fp64.f90 done.
sin_r2fp32.f90 done.
sech_sfp64.f90 done.
log_r2fp64.f90 done.
sqrt_r2fp64.f90 done.
gaussian3d_r3fp32.f90 done.
asin_r3fp64.f90 done.
...

```

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [December 4, 2023, 9:57am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/3 "2023-12-04T09:57:58Z")

</div>

Hm, thanks for this! It is a different file, but there does seem to be a dependency issue, which is independent of the build method (no pun intended).

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 4, 2023, 10:23am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/4 "2023-12-04T10:23:01Z")

</div>

Could it be related to those `include` statements in `test/tests.f90` ? :

```fortran
...
    contains

    include "abs_r1fp32.f90"
    include "abs_r1fp64.f90"
    include "abs_r2fp32.f90"
...

```

Each test file has a `use FEQParse`.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [December 4, 2023, 10:56am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/5 "2023-12-04T10:56:28Z")

</div>

Hm, my guess is that fpm does not see the dependency via the included files. Could be fixed by adding a use statement in test.f90. In the VS case I get a complaint for four source files and not for all the other ones. Each is compiled independently.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 4, 2023, 11:17am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/6 "2023-12-04T11:17:39Z")

</div>

> [@Arjen](#):
>
> Could be fixed by adding a use statement in test.f90.

Yes, it then works with fpm.

---

<div class="post-metadata">

**Author:** ![fluidnumerics\_joe](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fluidnumerics_joe/32/4360_2.png) [@fluidnumerics\_joe](https://fortran-lang.discourse.group/u/fluidnumerics_joe)\
**Post date:** [December 4, 2023, 11:18am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/7 "2023-12-04T11:18:55Z")

</div>

@vmagnin - what does your build environment look like ?

`fpm test` passes currently on Linux with gfortran : [[WIP] Bugfix/issue 12 · FluidNumerics/feq-parse@f2a52a4 · GitHub](https://github.com/FluidNumerics/feq-parse/actions/runs/7085706440/job/19282492805?pr=13)

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 4, 2023, 11:20am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/8 "2023-12-04T11:20:49Z")

</div>

> [@fluidnumerics\_joe](#):
>
> what does your build environment look like ?

GFortran 12.3, Ubuntu 23.04 with :

```auto
$ fpm --version
Version: 0.8.2, alpha

```

I will try to upgrade to fpm 0.9.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 4, 2023, 11:27am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/9 "2023-12-04T11:27:13Z")

</div>

No, same problem with fpm 0.9.0.

---

<div class="post-metadata">

**Author:** ![fluidnumerics\_joe](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fluidnumerics_joe/32/4360_2.png) [@fluidnumerics\_joe](https://fortran-lang.discourse.group/u/fluidnumerics_joe)\
**Post date:** [December 4, 2023, 6:32pm UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/10 "2023-12-04T18:32:41Z")

</div>

> [@vmagnin](#):
>
> `abs_r1fp32.f90:3:7:`

It’d be helpful to see any verbose output from FPM… however, from this output it looks like `src/FEQParse.F90` is not compiled on the first go-around. If you run `fpm install` followed by `fpm test`, I suppose it would work ?

---

<div class="post-metadata">

**Author:** ![fluidnumerics\_joe](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fluidnumerics_joe/32/4360_2.png) [@fluidnumerics\_joe](https://fortran-lang.discourse.group/u/fluidnumerics_joe)\
**Post date:** [December 4, 2023, 6:47pm UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/11 "2023-12-04T18:47:27Z")

</div>

@vmagnin - I’ve added the `use FEQParse` statement to the top of `test.f90` in the [bugfix/issue-12 branch](https://github.com/FluidNumerics/feq-parse/tree/bugfix/issue-12) branch; this does cause `fpm` to build `src/FEQParse.f90` before any of the tests in `test/` .

@Arjen - what version of CMake are you working with ?

---

<div class="post-metadata">

**Author:** ![fluidnumerics\_joe](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fluidnumerics_joe/32/4360_2.png) [@fluidnumerics\_joe](https://fortran-lang.discourse.group/u/fluidnumerics_joe)\
**Post date:** [December 4, 2023, 7:19pm UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/12 "2023-12-04T19:19:31Z")

</div>

@Arjen - I’ve added a fix to the [bugfix/issue-12 branch](https://github.com/FluidNumerics/feq-parse/tree/bugfix/issue-12) that forces a dependency of the `${TARGET}_fortran` target on the `feqparse-static` target which will guarantee that everything in `src/` is compiled before starting on building anything in `test/`

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [December 4, 2023, 7:21pm UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/13 "2023-12-04T19:21:00Z")

</div>

> [@fluidnumerics\_joe](#):
>
> it looks like `src/FEQParse.F90` is not compiled on the first go-around.

Yes, that is the problem when running `fpm test` first.

> [@fluidnumerics\_joe](#):
>
> If you run `fpm install` followed by `fpm test`, I suppose it would work ?

When running first `fpm install` (or `fpm build`), `src/FEQParse.F90` is immediately built:

```bash
$ fpm install
 + mkdir -p build/dependencies
FEQParse_FloatStacks.F90 done.
FEQParse_Functions.F90 done.
FEQParse_TokenStack.F90 done.
FEQParse.F90 done.
libfeq-parse.a done.
array_with_array_eval.f90 done.
array_with_scalar_eval.f90 done.
scalar_with_scalar_eval.f90 done.
scalar_function_product.f90 done.
array_with_array_eval done.
array_with_scalar_eval done.
scalar_with_scalar_eval done.
scalar_function_product done.
[100%] Project compiled successfully.
# Update: build/gfortran_50F62D7499E64B65/feq-parse/libfeq-parse.a -> /home/vmagnin/.local/lib
 + mkdir -p /home/vmagnin/.local/include
# Update: build/gfortran_87E2AE0597D39913/feqparse_floatstacks.mod -> /home/vmagnin/.local/include
# Update: build/gfortran_87E2AE0597D39913/feqparse_functions.mod -> /home/vmagnin/.local/include
# Update: build/gfortran_87E2AE0597D39913/feqparse_tokenstack.mod -> /home/vmagnin/.local/include
# Update: build/gfortran_87E2AE0597D39913/feqparse.mod -> /home/vmagnin/.local/include
$ fpm test
random_r3fp32.f90 done.
sech_r2fp64.f90 done.
tanh_r2fp64.f90 done.
monadic_r4fp64.f90 done.
linear_r1fp32.f90 done.
...

```

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [December 4, 2023, 9:58pm UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/14 "2023-12-04T21:58:02Z")

</div>

I believe the issue with fpm is linked to: [source pre-processing prior to determining dependencies · Issue #469 · fortran-lang/fpm · GitHub](https://github.com/fortran-lang/fpm/issues/469)

fpm would need to analyse the included files to determine that the main program depends on the `FEQParse` module indirectly via the contained subroutines.

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [December 5, 2023, 6:55am UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/15 "2023-12-05T06:55:27Z")

</div>

The addition of the add\_dependencies statement helped. It now builds fine with Visual Studio.

---

<div class="post-metadata">

**Author:** ![fluidnumerics\_joe](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fluidnumerics_joe/32/4360_2.png) [@fluidnumerics\_joe](https://fortran-lang.discourse.group/u/fluidnumerics_joe)\
**Post date:** [December 6, 2023, 7:02pm UTC](https://fortran-lang.discourse.group/t/curious-problem-with-cmake-related-to-the-feq-parse-project/6915/16 "2023-12-06T19:02:07Z")

</div>

Also got this resolved with fpm, thanks to @vmagnin 's suggestion.
