So, for your compiler, I think defining variables CMAKE_COMPILE_OPTIONS_PIC, CMAKELINK_OPTIONS_PIE and CMAKE_LINK_OPTIONS_NO_PIE will be enough.
Not really, it is kind of the behaviour I have right now. As @brad.king mentioned, the issue is that the linker coming with my linux distribution defaults to using PIE (and GCC compiles with PIC/PIE by default too) without us having to give it any flag.
ISPC, which produces object files, has a different default which is not to enable PIC.
So right now, everything compiles, but when I try to link I’m getting an error because the linker expects both GCC and ISPC to produce objects that have position independent code.
So right now, by default (regardless of
CMAKE_<LANG>_LINK_OPTIONS_NO_PIE) it will not build correctly on this system, due to GNU tools and ISPC having different defaults.
That’s what I’m trying to fix.
CMAKE_<lang>_LINK_OPTIONS_NO_PIE is used by default (when
CMAKE_POSITION_INDEPENDENT_CODE is not set) then what I would need is for
CMAKE_CXX_LINK_OPTIONS_NO_PIE to actually use the flag
-fno-pie for GCC/clang instead of nothing?
Basicly, the following (pseudocode) won’t work.
$CC main.c -o main.o
ispc code.ispc -o code.o
$LD main.o code.o
and ouput something along the lines of
/usr/bin/ld: (code.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC