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

前端 未结 2 886
温柔的废话
温柔的废话 2020-11-30 19:34

I\'ve come across at least 3 ways to do this and I\'m wondering which is the idiomatic way. This needs to be done almost universally to any static library. I\'m surprised

相关标签:
2条回答
  • 2020-11-30 19:54

    If this is not your cmake project and you can't or don't want to modify the project files you can also pass the following command line option to cmake:

    -DCMAKE_POSITION_INDEPENDENT_CODE=ON
    
    0 讨论(0)
  • 2020-11-30 19:57

    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

    0 讨论(0)
提交回复
热议问题