0

I'm trying to compile a single codebase for both ArmV8 aarch64 and aarch32 with GCC. My code requires the -mfloat-abi=hard flag and possibly others when compiled for aarch32, but not for aarch64.

I have multiple toolchains so I created two toolchain files. What's the most idiomatic CMake way to add this flag only when the aarch32 toolchain file is used?

Of course I could do this inside the project CMakeLists.txt file, at the point where I already created the target and I'm setting other compiler flags. But then I would have to add this flag conditionally depending on the toolchain, which seems to defeat the point of having two neatly separated toolchain files.

Kafein
  • 357
  • 1
  • 7
  • 1
    So, should the compiler flag `-mfloat-abi=hard` be part of the toolchain or not? If yes, then see e.g. [that answer](https://stackoverflow.com/a/30217088/3440745) about adding the flag to the toolchian. If instead you want to set the flag in the `CMakeLists.txt`, then do not check a toolchain by itself but check some **property** of the target machine or a compiler. E.g. you may check [CMAKE_SYSTEM_PROCESSOR](https://cmake.org/cmake/help/v3.17/variable/CMAKE_SYSTEM_PROCESSOR.html) variable for distinguish aarch64 and aarch32. – Tsyvarev Jun 24 '20 at 09:48
  • In this project I have just a few targets and whether I want to add this option or not depends only on the toolchain and not on these targets that I'm not changing. That's why I want to put the option in the toolchain, even though it means that now my toolchain is specialized for these targets. Whether I *should* put the compiler flag in the toolchain file to begin with is part of the question. You did provide an answer to *how*. – Kafein Jun 25 '20 at 08:36
  • 2
    "Whether I should put the compiler flag in the toolchain file to begin with is part of the question." - It is difficult to (objectively) suggest whether the compiler flag should belong to the toolchain or to the `CMakeLists.txt`. The borderline between toolchain and `CMakeLists.txt` is quite wide. E.g. you may treat a toolchain as something **reusable**. Would you add the flag to the toolchain, could you *imagine* another project used this toolchain? If the answer "yes", then specialization of your toolchain could be a good idea. Note also that you may parameterize your toolchain. – Tsyvarev Jun 25 '20 at 08:52

0 Answers0