Repository: spack/spack

Issue:
Installation issue: cgns (fPIC issue)
### Steps to reproduce the issue

```console
$ spack spec -lI cgns
Input spec
--------------------------------
 -   cgns

Concretized
--------------------------------
 -   m5vc5qo  cgns@4.2.0%gcc@9.4.0+base_scope+fortran+hdf5~int64+ipo+legacy~mem_debug+mpi+scoping+shared+static+testing+tools build_system=cmake build_type=RelWithDebInfo generator=make arch=linux-rhel8-zen2
[+]  kzbjptx      ^cmake@3.21.4%gcc@9.4.0~doc+ncurses+ownlibs~qt build_system=generic build_type=Release arch=linux-rhel8-zen2
[+]  2nd5xjs          ^ncurses@6.2%gcc@9.4.0+symlinks+termlib abi=5 build_system=autotools arch=linux-rhel8-zen2
[+]  acpcwrk          ^openssl@1.1.1v%gcc@9.4.0~docs+shared build_system=generic certs=system arch=linux-rhel8-zen2
[+]  p7qp44w      ^gmake@4.3%gcc@9.4.0+guile build_system=autotools patches=599f134 arch=linux-rhel8-zen2
[+]  snqs5yc          ^guile@2.2.6%gcc@9.4.0+readline build_system=autotools threads=posix arch=linux-rhel8-zen2
[+]  c26pf64              ^bdw-gc@8.0.6%gcc@9.4.0+libatomic-ops build_system=autotools threads=posix arch=linux-rhel8-zen2
[+]  lhefaa5                  ^libatomic-ops@7.6.12%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  nwvzdt4              ^gettext@0.21.1%gcc@9.4.0+bzip2+curses+git+libunistring+libxml2+tar+xz build_system=autotools arch=linux-rhel8-zen2
[+]  jmrtao4                  ^libiconv@1.16%gcc@9.4.0 build_system=autotools libs=shared,static arch=linux-rhel8-zen2
[+]  6tl6au3                  ^tar@1.34%gcc@9.4.0 build_system=autotools zip=pigz arch=linux-rhel8-zen2
[+]  onyctuz                      ^pigz@2.7%gcc@9.4.0 build_system=makefile arch=linux-rhel8-zen2
[+]  ogpntgf                      ^zstd@1.5.0%gcc@9.4.0+programs build_system=makefile compression=lz4,lzma,zlib libs=shared,static arch=linux-rhel8-zen2
[+]  s2yvnqh                          ^lz4@1.9.3%gcc@9.4.0 build_system=makefile libs=shared,static arch=linux-rhel8-zen2
[+]  h5xayww                  ^xz@5.2.5%gcc@9.4.0+pic build_system=autotools libs=shared,static arch=linux-rhel8-zen2
[+]  k7tcz64              ^gmp@6.2.1%gcc@9.4.0+cxx build_system=autotools libs=shared,static patches=69ad2e2 arch=linux-rhel8-zen2
[+]  kpsuuut              ^libffi@3.4.2%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  d3bx5oi              ^libtool@2.4.7%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  x3mkx4p              ^libunistring@0.9.10%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  ryhrrvu              ^readline@8.1%gcc@9.4.0 build_system=autotools patches=682a465,e55be05 arch=linux-rhel8-zen2
[+]  rxkfgbd          ^pkg-config@0.29.2%gcc@9.4.0+internal_glib build_system=autotools arch=linux-rhel8-zen2
[+]  stpg6jt      ^hdf5@1.10.7%gcc@9.4.0+cxx+fortran+hl+ipo+java+mpi+shared+szip+threadsafe+tools api=default build_system=cmake build_type=RelWithDebInfo generator=make patches=2a1e311 arch=linux-rhel8-zen2
[+]  iy5ro4n          ^libszip@2.1.1%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  vqsod6z          ^openjdk@11.0.12_7%gcc@9.4.0 build_system=generic arch=linux-rhel8-zen2
[+]  jpm3doc          ^zlib@1.2.13%gcc@9.4.0+optimize+pic+shared build_system=makefile arch=linux-rhel8-zen2
[+]  roegncq      ^libsm@1.2.3%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  at6vdch          ^libice@1.0.9%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  a2wysy5          ^libuuid@1.0.3%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  3nodp4k          ^util-macros@1.19.3%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  23l2zhm          ^xproto@7.0.31%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  jfsbatp          ^xtrans@1.3.5%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  qlyp3o5      ^libxmu@1.1.2%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  svszhzp          ^libx11@1.7.0%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  gwfkdc3              ^inputproto@2.3.2%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  knlmgzd              ^kbproto@1.0.7%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  2rzdmj2              ^libxcb@1.14%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  k3erefc                  ^libpthread-stubs@0.4%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  t7btf5s                  ^libxau@1.0.8%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  qhsvnq2                  ^libxdmcp@1.1.2%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  herup77                  ^xcb-proto@1.14.1%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  o4aqa47          ^libxext@1.3.3%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  3c7dro2          ^libxt@1.1.5%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  yo3pway          ^xextproto@7.3.0%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  o6mgx5d      ^mesa-glu@9.0.1%gcc@9.4.0 build_system=autotools gl=osmesa arch=linux-rhel8-zen2
[+]  lvj7wgx      ^openmpi@4.1.1%gcc@9.4.0+atomics~cuda+cxx+cxx_exceptions~gpfs~internal-hwloc~java+legacylaunchers~lustre~memchecker+orterunprefix+pmi+romio+rsh~singularity~static~vt+wrapper-rpath build_system=autotools fabrics=ucx schedulers=slurm arch=linux-rhel8-zen2
[+]  ctfnt3p          ^hwloc@2.6.0%gcc@9.4.0~cairo~cuda~gl+libudev+libxml2~netloc~nvml~oneapi-level-zero~opencl+pci~rocm build_system=autotools libs=shared,static arch=linux-rhel8-zen2
[+]  oktvvq3              ^libpciaccess@0.16%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  zteihso              ^libxml2@2.9.12%gcc@9.4.0~python build_system=autotools patches=3e06d42 arch=linux-rhel8-zen2
[+]  6p53zmi          ^numactl@2.0.14%gcc@9.4.0 build_system=autotools patches=4e1d78c,62fc8a8,ff37630 arch=linux-rhel8-zen2
[+]  e5cktjy              ^autoconf@2.69%gcc@9.4.0 build_system=autotools patches=35c4492,7793209,a49dd5b arch=linux-rhel8-zen2
[+]  6mgpv7j              ^automake@1.16.3%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  cjebbaj              ^m4@1.4.19%gcc@9.4.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=linux-rhel8-zen2
[+]  uvi2god                  ^diffutils@3.8%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  soukbeu                  ^libsigsegv@2.13%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  qtcped7          ^openssh@9.0p1%gcc@9.4.0+gssapi build_system=autotools arch=linux-rhel8-zen2
[+]  ko25i4e              ^krb5@1.19.2%gcc@9.4.0+shared build_system=autotools arch=linux-rhel8-zen2
[+]  43xbx5l              ^libedit@3.1-20210216%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  2tqklmb              ^libxcrypt@4.4.33%gcc@9.4.0~obsolete_api build_system=autotools arch=linux-rhel8-zen2
[+]  4grunmz          ^perl@5.34.0%gcc@9.4.0+cpanm+open+shared+threads build_system=generic arch=linux-rhel8-zen2
[+]  nkkrcue              ^berkeley-db@18.1.40%gcc@9.4.0+cxx+docs+stl build_system=autotools patches=26090f4 arch=linux-rhel8-zen2
[+]  hjzedoe              ^bzip2@1.0.8%gcc@9.4.0~debug+pic+shared build_system=generic arch=linux-rhel8-zen2
[+]  tsdsqho              ^gdbm@1.19%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  xbiwwfl          ^pmix@3.2.3%gcc@9.4.0~docs+pmi_backwards_compatibility build_system=autotools arch=linux-rhel8-zen2
[+]  ug5dirg          ^slurm@system%gcc@9.4.0~gtk~hdf5~hwloc~mariadb~pmix+readline~restd build_system=autotools sysconfdir=/etc/slurm arch=linux-rhel8-zen2
[+]  oq3hlnb          ^ucx@1.15.0%gcc@9.4.0~assertions~backtrace_detail+cma~cuda~dc~debug~dm+examples~gdrcopy~gtest~ib_hw_tm~java+knem~logging~mlx5_dv+openmp+optimizations~parameter_checking+pic~rc+rdmacm~rocm+thread_multiple~ucg~ud~verbs~vfs+xpmem build_system=autotools libs=shared opt=3 simd=auto arch=linux-rhel8-zen2
[+]  5gqoewn      ^osmesa@11.2.0%gcc@9.4.0 build_system=bundle arch=linux-rhel8-zen2
[+]  ronsr6s          ^mesa@21.2.5%gcc@9.4.0+glx~llvm+opengl+opengles+osmesa~strip build_system=meson buildtype=debugoptimized default_library=shared,static patches=ee737d1 arch=linux-rhel8-zen2
[+]  fxc4ppz              ^bison@3.8.2%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  lazftoc              ^expat@2.5.0%gcc@9.4.0+libbsd build_system=autotools arch=linux-rhel8-zen2
[+]  rs2ddq5                  ^libbsd@0.11.5%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  hkztvet                      ^libmd@1.0.4%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  foha5hv              ^flex@2.6.4%gcc@9.4.0+lex+nls build_system=autotools patches=f8b85a0 arch=linux-rhel8-zen2
[+]  lr5iwpq                  ^findutils@4.9.0%gcc@9.4.0 build_system=autotools patches=440b954 arch=linux-rhel8-zen2
[+]  lutg2mh                  ^help2man@1.47.16%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  2yshqcu              ^glproto@1.4.17%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  65dpibi              ^libunwind@1.6.2%gcc@9.4.0~block_signals~conservative_checks~cxx_exceptions~debug~debug_frame+docs+pic+tests+weak_backtrace+xz+zlib build_system=autotools components=coredump,ptrace,setjump libs=shared,static arch=linux-rhel8-zen2
[+]  oozqy34              ^meson@0.64.1%gcc@9.4.0 build_system=python_pip patches=0f0b1bd arch=linux-rhel8-zen2
[+]  dcjyras                  ^py-pip@21.1.2%gcc@9.4.0 build_system=generic arch=linux-rhel8-zen2
[+]  3f4dteo                  ^py-setuptools@63.4.3%gcc@9.4.0 build_system=generic arch=linux-rhel8-zen2
[+]  zu7kuev                  ^py-wheel@0.37.0%gcc@9.4.0 build_system=generic arch=linux-rhel8-zen2
[+]  gsrt7hl              ^ninja@1.10.2%gcc@9.4.0+re2c build_system=generic arch=linux-rhel8-zen2
[+]  npv6wpd                  ^re2c@2.2%gcc@9.4.0 build_system=generic arch=linux-rhel8-zen2
[+]  5meqv3b              ^py-mako@1.1.6%gcc@9.4.0 build_system=python_pip arch=linux-rhel8-zen2
[+]  26xogaz                  ^py-markupsafe@2.0.1%gcc@9.4.0 build_system=python_pip arch=linux-rhel8-zen2
[+]  t45xqwm              ^python@3.8.12%gcc@9.4.0+bz2+crypt+ctypes+dbm~debug+libxml2+lzma+nis+optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tkinter+uuid+zlib build_system=generic patches=0d98e93,4c24573,f2fd060 arch=linux-rhel8-zen2
[+]  qna53es                  ^libnsl@1.3.0%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  icy23ix                      ^libtirpc@1.2.6%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  jbj5l5f                      ^rpcsvc-proto@1.4.3%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  hhwsw3i                  ^sqlite@3.38.5%gcc@9.4.0+column_metadata+dynamic_extensions+fts+functions+rtree build_system=autotools arch=linux-rhel8-zen2
[+]  rckoxz7              ^xrandr@1.5.0%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  4zbzlco                  ^libxrandr@1.5.0%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  6fgglfp                  ^randrproto@1.5.0%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  4tvhibv      ^tcl@8.6.11%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  uv323sa      ^tk@8.6.11%gcc@9.4.0+xft+xss build_system=autotools arch=linux-rhel8-zen2
[+]  3oevaar          ^libxft@2.3.2%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  ebtsjlq              ^fontconfig@2.13.1%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  ruxdkjg                  ^font-util@1.3.2%gcc@9.4.0 build_system=autotools fonts=encodings,font-adobe-100dpi,font-adobe-75dpi,font-adobe-utopia-100dpi,font-adobe-utopia-75dpi,font-adobe-utopia-type1,font-alias,font-arabic-misc,font-bh-100dpi,font-bh-75dpi,font-bh-lucidatypewriter-100dpi,font-bh-lucidatypewriter-75dpi,font-bh-type1,font-bitstream-100dpi,font-bitstream-75dpi,font-bitstream-speedo,font-bitstream-type1,font-cronyx-cyrillic,font-cursor-misc,font-daewoo-misc,font-dec-misc,font-ibm-type1,font-isas-misc,font-jis-misc,font-micro-misc,font-misc-cyrillic,font-misc-ethiopic,font-misc-meltho,font-misc-misc,font-mutt-misc,font-schumacher-misc,font-screen-cyrillic,font-sun-misc,font-winitzki-cyrillic,font-xfree86-type1 arch=linux-rhel8-zen2
[+]  v4lwqfy                      ^bdftopcf@1.0.5%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  kztf3jt                          ^fontsproto@2.1.3%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  q7rswc7                          ^libxfont@1.5.2%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  el4zigk                      ^mkfontdir@1.0.7%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  cjqnhw3                      ^mkfontscale@1.1.2%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  r4tsdwi                          ^libfontenc@1.1.3%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  pcfi3uy                  ^gperf@3.1%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  6cupoxl              ^freetype@2.11.0%gcc@9.4.0+pic+shared build_system=autotools arch=linux-rhel8-zen2
[+]  yj4wdtz                  ^libpng@1.6.37%gcc@9.4.0+ipo build_system=cmake build_type=RelWithDebInfo generator=make libs=shared,static arch=linux-rhel8-zen2
[+]  swbnj5g              ^libxrender@0.9.10%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  s4fgvuq                  ^renderproto@0.11.1%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  kdzyy7n          ^libxscrnsaver@1.2.2%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
[+]  g7lhvjh              ^scrnsaverproto@1.2.2%gcc@9.4.0 build_system=autotools arch=linux-rhel8-zen2
...
```


### Error message

<details><summary>Error message</summary>

<pre>
...
/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-9.4.0/openmpi-4.1.1-lvj7wgxqp223cb6msiwgof2ms3qcij4o/bin/mpif90 -fPIC  -DNO_CONCATENATION -O2 -g -DNDEBUG -shared -Wl,-soname,libcgns.so.4.2 -o libcgns.so.4.2 CMakeFiles/cgns_shared.dir/cgns_error.c.o CMakeFiles/cgns_shared.dir/cgns_internals.c.o CMakeFiles/cgns_shared.dir/cgns_io.c.o CMakeFiles/cgns_shared.dir/cgnslib.c.o CMakeFiles/cgns_shared.dir/cg_hashmap.c.o CMakeFiles/cgns_shared.dir/adf/ADF_interface.c.o CMakeFiles/cgns_shared.dir/adf/ADF_internals.c.o CMakeFiles/cgns_shared.dir/adfh/ADFH.c.o CMakeFiles/cgns_shared.dir/pcgnslib.c.o CMakeFiles/cgns_shared.dir/cg_ftoc.c.o CMakeFiles/cgns_shared.dir/cgio_ftoc.c.o CMakeFiles/cgns_f2c.dir/cgns_f.F90.o  -Wl,-rpath,/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-9.4.0/hdf5-1.10.7-stpg6jtn3e2ollbzguvwdhse65o57hjk/lib:/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-9.4.0/zlib-1.2.13-jpm3doc2g37hjstjg5rhj7vrtrusrtxi/lib:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-9.4.0/hdf5-1.10.7-stpg6jtn3e2ollbzguvwdhse65o57hjk/lib/libhdf5.so.103.3.0 -ldl /cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-9.4.0/zlib-1.2.13-jpm3doc2g37hjstjg5rhj7vrtrusrtxi/lib/libz.so 
/bin/ld: CMakeFiles/cgns_f2c.dir/cgns_f.F90.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
...
</pre></details>


### Information on your system

```console
$ spack debug report
* **Spack:** 0.21.0.dev0 (84faf5a6cf342efddb976b7432e44aff12f1c985)
* **Python:** 3.6.8
* **Platform:** linux-rhel8-zen2
* **Concretizer:** clingo
```

### Additional information

[spack-build-env.txt](https://github.com/spack/spack/files/12476508/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/12476509/spack-build-out.txt)

Maintainers: @gsjaardema

Basically, it looks like we need to add -fPIC to the compilation flags

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/cgns/package.py b/var/spack/repos/builtin/packages/cgns/package.py
--- a/var/spack/repos/builtin/packages/cgns/package.py
+++ b/var/spack/repos/builtin/packages/cgns/package.py
@@ -46,6 +46,7 @@ class Cgns(CMakePackage):
     variant("legacy", default=False, description="Enable legacy options")
     variant("mem_debug", default=False, description="Enable memory debugging option")
     variant("tools", default=False, description="Enable CGNS tools")
+    variant("pic", default=False, description="Produce position-independent code")
 
     depends_on("cmake@3.12:", when="@4.3:", type="build")
     depends_on("cmake@3.8:", when="@4.2:", type="build")
@@ -62,6 +63,8 @@ class Cgns(CMakePackage):
     depends_on("libxmu", when="+tools")
     depends_on("libsm", when="+tools")
 
+    conflicts("~pic", when="+fortran", msg="+pic required when +fortran")
+
     # patch for error undefined reference to `matherr, see
     # https://bugs.gentoo.org/662210
     patch("no-matherr.patch", when="@:3.3.1 +tools")
@@ -83,6 +86,7 @@ def cmake_args(self):
                 self.define_from_variant("CGNS_ENABLE_BASE_SCOPE", "base_scope"),
                 self.define_from_variant("CGNS_ENABLE_LEGACY", "legacy"),
                 self.define_from_variant("CGNS_ENABLE_MEM_DEBUG", "mem_debug"),
+                self.define_from_variant("CMAKE_POSITION_INDEPENDENT_CODE", "pic"),
             ]
         )
 


Test patch: