How can I remove an option from the default compile command template for a specific compiler?

221 views Asked by At

Any normal gcc compatible compiler specifies the source file with -c option (compile but not link). I have to deal with "Tasking" compiler which doesn't like this option. -c option for this TASKING compiler indicates C standard (page 280) indicates the C standard. I've used the common way to specify the compiler using the toolchain file:

set(CMAKE_C_COMPILER "${AURIX_SDK_ROOT}/bin/ctc" CACHE INTERNAL "")
set(CMAKE_CXX_COMPILER "${AURIX_SDK_ROOT}/bin/cptc" CACHE INTERNAL "")

foreach (_prefix C CXX)
    # set(CMAKE_${_prefix}_COMPILER "${AURIX_SDK_ROOT}/bin/cctc")
    # This is used only if we skip auto compiler identification
    set(CMAKE_${_prefix}_COMPILER_ID "Tasking")
    set(CMAKE_${_prefix}_COMPILER_VERSION "6.3r1")

    # Skip compiler ID identification: use "Tasking"
    set(CMAKE_${_prefix}_COMPILER_ID_RUN TRUE CACHE INTERNAL "")
    set(CMAKE_${_prefix}_COMPILER_FORCED TRUE CACHE INTERNAL "")

    SET(CMAKE_${_prefix}_COMPILER_WORKS TRUE CACHE INTERNAL "")
    SET(CMAKE_${_prefix}_COMPILER_FORCED TRUE CACHE INTERNAL "")
    SET(CMAKE_${_prefix}_COMPILER_ID_RUN TRUE CACHE INTERNAL "")
endforeach()

set(CMAKE_AR "${AURIX_SDK_ROOT}/bin/artc")
set(CMAKE_ASM_COMPILER  "${AURIX_SDK_ROOT}/bin/astc")
set(CMAKE_LINKER  "${AURIX_SDK_ROOT}/bin/ltc")

# Search paths for libraries
set(CMAKE_FIND_ROOT_PATH ${AURIX_SDK_ROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

Is there any way to configure CMake (version 3.16) to not use -c option? I did specify CMAKE_CCOMPILER_ID as "Tasking".

Versions:

  • CMake >3.16
  • TASKING VX-toolset for TriCore v6.3r1
2

There are 2 answers

0
starball On BEST ANSWER

If the Tasking compiler really isn't supposed to have -c to specify the file to compile (I wouldn't know, because I don't know that compiler), then you might be able to do this by modifying your CMake installation's Modules/Compiler/Tasking-CXX.cmake file to make it override the default value of CMAKE_CXX_COMPILE_OBJECT which gets set in the Modules/CMakeCXXInformation.cmake file like:

set(CMAKE_CXX_COMPILE_OBJECT
  "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")

and just put that same line in the Modules/Compiler/Tasking-CXX.cmake except removing the -c argument. Or you could try putting this in your toolchain file.

At least- that's how things look to be set up to work in the CMake modules. Just grep the modules for CMAKE_CXX_COMPILE_OBJECT and you'll see similar overrides for specific compilers or platforms.

Disclaimer: I'm not 100% sure this will work. I just grepped the code to find something that looks like it might be the thing to poke with a stick. Documentation for CMAKE_CXX_COMPILE_OBJECT can be found here.

The places in the CMake source code where CMAKE_CXX_COMPILE_OBJECT is used is in Source/cmMakefileTargetGenerator.cxx and Source/cmNinjaTargetGenerator.cxx (search for regex CMAKE_.*_COMPILE_OBJECT). It's pretty interesting (or very boring)- you can read how the compile command gets built by the CMake executable for various generators.

0
ilya1725 On

The solution to this problem, turned out, is the CMake version 3.25. The support for Tasking compiler was added in this version. The toolchain file looks like this:

set(CMAKE_C_COMPILER "${AURIX_SDK_ROOT}/bin/cctc" CACHE INTERNAL "")

foreach (_prefix C)
    # set(CMAKE_${_prefix}_COMPILER "${AURIX_SDK_ROOT}/bin/cctc")
    # This is used only if we skip auto compiler identification
    set(CMAKE_${_prefix}_COMPILER_ID "Tasking")
    set(CMAKE_${_prefix}_COMPILER_VERSION "Tricore")
    set(CMAKE_${_prefix}_COMPILER_ARCHITECTURE_ID "Tricore")

    # Skip compiler ID identification: use "Tasking"
    set(CMAKE_${_prefix}_COMPILER_ID_RUN TRUE CACHE INTERNAL "")
    set(CMAKE_${_prefix}_COMPILER_FORCED TRUE CACHE INTERNAL "")

    SET(CMAKE_${_prefix}_COMPILER_WORKS TRUE CACHE INTERNAL "")
    SET(CMAKE_${_prefix}_COMPILER_FORCED TRUE CACHE INTERNAL "")
    SET(CMAKE_${_prefix}_COMPILER_ID_RUN TRUE CACHE INTERNAL "")
endforeach()

set(CMAKE_AR "${AURIX_SDK_ROOT}/bin/artc")
set(CMAKE_ASM_COMPILER "${AURIX_SDK_ROOT}/bin/astc")
set(CMAKE_LINKER "${AURIX_SDK_ROOT}/bin/ltc")

# Search paths for libraries
set(CMAKE_FIND_ROOT_PATH ${AURIX_SDK_ROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

Some notes:

  1. The compiler setup emphatically does not support C++. Not sure why. There is a C++ compiler cptc.
  2. The control application cctc should be used instead of the ctc compiler directly.