CMAKE's undefined variable in document 3.21.but could be used

hi, i’m a new cmake.
now using cmake(v3.21) + ninja(v1.5) build cross-compiler enviroment by compiler Tasking v6.2r2

cause the compiler’s arguments are a little bit different from gcc,
I have to use custom commands and custom target to make the building.

I’m quite confused with the CMAKE documents,
there are lots of cmake varibles which not described in docs.
E.g CMAKE_C_COMPILER_WORKS

should be like “CMAKE_<< LANG >>_COMILER_WORKS”,
but I could not find the definition in the newest docs online
https://cmake.org/cmake/help/v3.21/manual/cmake-variables.7.html

but it really works well.

I’d be very appreciated if anyone could give me some advice about
“how to search CMAKE variable’s definition like CMAKE_C_COMPILER_WORKS”

This variable is not documented on purpose because it is an internal one. You must not rely on it or change its value.

Only Public variables are documented.

If your compiler is not compatible with already supported ones, you have to define a toolchain file rather than hacking internal variables.

thanks for the rely.

An additional question:

the tasking compiler is a little different from gcc,
for a normal compiling command would be
E.g gcc -c xx.c -o xx.o

but in Tasking
-c is used for iso-c standard selection.

while using self-defined toolchain-file,
the ninja default generator generated the rules in ninja.build as
" ctc.exe -c xx.c -o xx.o"
(I could not find or modify the Ninja generating template Orz,
so I have to use custom command)

the generated default command “ctc.exe -c xx.c -o xx.o”
would be recognized as wrong argument.

the correct command would be " ctc.exe -o xx.o xx.c"

does there any compiling rule setting existed,
which could be defined by user as a new rule template?
just like CMAKE_C_LINK_EXECUTABLE

thank you.

You don’t have to rely on custom commands to compile C source files, but define all needed information as part of the toolchain file.

Variable defining source compilation is CMAKE_C_COMPILE_OBJECT. See Modules/CMakeCInformation.cmake for the generic definition…

Many thanks, it’s very helpful~
I will have a try

m( _ _ )m

hi,
I have another question while editing the rule,
would you please give me some advice?

my target is to set the the command like the following
command1:
"cc -o ./aa_path/xxxx.asm -d ./bb_path/xxxx.d -c ./cc_path/xxxx.c -e ./dd_path/xxxx.c_err_log "
command2:
"ss -o ./oo_path/xxxx.o -s ./aa_path/xxxx.asm "

force to compiler the file in the raw folder(not copied into cmakefile folder)
and output the .asm .obj .dep, .error_log file into my target tmp folder.

I could modify the variable which you offered me before,
set(CMAKE_C_COMPILE_OBJECT
“<CMAKE_C_COMPILER> < DEFINES> < INCLUDES> < FLAGS> -o < OBJECT> -c < SOURCE>”

my question ares:

  1. is there any rule like $(c_files:.c=.d) function in cmake?
  2. how to force the output to my target path, not CMakeFiles folder?
  3. how to add “-e ./dd_path/xxxx.c_err_log” into CMAKE_C_COMPILE_OBJECT?
  4. how to add two command into one command message?

Why do you want to generate temporary asm file? Your compiler is not able to directly generate object file?

For 1., No, there is no such possibility. For dependencies, see Modules/Compiler/GNU.cmake, the setting of variable CMAKE_DEPFILE_FLAGS_${lang}. The expected dependency file should be in a format compatible with GNU. See also CMAKE_DEPENDS_USE_COMPILER.
2. I think it is not possible.Why do you want this, anyway?
3. I think it is not possible
4. CMAKE_C_COMPILE_OBJECT is a CMake list. So multiple commands can be specified.

The tasking C compiler is just generating assembler source, like its macro assembler does. And afterwards the assembler is used to generate an object file. And C++ is first converted to C.

About 2. You should not care too much about the location of intermediate files. I think CMake does not provide any settings to change this.

About 3. -e is not a documented flag. I assume you want to create the error file. Here again, you should adopt to the naming that CMake uses, then you can do something like --error-file=<OBJECT>.err.log.
But be aware that those messages are not shown on STDERR anymore AFAIR.

About 4.
For CMake it’s a lot better to use the control program cctc instead of the separate tools. Otherwise you can’t easily define the flags of the several tools at the same time.
Example: For a .cpp <FLAGS> will be expanded to the C++ Flags, but you can’t access those needed for the intermediate C file or the assembler.

Why do you want to generate temporary asm file? Your compiler is not able to directly generate object file?

Answer:You know, in MCU development, sometimes the asm files are useful for the debugging if necessary. The object files actually could be generate directly in another way. I just want to know, by CMake, if it is possible to do all the process what I did in makefile before .

  1. I think it is not possible.Why do you want this, anyway?

Answer: I just want to know whether there existed a way to set the rule, because I am a new CMake user, I hope to grasp more

  1. CMAKE_C_COMPILE_OBJECT is a CMake list. So multiple commands can be specified.

Answer: I used ‘&&’ to connect the two command, but failed. I thought the < test_variable> in CMAKE_C_COMPILE_OBJECT could be a defined cmake-variable, but some of them doesn’t work.
please correct me if I misunderstood it. and I 'd be appreciated that if you could offer me some advice about the definition of < variable>'s in the command, and how to find their definitions. ( like “CMAKE_C_COMPILE_OBJECT” could be found int Modules/CMakeCInformation.cmake )
< test_variable> and ${test_variable} seems different, what’s the difference?

thanks a lot for your quick reply
m(_ _)m

I defined compiler as follows:

SET(CMAKE_C_COMPILER “${CCPATH}/ctc/bin/ctc.exe”)
SET(CMAKE_CXX_COMPILER “${CCPATH}/ctc/bin/cptc.exe”)
SET(CMAKE_ASM_COMPILER “${CCPATH}/ctc/bin/astc.exe”)
SET(CMAKE_LINKER “${CCPATH}/ctc/bin/ltc.exe”)

set(CMAKE_C_COMPILE_OBJECT
“<CMAKE_C_COMPILER> -o .src --dep-file=<DEP_FILE> --error-file=.c_err && <CMAKE_ASM_COMPILER> -o .src <ASM_OPTIONS>”)

In build.ninja file, only "CMAKE_ASM_COMPILER " could NOT be replaced by the actual path, I don’t know the reason why… (while c/cxx/link works well)

I used ${CMAKE_ASM_COMPILER} instead of < CMAKE_ASM_COMPILER>, it seems that it could works, but I want to know the difference, the system ASM compiler did not be correctly defined like C compiler in my env. it might be some settings missing in my CMakelist.txt

many thanks for the reply

For CMake it’s a lot better to use the control program cctc instead of the separate tools. Otherwise you can’t easily define the flags of the several tools at the same time.
Example: For a .cpp <FLAGS> will be expanded to the C++ Flags, but you can’t access those needed for the intermediate C file or the assembler.

yes, CMake did a lot for users, It’s convenient for GCC users, as all the settings are unambiguous.
But for some compiler like Tasking, if you have some customed setting, you have to know lot of setting’s source to let the CMake do the same things as MAKE, which drives me crazy cause I could not find all the information by online-document. Fortunately, I could be helped by some warm-hearted users like you and @ Marc Chevrier
Thanks again for your warm reply

“cctc” is a sample way, and I am a new CMake user, so I hope to know more about “What I can do” in CMake. :grinning:

To execute multiple commands, as part of object compilation, set a list of commands:

set(CMAKE_C_COMPILE_OBJECT "first command" "second command")

Variable CMAKE_<LANG>_COMPILE_OBJECT is for ONE language. You cannot use patterns (i.e. names insides <>) of different languages inside this variable.

What you are trying to do is quite an advanced CMake usage. May I recommend to you to have a look at this book which covers many aspects of CMake, including advanced features.

1 Like

For getting the assembler files you can use the flag --keep-temporary-files on the control program.

If everything is configured correctly the control program produces hex-identical builds. In fact it’s internally calling the separate tools itself, you can check this with --verbose.

Using the control program, Tasking behaves more or less like other compilers do.

many thanks for the recommandation.

I used " CMD /S /C “xxx && xxx” " to temporarily solved it.
and I will try your suggestion later.

thanks again
m(_ _)m

thanks for the advice.
It could work easily with CMake + Ninja.

Thanks again
m(_ _)m