[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cmake
Subject:    [CMake] Is there an idiomatic way of setting platform specific compiler options in a generic way?
From:       Kuba Ober <kuba () mareimbrium ! org>
Date:       2019-02-20 22:55:03
Message-ID: 91F06EC0-DEB4-4EAB-BB93-961A140E735D () mareimbrium ! org
[Download RAW message or body]

I am developing platform support for an embedded target (Z8 Encore!), and it mostly works – but I'd \
like to make it easier to set the compiler and linker flags, as there's a ton of them: and they are \
nothing like GNU flags, so they only apply when building for that particular target. 

Thus a question: is there a preferred way for the user to set platform-specific flags without having to \
know them exactly? I'm thinking of having some sort of platform-agnostic means of selecting compile and \
link flags, and then translating those for the platform the target is generated for.

Specifically, I want to avoid having the following in CMakeLists for the project:

if("${COMPILER_ID}" strequal "ez8cc")
target_compile_options(target1 PRIVATE -const:RAM)
elseif("${COMPILER_ID}" strequal "gcc" and "${CMAKE_SYSTEM_PROCESSOR}" strequal "somecpu")
target_compile_definitions(target1 PRIVATE ram rom far near) # those shall be empty
endif()

I'd like to do something like this instead:

set_target_properties(target1 PROPERTIES  OPT_CONST RAM OPT_PACK TIGHT …)

Then, a process_target_opts() function called at the end of CMakeLists would iterate the targets, and for \
each target call process_${COMPILER_ID}_opts() (if such function would be present or issue a warning \
otherwise). That function then converts the OPT_ options to platform-specific flags, based on cpu and/or \
compiler.

Is it something that would be more-or-less idiomatic, or is there another preferred way of doing it? I \
really don't want to list the options manually for each target/platform combo, as they'd differ quite a \
bit, and I have lots of targets (hundreds).

I'd appreciate any hints.

Cheers, Kuba Ober

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, \
please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic