cmaketricore

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


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:


Solution

  • 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.