-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split linker flags in separate files
- Loading branch information
Showing
5 changed files
with
45 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Force symbols in shared libraries to be loaded on startup instead of lazily loaded. | ||
cninja_require(pre) | ||
|
||
if(APPLE) | ||
add_linker_flags(" -Wl,-z,now") | ||
elseif(MSVC) | ||
# Nothing special to do here, it's the default | ||
else() | ||
# For macOS this only works for executables | ||
string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -Wl,-bind_at_load") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Discard unused symbols & libraries | ||
cninja_require(pre) | ||
|
||
# -ffunction-sections, etc... : Allows to discard unused code more easily with --gc-sections | ||
string(APPEND CMAKE_C_FLAGS_INIT " -ffunction-sections -fdata-sections") | ||
string(APPEND CMAKE_CXX_FLAGS_INIT " -ffunction-sections -fdata-sections") | ||
|
||
if(NOT APPLE) | ||
# In conjunction with ffunction-sections / fdata-sections, removes unused code | ||
add_linker_flags(" -Wl,--gc-sections") | ||
|
||
# Don't link against libraries of which no symbols are used | ||
add_linker_flags(" -Wl,--as-needed") | ||
|
||
# Make all platforms behave like Windows, which is in itself terrible but will | ||
# spare you trying to debug why dynamic_cast of inline classes across DLLs | ||
# doesn't work in MSW - simply don't write code assuming this works anywhere. | ||
add_linker_flags(" -Bsymbolic -Bsymbolic-functions") | ||
else() | ||
# Apple way to strip unneeded libs: | ||
add_linker_flags(" -Wl,-dead_strip -Wl,-dead_strip_dylibs") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters