How can I use CMake with GreenHills compiler

Hello,

I have been trying to use CMake to generate Makefiles for a C project compiling using GreenHills compiler. But I am getting these errors:

– The C compiler identification is GHS
– The CXX compiler identification is GHS
– Detecting C compiler ABI info
CMake Error: Generator: execution of make failed. Make command was: C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe/gbuild.exe -top CMAKE_TRY_COMPILE.top.gpj cmTC_dd868.tgt.gpj &&
– Detecting C compiler ABI info - failed
– Check for working C compiler: C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe
CMake Error: Generator: execution of make failed. Make command was: C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe/gbuild.exe -top CMAKE_TRY_COMPILE.top.gpj cmTC_86df9.tgt.gpj &&
– Check for working C compiler: C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe - broken
CMake Error at C:/Sources/cmake-3.21.3-windows-x86_64/share/cmake-3.21/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler

"C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: C:/UIDE/build/CMakeFiles/CMakeTmp

Run Build Command(s):C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe/gbuild.exe -top CMAKE_TRY_COMPILE.top.gpj cmTC_86df9.tgt.gpj && The system cannot find the file specified
Generator: execution of make failed. Make command was: C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe/gbuild.exe -top CMAKE_TRY_COMPILE.top.gpj cmTC_86df9.tgt.gpj &&

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)

– Configuring incomplete, errors occurred!
See also “C:/UIDE/build/CMakeFiles/CMakeOutput.log”.
See also “C:/UIDE/build/CMakeFiles/CMakeError.log”.

Could you please help?

What was the full command to CMake to receive this output?

I’m confused why the output shows gbuild.exe. This is the build tool for GHS project files which is a file format very different from Makefiles. You can use GHS compilers with Ninja or Make but then you need to run the appropriate generator and use the correct compiler options.

CMake can also be used to generate GHS project files for use with MULTI and gbuild.exe.
In this case the command line would be something like: cmake -G "Green Hills MULTI" -T "C:\AGL_2005\COMPILER\ARM\GHS\V2019_5_4" -D GHS_PRIMARY_TARGET=arm_standalone.tgt. ccarm should be the standalone target compiler for ARM. -T is used to specify the directory of where the tools are installed. I made a guess on what target you wanted for GHS_PRIMARY_TARGET. This is usually specific to the board you are targeting and should have been specified when receiving the tools from Green Hills.

@fdk17 Thank you so much Your input is very helpful.

Now it is generated but with another error in the linker

Green Hills MULTI: -A not specified; defaulting to “arm”
– The C compiler identification is GHS 2019.5.4
– The CXX compiler identification is GHS 2019.5.4
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working C compiler: C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe - skipped
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/cxarm.exe - skipped
– Configuring done
CMake Error: CMake can not determine linker language for target: UIDE_test_1.elf
CMake Error: CMake can not determine linker language for target: UIDE_test_1.elf
– Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.

Do you have any suggestion for that?

Sorry, I’ve never seen such an error.

Have you added at least one C/C++ file to your executable?

@jtxa Yes

I solved the problem of this error:
CMake Error: CMake can not determine linker language for target: UIDE_test_1.elf

by adding the following line after the line of “add_executable”
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)

This is usually only necessary, if you don’t have any recognized source files.
So if you have added e.g. a main.cpp to your executable, the language should be automatically set to CXX.

@jtxa
This is confusing!
Because I have already added a main.c file.
Do you think the file couldn’t be read properly?

I don’t know if there are some issues with GHS generator (which I don’t have) or your cmake files.
I made a minimal example to demonstrate it. With if(1) it shows the “can not determine linker language for target” error message. And with if(0) the message vanishes.

cmake_minimum_required(VERSION 3.13)
project(x LANGUAGES C)
add_executable(x)

if(1)
  target_sources(x PRIVATE "${CMAKE_BINARY_DIR}/main.unknown")
  file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/main.unknown" CONTENT "")
else()
  target_sources(x PRIVATE "${CMAKE_BINARY_DIR}/main.c")
  file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/main.c" CONTENT "")
endif()

For this error message the content of main.c is irrelevant, because CMake only uses the file extension to decide the language.

I haven’t run into that issue with C and CXX code while using the GHS generator. If you could create a minimum example that demonstrates the issue that would be beneficial to understanding the problem.

Do you have a toolchain file for the GHS tools?

see too cmake/cmake#19743

@ClausKlein No,
I haven’t found it necessary to use one. I do use a small script to run the CMake command. For me it’s working fine. I’m using the Green Hills MULTI generator to use gbuild to parse the integrate file, generate header files, build the kernel, build the applications, and then integrate everything into a Monolith image, then a custom command to deploy image.

I’m not using Ninja for running the build with the GHS compilers. I pushed some changes that incorporates some of the ideas of #19743. cmake/cmake!4136 and cmake/cmake#20089 make it easy to at least compile a file with Ninja but there would be more work for archiving libraries. Then there would be the custom rules for running the integrate and other commands required for building a monolith image.

I work with Ninja and this toolchain:

# Toolchain file for Green Hills Software MULTI environment for Integrity target 
#
# Requires environment variables MULTI_ROOT, INTEGRITY_BASE, and INTEGRITY_BSP
# set to the right directories of the Integrity/PPC environment

set(CMAKE_SYSTEM_NAME GHS-MULTI)
set(CMAKE_SYSTEM_PROCESSOR ppc)
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_CXX_PLATFORM_ID Integrity)

# Disable Compiler tests
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_C_COMPILER_ID_RUN 1)
set(CMAKE_C_ABI_COMPILED 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_ID_RUN 1)
set(CMAKE_CXX_ABI_COMPILED 1)

# Get MULTI root path from environment
file(TO_CMAKE_PATH $ENV{MULTI_ROOT} MULTI_ROOT)
message(STATUS "MULTI_ROOT: ${MULTI_ROOT}")

# Set default cmake flags variables
set(CMAKE_C_FLAGS "-os_dir=$ENV{INTEGRITY_BASE} -bsp=$ENV{INTEGRITY_BSP}")
set(CMAKE_CXX_FLAGS "-os_dir=$ENV{INTEGRITY_BASE} -bsp=$ENV{INTEGRITY_BSP}")
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_C_FLAGS CMAKE_CXX_FLAGS)

# Set compilers
set(CMAKE_C_COMPILER   ${MULTI_ROOT}/ccintppc.exe)
set(CMAKE_CXX_COMPILER ${MULTI_ROOT}/ccintppc.exe)

# Set compilers ID
set(CMAKE_C_COMPILER_ID "GHS")
set(CMAKE_CXX_COMPILER_ID "GHS")

set(CMAKE_C_STANDARD_COMPUTED_DEFAULT 99)
set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT 98)

# Set format for compiling
set(CMAKE_C_COMPILE_OBJECT   "<CMAKE_C_COMPILER>   <DEFINES> <INCLUDES> <FLAGS> -MD -filetype.c  <SOURCE> -o <OBJECT>") 
set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -MD -filetype.cc <SOURCE> -o <OBJECT>")
# TODO: --instantiation_dir=<OBJECT>_") 

# Set format for creating static library
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "${MULTI_ROOT}/cxintppc.exe <LINK_FLAGS> -o <TARGET> <OBJECTS> -keep_objs")
set(CMAKE_C_CREATE_STATIC_LIBRARY   "${MULTI_ROOT}/cxintppc.exe <LINK_FLAGS> -o <TARGET> <OBJECTS> -keep_objs")

# Set format to create executables
set(CMAKE_CXX_LINK_EXECUTABLE "${MULTI_ROOT}/cxintppc.exe <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_C_LINK_EXECUTABLE   "${MULTI_ROOT}/cxintppc.exe <CMAKE_C_LINK_FLAGS>   <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")

set(CMAKE_FIND_ROOT_PATH ${MULTI_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)
1 Like

How can i compile a Assembly file using GHS compile rtoolchain with CMAKE. I tried with setting up target properties as ASM but no luck,

I also have below in my topl level CMAKE list.

enable_language(ASM)
enable_language(C)
enable_language(CXX)

Can some one help me on this. I noticed below
– Warning: Did not find file Compiler/GHS-ASM
– Warning: Did not find file Compiler/GHS-ASM
– Configuring done

Hi fdk17,

I came across your post about using the Green Hills MULTI generator with CMake and had a quick question. I apologize for responding to an old message, but I’m really interested in your approach.

You mentioned that you use the Green Hills MULTI generator to parse the integrate file, generate header files, build the kernel, build the applications, and integrate everything into a Monolith image. Did you manage to do all this natively with the CMake Green Hills MULTI generator, or did you have to add custom commands to achieve this?

I’m currently trying to create a CMake build that uses the Green Hills MULTI generator, but I’m struggling to get it to actually create a Green Hills project that builds a Monolith image. Any insights or guidance would be greatly appreciated!

Thanks,
payneshouse

Many of the build steps are performed via add_custom_target and add_custom_command.