# CMake install does not respect the SGID bit

**URL:** https://discourse.cmake.org/t/cmake-install-does-not-respect-the-sgid-bit/5685
**Category:** Usage
**Tags:** os:linux
**Created:** [May 18, 2022, 4:19am UTC](https://discourse.cmake.org/t/cmake-install-does-not-respect-the-sgid-bit/5685 "2022-05-18T04:19:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dipietrantonio](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/e8c25b/32.png) [@dipietrantonio](https://discourse.cmake.org/u/dipietrantonio)
#### Post date: [May 18, 2022, 4:19am UTC](https://discourse.cmake.org/t/cmake-install-does-not-respect-the-sgid-bit/5685/1 "2022-05-18T04:19:54Z")

</div>

Dear Cmake devs,

I am having issues with files installed using CMake in a directory tree with the SGID bit set.  
When set on a directory, the SGID permission bit makes such that all files under that directory will have the same linux group as that directory. So If I set the install directory to  
`/software/cdipietrantonio/gromacs_test_build`  
and that directory belongs to the group `myothergroup` and has the SGID bit set, then all the files installed by CMake under that directory should have the group `myothergroup`.  
However, in some cases, the group ownership of the installed files is assigned to my user group cdipietrantonio instead of `myothergroup`. This makes me think that the special bit is ignored in some cases. In fact, this does not happen for every installation, and it is hard to reproduce. A case when this happen is the gromacs installation ( [https://www.gromacs.org/](https://www.gromacs.org/) ).

Here is what i have in my bin directory, after the installation

```auto
drwxr-xr-x 2 cdipietrantonio pawsey0001 4.0K May 13 16:44 .
drwxr-sr-x 6 cdipietrantonio pawsey0001 4.0K May 13 16:44 ..
-rwxr-xr-x 1 cdipietrantonio pawsey0001 3.4K Apr 23 02:41 demux.pl
-rw-r--r-- 1 cdipietrantonio cdipietrantonio 138K Apr 23 02:42 gmx-completion.bash
-rw-r--r-- 1 cdipietrantonio cdipietrantonio 43 May 13 16:43 gmx-completion-gmx_mpi_d.bash
-rwxr-xr-x 1 cdipietrantonio pawsey0001 114K May 13 16:44 gmx_mpi_d
-rwxr-xr-x 1 cdipietrantonio pawsey0001 642 May 13 16:43 GMXRC
-rwxr-xr-x 1 cdipietrantonio pawsey0001 3.2K May 13 16:43 GMXRC.bash
-rwxr-xr-x 1 cdipietrantonio pawsey0001 3.1K May 13 16:43 GMXRC.csh
-rwxr-xr-x 1 cdipietrantonio pawsey0001 156 May 13 16:43 GMXRC.zsh
-rwxr-xr-x 1 cdipietrantonio pawsey0001 8.8K Apr 23 02:41 xplor2gmx.pl

```

in this case `myothergroup = pawsey0001`

How can I solve this issue?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 18, 2022, 1:07pm UTC](https://discourse.cmake.org/t/cmake-install-does-not-respect-the-sgid-bit/5685/2 "2022-05-18T13:07:58Z")

</div>

Other information I found says that sgid on a directory is a no-op.

> **[SGID on Directories](https://forums.freebsd.org/threads/sgid-on-directories.70392/)**
>
> Traditionally, as I remember, setting SGID on a directory makes the files which are created within to inherit the group of the directory.
> 
> For whatever reason, on my systems this is always the case, with or without SGID bit.
> Nevertheless, the bit can...

It seems that just creating a new file will inherit the directory’s group ownership regardless of that bit.

However, these files seem to be in the wrong directory. Should they not be under `/etc/bash_completion.d/` or the like? It is also weird to have non-executable files in `bin/`.

---

<div class="post-metadata">

### Author: ![dipietrantonio](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/e8c25b/32.png) [@dipietrantonio](https://discourse.cmake.org/u/dipietrantonio)
#### Post date: [May 18, 2022, 3:40pm UTC](https://discourse.cmake.org/t/cmake-install-does-not-respect-the-sgid-bit/5685/3 "2022-05-18T15:40:57Z")

</div>

HI Ben, I am not extremely familiar with SGID but that’s the behaviour we observe and rely on on our system and many other programs follow that convention. Well, as you can see, that does not “happen regardless”, since the parent bin directory has group `pawsey0001` and those two files are in group `cdipietrantonio`. We observe this behavior with CMake, and we would like at least to know what CMake commands, and what sequence of actions brings to this result. The reason they are there is that this software has to be installed on a supercomputer, and there software is organised differently than a workstation 🙂

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [May 18, 2022, 4:12pm UTC](https://discourse.cmake.org/t/cmake-install-does-not-respect-the-sgid-bit/5685/4 "2022-05-18T16:12:55Z")

</div>

Ah. You can strip down the `cmake_install.cmake` scripts to pin down what command is installing the file and see if you can change `file(INSTALL)` command responsible for it to do what you want (it seems that programs are installed properly at least). Once that is known, figuring out how to change the CMake code that ends up causing it to be generated can be investigated.
