From 8ce6689d8bf2ab3b1f2fd7f2fb6c4611682dc6a2 Mon Sep 17 00:00:00 2001 From: Sanjiv Gupta Date: Sun, 2 Feb 2025 01:24:03 -0500 Subject: [PATCH] Diab: Add WindRiver Systems's Diab C/C++ toolchain Teach CMake to recognize Diab versions 5.9.x.x and above. Closes: #26666 --- Help/release/dev/diab-compiler-support.rst | 8 +++++ Help/variable/CMAKE_LANG_COMPILER_ID.rst | 2 ++ Modules/CMakeCompilerIdDetection.cmake | 1 + Modules/CMakeDetermineASMCompiler.cmake | 4 +++ Modules/Compiler/Diab-ASM.cmake | 3 ++ Modules/Compiler/Diab-C.cmake | 9 +++++ Modules/Compiler/Diab-CXX.cmake | 12 +++++++ Modules/Compiler/Diab-DetermineCompiler.cmake | 10 ++++++ Modules/Compiler/Diab-FindBinUtils.cmake | 15 +++++++++ Modules/Compiler/Diab.cmake | 33 +++++++++++++++++++ 10 files changed, 97 insertions(+) create mode 100644 Help/release/dev/diab-compiler-support.rst create mode 100644 Modules/Compiler/Diab-ASM.cmake create mode 100644 Modules/Compiler/Diab-C.cmake create mode 100644 Modules/Compiler/Diab-CXX.cmake create mode 100644 Modules/Compiler/Diab-DetermineCompiler.cmake create mode 100644 Modules/Compiler/Diab-FindBinUtils.cmake create mode 100644 Modules/Compiler/Diab.cmake diff --git a/Help/release/dev/diab-compiler-support.rst b/Help/release/dev/diab-compiler-support.rst new file mode 100644 index 0000000000..2cf0bd6b09 --- /dev/null +++ b/Help/release/dev/diab-compiler-support.rst @@ -0,0 +1,8 @@ +diab-compiler-support +--------------------- + +* `Diab compilers from Wind River Systems`_, versions 5.9.x+, are now + supported with :variable:`compiler id _COMPILER_ID>` ``Diab`` + for languages ``ASM``, ``C``, and ``CXX``. + +.. _`Diab compilers from Wind River Systems`: https://www.windriver.com/resource/wind-river-diab-compiler-product-overview diff --git a/Help/variable/CMAKE_LANG_COMPILER_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ID.rst index a4f899e24c..f46ac73adc 100644 --- a/Help/variable/CMAKE_LANG_COMPILER_ID.rst +++ b/Help/variable/CMAKE_LANG_COMPILER_ID.rst @@ -19,6 +19,7 @@ Value Name ``Clang`` `LLVM Clang`_ ``Cray`` Cray Compiler ``CrayClang`` Cray Clang-based Compiler +``Diab`` `Wind River Systems Diab Compiler`_ ``Embarcadero``, ``Borland`` `Embarcadero`_ ``Flang`` `Classic Flang Fortran Compiler`_ ``LLVMFlang`` `LLVM Flang Fortran Compiler`_ @@ -71,3 +72,4 @@ languages. .. _Tiny C Compiler: https://bellard.org/tcc .. _Tasking Compiler Toolsets: https://www.tasking.com .. _Texas Instruments Clang-based Compilers: https://www.ti.com/tool/download/ARM-CGT-CLANG +.. _Wind River Systems Diab Compiler: https://www.windriver.com/resource/wind-river-diab-compiler-product-overview diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index 2817d37776..ad73373eaa 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -89,6 +89,7 @@ function(compiler_id_detection outvar lang) MSVC ADSP IAR + Diab ) if ("x${lang}" STREQUAL "xC") list(APPEND ordered_compilers diff --git a/Modules/CMakeDetermineASMCompiler.cmake b/Modules/CMakeDetermineASMCompiler.cmake index 412fe36abf..d3b425a3e6 100644 --- a/Modules/CMakeDetermineASMCompiler.cmake +++ b/Modules/CMakeDetermineASMCompiler.cmake @@ -110,6 +110,10 @@ if(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER_ID) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_IAR ) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_IAR "IAR Assembler") + list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS Diab) + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_Diab "-V" ) + set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_Diab "Wind River Systems") + list(APPEND CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDORS ARMCC) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_FLAGS_ARMCC ) set(CMAKE_ASM${ASM_DIALECT}_COMPILER_ID_VENDOR_REGEX_ARMCC "(ARM Compiler)|(ARM Assembler)|(Arm Compiler)") diff --git a/Modules/Compiler/Diab-ASM.cmake b/Modules/Compiler/Diab-ASM.cmake new file mode 100644 index 0000000000..ccc8cb69f7 --- /dev/null +++ b/Modules/Compiler/Diab-ASM.cmake @@ -0,0 +1,3 @@ +include(Compiler/Diab) + +__compiler_diab(ASM) diff --git a/Modules/Compiler/Diab-C.cmake b/Modules/Compiler/Diab-C.cmake new file mode 100644 index 0000000000..0fd5345924 --- /dev/null +++ b/Modules/Compiler/Diab-C.cmake @@ -0,0 +1,9 @@ +include(Compiler/Diab) + +__compiler_diab(C) + +# c89/90 is both -Xdialect-c89 +set(CMAKE_C89_STANDARD_COMPILE_OPTION "-Xdialect-c89") +set(CMAKE_C90_STANDARD_COMPILE_OPTION "-Xdialect-c89") +set(CMAKE_C99_STANDARD_COMPILE_OPTION "-Xdialect-c99") +set(CMAKE_C11_STANDARD_COMPILE_OPTION "-Xdialect-c11") diff --git a/Modules/Compiler/Diab-CXX.cmake b/Modules/Compiler/Diab-CXX.cmake new file mode 100644 index 0000000000..a8a17c51a9 --- /dev/null +++ b/Modules/Compiler/Diab-CXX.cmake @@ -0,0 +1,12 @@ +include(Compiler/Diab) + +__compiler_diab(CXX) + +# Diab C++98 is named as -Xdialect-c++03 +set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-Xdialect-c++03") +set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-Xdialect-c++11") +set(CMAKE_CXX14_STANDARD_COMPILE_OPTION "-Xdialect-c++14") +set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-Xdialect-c++17") +set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-Xdialect-c++20") + +__compiler_check_default_language_standard(CXX 4.0 98 5.0 11) diff --git a/Modules/Compiler/Diab-DetermineCompiler.cmake b/Modules/Compiler/Diab-DetermineCompiler.cmake new file mode 100644 index 0000000000..86518f5fe5 --- /dev/null +++ b/Modules/Compiler/Diab-DetermineCompiler.cmake @@ -0,0 +1,10 @@ +# Diab Toolchain. Works only for versions 5.9.x or higher. +set(_compiler_id_pp_test "defined(__DCC__) && defined(_DIAB_TOOL)") + +set(_compiler_id_version_compute " + # define @PREFIX@COMPILER_VERSION_MAJOR @MACRO_DEC@(__VERSION_MAJOR_NUMBER__) + # define @PREFIX@COMPILER_VERSION_MINOR @MACRO_DEC@(__VERSION_MINOR_NUMBER__) + # define @PREFIX@COMPILER_VERSION_PATCH @MACRO_DEC@(__VERSION_ARCH_FEATURE_NUMBER__) + # define @PREFIX@COMPILER_VERSION_TWEAK @MACRO_DEC@(__VERSION_BUG_FIX_NUMBER__) +" +) diff --git a/Modules/Compiler/Diab-FindBinUtils.cmake b/Modules/Compiler/Diab-FindBinUtils.cmake new file mode 100644 index 0000000000..7ca00cb57f --- /dev/null +++ b/Modules/Compiler/Diab-FindBinUtils.cmake @@ -0,0 +1,15 @@ +# Find the archiver for the compiler architecture, which is always in the same +# directory as the compiler. +if(NOT DEFINED _CMAKE_PROCESSING_LANGUAGE OR _CMAKE_PROCESSING_LANGUAGE STREQUAL "") + message(FATAL_ERROR "Internal error: _CMAKE_PROCESSING_LANGUAGE is not set") +endif() + +get_filename_component(__diab_path "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" DIRECTORY) + +find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR + NAMES dar + HINTS ${__diab_path} + NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH + DOC "Diab Archiver" +) +mark_as_advanced(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR) diff --git a/Modules/Compiler/Diab.cmake b/Modules/Compiler/Diab.cmake new file mode 100644 index 0000000000..cf32139632 --- /dev/null +++ b/Modules/Compiler/Diab.cmake @@ -0,0 +1,33 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# This module is shared by multiple languages; use include blocker. +if(__COMPILER_Diab) + return() +endif() +set(__COMPILER_Diab 1) + +include(Compiler/CMakeCommonCompilerMacros) + +macro(__compiler_diab lang) + set(CMAKE_${lang}_VERBOSE_FLAG "-#") + set(CMAKE_${lang}_OUTPUT_EXTENSION ".o") + + string(APPEND CMAKE_${lang}_FLAGS_INIT " ") + string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g") + string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -O -Xsize-opt") + string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -XO") + string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -XO -g3") + + set(__DIAB_AR "${CMAKE_${lang}_COMPILER_AR}") + set(CMAKE_${lang}_CREATE_STATIC_LIBRARY "\"${__DIAB_AR}\" -r ") + set(CMAKE_${lang}_ARCHIVE_CREATE "\"${__DIAB_AR}\" -r ") + + set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES) + set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES) + set(CMAKE_${lang}_COMPILE_OPTIONS_IPO -XO -Xwhole-program-optim) +endmacro() + +set(CMAKE_EXECUTABLE_SUFFIX "") +set(CMAKE_LIBRARY_PATH_TERMINATOR "") +set(CMAKE_LIBRARY_PATH_FLAG "")