3

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
  • 14,269
  • 7
  • 44
  • 64
  • 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? – alfonsostocchetti 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

0 Answers0