#5992·caffe

CMake: position independent code on Windows?

Author: morrisonleviCreated Oct 17, 2017Updated Feb 7, 2025

Currently the flag -fPIC is being set like this:

cmake
if(UNIX OR APPLE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
endif()

CMake has a property for this: POSITION_INDEPENDENT_CODE which can be set globally like this:

cmake
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

However, this begs the question: is there a reason Windows does not need PIC enabled?