CMake install does not respect the SGID bit

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/ ).

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

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?

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

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/.

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 :slight_smile:

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.