0

I'm using the __FILE__ macro in my main.cpp file. When compiling with make + Makefile the final executable main contains the string main.cpp (you can check it via strings main | grep "*.cpp"). But when using cmake + CMakeLists.txt cmake uses absolute paths and the final executable contains /home/cpp/main.cpp, so it causes the following warning (makepkg):

==> Checking for packaging issues...

==> WARNING: Package contains reference to $srcdir

What should I do in this case? Somehow tell cmake to not use absolute paths? Don't use the __FILE__ macro (then, what?)? Ignore the warning?

cppbest
  • 59
  • 8
  • Answer really depends on what you are using the macro `__FILE__` for. – john Dec 01 '22 at 09:09
  • First hit for `gcc __FILE__ relative` brought me straight back to SO. Please do the same before you ask questions. See [this answer](https://stackoverflow.com/a/53848526/1548468) for a way to strip the source path, or [this answer](https://stackoverflow.com/a/59154301/1548468) which proposes using `__FILE_NAME__`. – Botje Dec 01 '22 at 09:11
  • @john so, I can't handle it on `cmake` level and should inspect the sources? Can't I just tell `cmake` to use relative paths as `make` does? – cppbest Dec 01 '22 at 09:13
  • @Botje thanks, there is an answer indeed. Actually, I found this question, but didn't read up to the 4th answer :) – cppbest Dec 01 '22 at 09:14
  • @cppbest I didn't say that. I just said the right thing to do depends largely on what you are using `__FILE__` for. – john Dec 01 '22 at 09:15
  • 1
    "Can't I just tell cmake to use relative paths as make does?" - Such question has been [asked recently](https://stackoverflow.com/questions/74617239/make-relative-path-vs-absolute-path-in-output). As far as I know, CMake has no "switch" to generate relative paths in Makefile. – Tsyvarev Dec 01 '22 at 09:31

0 Answers0