Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cmake option to enable PIC #360

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add cmake option to enable PIC #360

wants to merge 1 commit into from

Conversation

mockbutler
Copy link
Contributor

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

Allows library to be used in the creation of dynamic libraries.
Not enabled by default.
@nakarlsson
Copy link
Contributor

ping @hefloryd

@hefloryd
Copy link
Contributor

hefloryd commented Mar 4, 2020

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

@mockbutler
Copy link
Contributor Author

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

@lepalom
Copy link

lepalom commented Oct 21, 2021

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.

@hefloryd
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants