Add cmake option to enable PIC - #360
mockbutler wants to merge 1 commit into
Conversation
Allows library to be used in the creation of dynamic libraries. Not enabled by default.
|
ping @hefloryd |
|
-fPIC is added automatically by cmake if BUILD_SHARED_LIBS is enabled. Currently of course a static library is always built, so you will also have to remove STATIC from the cmakelist, but I guess you would need to do that anyway in order to build a shared library. Note that PR #343 modernizes the cmakelist and lets you build a shared library without editing the cmakelists (just by setting BUILD_SHARED_LIBS). Please try it out if you have the time. |
|
@hefloryd For my purposes I want to build the static library with -fPIC. This library is then linked into another project which produces a dynamic library. The second project provides wrapper code for a managed language. So linking against an -fPIC static library simplifies the distribution to a single native library, precluding dynamic library version mismatch. This use case is atypical, but I didn't think unique. So I thought might be useful to support this almost hybrid target. There are other ways to achieve this, but using CMake allows the broad platform support. |
|
I agree with @mockbutler and I would like to add that it's a typical case to use SOEM and build a shared library to provide a wrapper for a managed language. Also, the BUILD_SHARED_LIBS is referred to build a shared lib when you have add_library, so it's not clear why to set this parameter to add the -PIC flag. |
|
Your use-case seems reasonable but would it not also be sufficient to configure SOEM with -DCMAKE_POSITION_INDEPENDENT_CODE=ON? There are many cmake flags that a user might wish to set and I'm not sure the best option is to wrap them in an SOEM option. |
|
|
Allows library to be used in the creation of dynamic libraries.
Not enabled by default.