Discussion:
[CMake] CPU specific compiler flags
Ciccio Pasticcio
2018-11-26 08:36:09 UTC
Permalink
Hi all,

I'm refactoring some libraries cmake files to be compliant to the use of
targets instead of tons of variables. Since these libraries are
cross-compiled I'm facing some problem finding how to properly set some
specific flags like: -march -marm -mfloat-abi etc. For now I set the
CMAKE_CXX_FLAGS:

set(CMAKE_CXX_FLAGS -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard
-mfpu=neon -mtune=cortex-a8 -Wno-psabi)

Is this the only way to do this? With targets I do something like this:

add_library(MyLib)
# add sources
...
# Comiler features
TARGET_COMPILE_FEATURES(MyLib PUBLIC cxx_lambdas)

Thanks,
Gabriele
Eric Noulard
2018-11-26 08:49:01 UTC
Permalink
Post by Ciccio Pasticcio
Hi all,
I'm refactoring some libraries cmake files to be compliant to the use of
targets instead of tons of variables. Since these libraries are
cross-compiled I'm facing some problem finding how to properly set some
specific flags like: -march -marm -mfloat-abi etc. For now I set the
set(CMAKE_CXX_FLAGS -march=armv7-a -marm -mthumb-interwork
-mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 -Wno-psabi)
Is this the only way to do this?
I'm not sure to understand, you can perfectly setup flags on a target
specific way using 'target_compile_option'
https://cmake.org/cmake/help/latest/command/target_compile_options.html

If all your libraries are in a common directory you can use,
COMPILE_OPTIONS property on the directory
https://cmake.org/cmake/help/latest/prop_tgt/COMPILE_OPTIONS.html#prop_tgt:COMPILE_OPTIONS
to avoid repetition for each lib.

All that said, if you are cross-compiling those I bet you are using a
toolchain file (
https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling
)
so if those "target-specific" compile options are global to your target
then you may set
https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS.html#variable:CMAKE_%3CLANG%3E_FLAGS
in the toolchain.
--
Eric
Continue reading on narkive:
Loading...