What is the idiomatic way in CMAKE to add the -fPIC compiler option?

You can set the position independent code property on all targets:

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

or in a specific library:

add_library(lib1 lib1.cpp)
set_property(TARGET lib1 PROPERTY POSITION_INDEPENDENT_CODE ON)

Reference:

  • CMAKE_POSITION_INDEPENDENT_CODE
  • cmake build system: “Compatible Interface Properties”

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)