Here is my directory structure:
.
├── CMakeLists.txt
├── LICENSE.txt
├── README.md
├── fpm.toml
├── my_build_script.sh
├── src
│ ├── CMakeLists.txt
│ ├── yaml-cpp
│ ├── yaml.cpp
│ ├── yaml.f90
│ └── yaml_types.f90
├── test.yaml
└── tests
├── example.f90
└── test.f90
My fpm.toml:
name = "fortran-yaml-cpp"
version = "0.0.1"
license = "MIT"
author = "Nick Wogan"
maintainer = "nicholaswogan@gmail.com"
copyright = "2021 Nick Wogan"
[library]
source-dir="src"
build-script="my_build_script.sh"
[[ executable ]]
name="runTests"
source-dir="tests"
main="test.f90"
and my_build_script.sh:
mkdir cmake_build_dir
cmake -B cmake_build_dir -S . -DFPM_BUILD=ON
cmake --build cmake_build_dir -j
The idea is to do all the right things in CMakeLists.txt for fpm work when FPM_BUILD=ON.
When I run fpm build, I get the following
+ mkdir -p build/dependencies
+ mkdir -p build/gfortran_2A42023B310FA28D/fortran-yaml-cpp
+ gfortran -c ././src/yaml_types.f90 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran_2A42023B310FA28D/fortran-yaml-cpp -I build/gfortran_2A42023B310FA28D/fortran-yaml-cpp -o build/gfortran_2A42023B310FA28D/fortran-yaml-cpp/src_yaml_types.f90.o
././src/yaml_types.f90:192:40:
192 | subroutine null_dump(self,unit,indent)
| 1
Warning: Unused dummy argument 'indent' at (1) [-Wunused-dummy-argument]
././src/yaml_types.f90:192:28:
192 | subroutine null_dump(self,unit,indent)
| 1
Warning: Unused dummy argument 'self' at (1) [-Wunused-dummy-argument]
././src/yaml_types.f90:186:41:
186 | subroutine value_dump(self,unit,indent)
| 1
Warning: Unused dummy argument 'indent' at (1) [-Wunused-dummy-argument]
././src/yaml_types.f90:107:42:
107 | recursive subroutine node_finalize(self)
| 1
Warning: Unused dummy argument 'self' at (1) [-Wunused-dummy-argument]
+ gfortran -c ././src/yaml.f90 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran_2A42023B310FA28D/fortran-yaml-cpp -I build/gfortran_2A42023B310FA28D/fortran-yaml-cpp -o build/gfortran_2A42023B310FA28D/fortran-yaml-cpp/src_yaml.f90.o
././src/yaml.f90:55:37:
55 | filename_copy = filename//char(0)
| ^
Warning: '.filename_copy' may be used uninitialized [-Wmaybe-uninitialized]
+ ar -rs build/gfortran_2A42023B310FA28D/fortran-yaml-cpp/libfortran-yaml-cpp.a build/gfortran_2A42023B310FA28D/fortran-yaml-cpp/src_yaml_types.f90.o build/gfortran_2A42023B310FA28D/fortran-yaml-cpp/src_yaml.f90.o
ar: creating archive build/gfortran_2A42023B310FA28D/fortran-yaml-cpp/libfortran-yaml-cpp.a
+ gfortran -c tests/test.f90 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran_2A42023B310FA28D/fortran-yaml-cpp -I build/gfortran_2A42023B310FA28D/fortran-yaml-cpp -o build/gfortran_2A42023B310FA28D/fortran-yaml-cpp/tests_test.f90.o
+ gfortran -c tests/example.f90 -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran_2A42023B310FA28D/fortran-yaml-cpp -I build/gfortran_2A42023B310FA28D/fortran-yaml-cpp -o build/gfortran_2A42023B310FA28D/fortran-yaml-cpp/tests_example.f90.o
tests/example.f90:41:61:
41 | string = trim(dict%get_string("equation",error = io_err))
| ^
Warning: '.string' may be used uninitialized [-Wmaybe-uninitialized]
+ mkdir -p build/gfortran_2A42023B310FA28D/app/
+ gfortran -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran_2A42023B310FA28D/fortran-yaml-cpp -I build/gfortran_2A42023B310FA28D/fortran-yaml-cpp build/gfortran_2A42023B310FA28D/fortran-yaml-cpp/tests_test.f90.o build/gfortran_2A42023B310FA28D/fortran-yaml-cpp/libfortran-yaml-cpp.a -o build/gfortran_2A42023B310FA28D/app/runTests
Undefined symbols for architecture x86_64:
"_DestroyNode", referenced from:
___yaml_MOD_parse in libfortran-yaml-cpp.a(src_yaml.f90.o)
"_LoadFile_c", referenced from:
___yaml_MOD_loadfile in libfortran-yaml-cpp.a(src_yaml.f90.o)
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
<ERROR> Compilation failed for object " runTests "
<ERROR>stopping due to failed compilation
STOP 1
my_build_script.sh is never executed. Instead, fpm compiles src/yaml.f90 and src/yaml_types.f90 and does not compile src/yaml.cpp, and makes libfortran-yaml-cpp.a. Then fpm tries to build and link the executable runTests, but fails because symbols from src/yaml.cpp are not contained in libfortran-yaml-cpp.a.