Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the possible values for the LANGUAGE variable in CMAKE

Tags:

cmake

I haven't been able to find a list of possible values for the LANGUAGE variable on the CMAKE.org site or anywhere else. Would someone please enumerate the values CMAKE recognises? I specifically need to specify Objective C++.

like image 495
gone Avatar asked Jul 02 '14 14:07

gone


People also ask

How do you define a variable in CMake?

Options and variables are defined on the CMake command line like this: $ cmake -DVARIABLE=value path/to/source You can set a variable after the initial `CMake` invocation to change its value. You can also undefine a variable: $ cmake -UVARIABLE path/to/source Variables are stored in the `CMake` cache.

What language does CMake use?

The executable programs CMake, CPack, and CTest are written in the C++ programming language. Much of CMake's functionality is implemented in modules that are written in the CMake language.

How can I see CMake variables?

Another way to view all cmake's internal variables, is by executing cmake with the --trace-expand option. This will give you a trace of all . cmake files executed and variables set on each line. Save this answer.


2 Answers

Just take a look at all the CMakeDetermine<Language>Compiler.cmake scripts CMake ships with.

This would result - in alphabetic order - in the following you could put in the enable_language() call:

  1. ASM
  2. ASM-ATT
  3. ASM-MASM
  4. ASM-NASM
  5. C
  6. CSharp
  7. CUDA
  8. CXX
  9. Fortran
  10. Java
  11. OBJC (Objective C)
  12. OBJCXX (Objective C++)
  13. RC (Windows Resource Compiler)
  14. Swift

Evaluated with CMake Version 3.16

References

  • enable_language()
  • Generic rule from makefile to CMake
like image 135
Florian Avatar answered Oct 18 '22 04:10

Florian


Update for CMake 3.16 and later: CMake added native support for Objective-C in version 3.16. The corresponding language strings are OBJC and OBJCXX. Thanks to squareskittles for pointing this out.

Original answer: The support for languages varies across platforms.

Currently CMake supports C, CXX and Fortran out of the box on most platforms. There is also support for certain Assemblers on some platforms. For a complete list, check out the contents of the Modules/Platform folder.

The idea is that the language given to the LANGUAGE field of the project command or the enable_language command is just a string, which will then be used by CMake together with the language dependent variables to setup the build system. The Platform scripts shipping with CMake do this configuration for C and C++. In theory, one can add their own language simply by setting the correct variables (although this is quite involved and I do not know of anyone ever successfully doing this).

As for adding support for Objective-C: Since most toolchains use the same compiler for C and Objective-C, you do not need to configure a new language. Simply compile your code as if it was plain C and add the appropriate compiler flags for Objective-C support.

Unfortunately, this is not very comfortable to use and can easily break in corner cases. But until CMake adds explicit support for Objective-C as a first class language, I'm afraid this is as good as it gets.

like image 33
ComicSansMS Avatar answered Oct 18 '22 05:10

ComicSansMS