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

Fix POSITION_INDEPENDENT_CODE #1347

Merged

Conversation

fjtrujy
Copy link
Contributor

@fjtrujy fjtrujy commented Oct 25, 2021

Description

This PR just fixed a wrong configuration in the cmake files with the POSITION_INDEPENDENT_CODE, it should be just enabled when the BUILD_SHARED_LIBS config is enabled as well.

The specific details about the issue can be found here:
#1344

Thanks

@fjtrujy fjtrujy force-pushed the position_independent_code branch from 96bd9fe to f13f2da Compare October 25, 2021 22:00
Copy link
Contributor

@cdunn2001 cdunn2001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! We depend on users for cmake maintenance. We use meson ourselves.

The TravisCI troubles should be fixed. Please rebase, then merge after the CI tests pass.

@fjtrujy
Copy link
Contributor Author

fjtrujy commented Oct 29, 2021

Thank you! We depend on users for cmake maintenance. We use meson ourselves.

The TravisCI troubles should be fixed. Please rebase, then merge after the CI tests pass.

Maybe it is a off topic question, but why don't you use GitHub Actions rather than TravisCI and implement a matrix with all possible combinations meson, cmake and different OS?

If you're interested I could easily do it.

Thanks

@fjtrujy fjtrujy force-pushed the position_independent_code branch from f13f2da to 29f9853 Compare October 29, 2021 08:41
@fjtrujy
Copy link
Contributor Author

fjtrujy commented Nov 2, 2021

Hello @cdunn2001,
I have rebased the PR and now all the CI checks are green, could you merge the PR?

Thanks

@cdunn2001
Copy link
Contributor

If you're interested I could easily do it.

Yes! Very interested. We would gladly accept your help.

@cdunn2001 cdunn2001 merged commit b22302e into open-source-parsers:master Nov 3, 2021
@cdunn2001
Copy link
Contributor

I think we already test cmake in AppVeyor. But as long as the tests run fast, more robustness would be welcome.

@@ -180,7 +180,7 @@ if(BUILD_OBJECT_LIBS)
OUTPUT_NAME jsoncpp
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION}
POSITION_INDEPENDENT_CODE ON
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
Copy link
Contributor

@SpaceIm SpaceIm Nov 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really make sense? I would have removed it, that's all (same behavior than STATIC). I mean, BUILD_SHARED_LIBS is orthogonal to BUILD_OBJECT_LIBS.

@@ -119,7 +119,7 @@ if(BUILD_SHARED_LIBS)
OUTPUT_NAME jsoncpp
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION}
POSITION_INDEPENDENT_CODE ON
POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
Copy link
Contributor

@SpaceIm SpaceIm Nov 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the BUILD_SHARED_LIBS branch, so it's always ON in this block. And actually forcing POSITION_INDEPENDENT_CODE for a shared lib is useless because it's implicit in CMake. Therefore this line could be removed, it's misleading.

@fjtrujy
Copy link
Contributor Author

fjtrujy commented Nov 3, 2021

@SpaceIm about your suggestions..... in my opinion, the best solution is just to put at the root level, and just once this:

POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}

I didn't want to do that change because I just took a quick way.

Thanks

@SpaceIm
Copy link
Contributor

SpaceIm commented Nov 4, 2021

I disagree. I like principle of least surprise:

  • shared libs are always PIC
  • static and object libs are not PIC by default (unless they are linked to a shared lib internally, therefore build system must manually force PIC).
  • PIC can be enabled for object and static libs (and it's a consumer decision through standard CMAKE_POSITION_INDEPENDENT_CODE variable).

@fjtrujy
Copy link
Contributor Author

fjtrujy commented Nov 4, 2021

I disagree. I like principle of least surprise:

  • shared libs are always PIC
  • static and object libs are not PIC by default (unless they are linked to a shared lib internally, therefore build system must manually force PIC).
  • PIC can be enabled for object and static libs (and it's a consumer decision through standard CMAKE_POSITION_INDEPENDENT_CODE variable).

Ok, I'm fine with whatever solution meanwhile there is a way by flags of disabling the CMAKE_POSITION_INDEPENDENT_CODE.

Thanks

@cdunn2001
Copy link
Contributor

@SpaceIm , I didn't realize there was controversy. If you feel strongly about this, please submit a PR with a better solution. We try to let the cmake community reach consensus.

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.

3 participants