4

I'm trying to cross-build a piece of SW over Android and iOS using CMake. Android project uses GNU ld, while iOS uses lld. I need to add linker options for stripping dead code from linked libraries to both toolchains. I identified the way to achieve it adding on GNU ld, the --gc-sections linker options, while on lld adding the -dead_strip linker options. So, my question is: Is there an alternative way to check cross-compiling platform, like below?

if(CMAKE_SYSTEM_NAME STREQUAL Android)
   target_link_options(GarminAis PRIVATE LINKER:--gc-sections)
elseif(CMAKE_SYSTEM_NAME STREQUAL APPLE)
   target_link_options(GarminAis PRIVATE LINKER:-dead_strip)
endif()

I would strongly prefer an unified approach.

Thanks in advance for any help

Kevin
  • 16,549
  • 8
  • 60
  • 74
fabiop
  • 179
  • 10
  • 1
    Kudos for looking for a unified approach. In the meantime, you could make the distinction based on compiler used (`CMAKE_COMPILER_IS_GNUCC`) instead of checking for Android as a platform. Not sure if that really improves things, just an idea. – DevSolar Nov 25 '19 at 10:59
  • 1
    @DevSolar good point, maybe checking CMAKE__COMPILER_ID could be even better? – fabiop Nov 25 '19 at 11:22
  • Jolly, that one had escaped my attention so far. Yes, that's even better (since the option isn't platform-dependent). As I can't find a property affecting that particular linker functionality, that's probably your best option at this point. – DevSolar Nov 25 '19 at 11:48
  • Seeing the answers in this [post](https://stackoverflow.com/a/9160449/3987854), it appears you could simplify your `APPLE` check. – Kevin Nov 25 '19 at 12:37
  • To clarify, is it that you are currently writing these lines each in separate toolchain files, and that you would like a way to write them in one single file? It might also help readers if you explain why you want to do this: what do you not like about your current approach? What specifically would be better about what you are ideally looking for? – starball Dec 01 '22 at 23:14

0 Answers0