Skip to content

set CMAKE_POSITION_INDEPENDENT_CODE if BUILD_SHARED_LIBS=OFF#1076

Merged
jbeder merged 1 commit intojbeder:masterfrom
christian-rauch:set_pic
Jan 27, 2022
Merged

set CMAKE_POSITION_INDEPENDENT_CODE if BUILD_SHARED_LIBS=OFF#1076
jbeder merged 1 commit intojbeder:masterfrom
christian-rauch:set_pic

Conversation

@christian-rauch
Copy link
Copy Markdown
Contributor

No description provided.

@gelldur
Copy link
Copy Markdown

gelldur commented Dec 17, 2021

This will set PIC for all targets (what if someone adds library as sub-directory, maybe set_property would be better?
set_property(TARGET lib1 PROPERTY POSITION_INDEPENDENT_CODE ON)

@christian-rauch
Copy link
Copy Markdown
Contributor Author

If BUILD_SHARED_LIBS=OFF then every library, that hasn't explicitly set SHARED or STATIC will build as STATIC. I think that PIC should therefore apply to all static libraries that the cmake project builds.

@milipili
Copy link
Copy Markdown

Property on targets should be used instead. It is not rare that CMake projects are included into another, and deciding to set CMAKE_POSITION_INDEPENDENT_CODE will just break everything.

It should always be per target. Also why setting position indepdendant code if building a static library? In many cases we dont want that option. Only if it is included into a bigger shared library

@christian-rauch
Copy link
Copy Markdown
Contributor Author

christian-rauch commented Dec 22, 2021

In many cases we dont want that option.

Why? You will need that option if you want to link your static library into an executable a shared library. Is there a downside of using this in executables too? AFAIK, all modern Linux distributions use position-independent-executables now.

@christian-rauch
Copy link
Copy Markdown
Contributor Author

Property on targets should be used instead.

I set this for the target yaml-cpp only. I think this is the only target in the project.

@jbeder jbeder merged commit cdf89fa into jbeder:master Jan 27, 2022
@jbeder
Copy link
Copy Markdown
Owner

jbeder commented Jan 27, 2022

Fixes #1031

@christian-rauch christian-rauch deleted the set_pic branch January 28, 2022 10:07
davemccann pushed a commit to davemccann/yaml-cpp that referenced this pull request Jul 30, 2023
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.

4 participants