SOEM icon indicating copy to clipboard operation
SOEM copied to clipboard

Add cmake option to enable PIC

Open mockbutler opened this issue 5 years ago • 5 comments

Allows library to be used in the creation of dynamic libraries. Not enabled by default.

mockbutler avatar Dec 18 '19 01:12 mockbutler

ping @hefloryd

nakarlsson avatar Mar 02 '20 14:03 nakarlsson

-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 avatar Mar 04 '20 10:03 hefloryd

@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.

mockbutler avatar Mar 07 '20 03:03 mockbutler

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.

lepalom avatar Oct 21 '21 07:10 lepalom

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.

hefloryd avatar Oct 25 '21 12:10 hefloryd