I’m building a C++ library with hipcc that can have either an amd or nvidia back-end depending on the HIP_PLATFORM setting. I’m building both static and shared libraries via building an object library that gets linked into the static/shared libraries to avoid the double compile. Everything works fine for AMD, but when building for NVIDIA, there is CMake magic happening that is trying to add -fPIC to the shared library target under the hood, which makes nvcc sad (the object library is built with -Xcompile=-fPIC, so no problems there). This library is only using C++ with .cpp/.h file extensions, btw. No CUDA kernels or .cu files at this time.
I’m not globally setting POSITION_INDEPENDENT_CODE and that property is explicitly set to OFF for the shared library target (in lieu of me manually setting it, since CMake is guessing incorrectly). The only place where I see -fPIC added to flags is CMAKE_SHARED_LINKER_FLAGS_INIT. I’ve tried making this a blank string, but that doesn’t help.
How can I either (a) convince CMake to stop adding -fPIC for the shared library target or (b) get CMake to understand that hipcc is driving nvcc so -fPIC needs to be decorated with -Xcompiler, etc.? Is there something I might be missing?
I’m on Linux, btw, with software versions as follows:
CMake: 3.23.2
g++: 9.4.0
nvcc: 12.8
hipcc: 6.1 (clang 17.0.0)
Thanks!