cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

cfg: add relative location of Cppcheck config location to search path

Open andresailer opened this issue 7 months ago • 8 comments

We are installing cppcheck on a distributed filesystem (CVMFS) in various locations.

Since the cppcheck cfg files are installed into ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME} it would be great if we could use the fact that the share folder is relative to the executable, so that we can relocate cppcheck easily.

Defining FILESDIR(_DEF) does not work for this, since we cannot change this after compilation, and we do not know a priory where the installation will be. We compile cppcheck once and install it on many locations.

Thanks!

andresailer avatar May 16 '25 12:05 andresailer

Thanks for your contribution.

This is a rather arbitrary addition and needs to be handled differently. Off the top of my head I cannot think of one right now.

It also applies to all external files not just cfg.

I am still in the midst of cleaning up and aligning the lookup handling - I cannot remember if it stalled or if I got side-tracked by more pressing things.

firewave avatar May 16 '25 12:05 firewave

Two questions:

  • you CAN install cppcheck binary and all the datafiles in a installation folder.. I wonder if you don't install cppcheck in some standard /usr/bin etc folder anyway then why not install it all in a installation folder.
  • How about allowing that you configure a relative path for FILESDIR such as "../share/Cppcheck" ?

danmar avatar May 16 '25 18:05 danmar

I have not thought much about this yet. I was thinking along indicating the prefix which is used during install.

And the suggested change is kinda of valid because it is what we use in the install. Maybe it should be dependent on FILESDIR and not be used by default.

I always get a very bad feeling when I see hard-coded path traversal in the code. IMO it should always be a fixed (not necessarily absolute path).

There might be some existing tickets which already have discussions in it - I have not checked yet.

firewave avatar May 16 '25 19:05 firewave

FYI I am hesitant in adding anything to the file lookup because the existing behavior is neither consistent nor clearly defined right now.

firewave avatar May 16 '25 19:05 firewave

I resumed work on the lookup cleanup and will be looking into this soon (hopefully).

firewave avatar May 18 '25 07:05 firewave

Thanks for looking at this issue so quickly @firewave @danmar !

you CAN install cppcheck binary and all the datafiles in a installation folder.. I wonder if you don't install cppcheck in some standard /usr/bin etc folder anyway then why not install it all in a installation folder.

We install in something like /cvmfs/sft.cern.ch/lcg/releases/cppcheck/<VERSION>/<PLATFORM/[bin,include,share...], but the base path is changing, so we cannot know what it will be at compile time, so we need to be able to relocate the executables and libraries.

How about allowing that you configure a relative path for FILESDIR such as "../share/Cppcheck" ?

That would be great! I tried to set FILESDIR to exepath + "../share/Cppcheck", but that MACRO replacement did not work everywhere.

andresailer avatar May 19 '25 10:05 andresailer

We install in something like /cvmfs/sft.cern.ch/lcg/releases/cppcheck/<VERSION>/<PLATFORM/[bin,include,share...], but the base path is changing, so we cannot know what it will be at compile time, so we need to be able to relocate the executables and libraries.

(How) do you support custom/user configurations?

I think this is a good point to take a closer look at FILESDIR (it always felt awkward).

firewave avatar May 20 '25 10:05 firewave

We install in something like /cvmfs/sft.cern.ch/lcg/releases/cppcheck/<VERSION>/<PLATFORM/[bin,include,share...], but the base path is changing

so if you compile cppcheck without FILESDIR and install in path /cvmfs/sft.cern.ch/lcg/releases/cppcheck/<VERSION>/<PLATFORM>/ like so:

INSTALLPATH=/cvmfs/sft.cern.ch/lcg/releases/cppcheck/<VERSION>/<PLATFORM>
cp cppcheck $INSTALLPATH/
cp -R cfg $INSTALLPATH/
cp -R platforms $INSTALLPATH/

now cppcheck works fine!

You can move it.. mv /cvmfs/sft.cern.ch/lcg/releases/cppcheck/<VERSION>/<PLATFORM> /some/other/basepath/cppcheck and now you will be able to execute /some/other/basepath/cppcheck/cppcheck ...

danmar avatar May 20 '25 18:05 danmar