5
votes

We work with a specific compiler, which is called Cadul. It has its own libraries, targets etc. The problem is that CMake does not support it in contrast to such "standard" compilers as GNU, Intel, Clang etc.

Firstly I thought to use cross compiling but it didn't work, since the host and target platforms are the same.

Then I looked into Modules, where I found the directory named "Compiler" which contains a lot of ".cmake" files specified for each compiler and each enabled language. I tried to substitute the word "GNU" by "Cadul" and hoped to see any changes, such as "The CXX compiler identification is Cadul ...". But it didn't happen.

Then I just removed the whole directory "Modules" from cmake and hoped to see that it doesn't work anymore. Surprisingly it did.

So has anyone ever integrated a new compiler to Cmake? With its own features, etc.

2
You can use the toolchain.txt file, look it up in the cmake documentation please. - πάντα ῥεῖ
The problem is that CMake does not support it - What do you mean? Does CMake pass wrong parameters to your compiler? Or what? - Tsyvarev
cmake -DCMAKE_CXX_COMPILER=/path/to/cadul ../ what does this do? - Christian Rapp
I did that once wit some weird C compiler: toolchain file and a bash wrapper for the hard stuff. - Velkan
@Velkan Thanks for advice. It seems to be the correct way. But I thought we use toolchain.txt only if we use a different target system? I would be very happy if you tell me more about that bash wrapper, I have never done it before. - Milayamila

2 Answers

1
votes

It looks like this has been recommended in the comments, but no one has condensed it to an answer yet.

You can choose a compiler by adding these lines to your CMakeLists.txt (source):

SET(CMAKE_C_COMPILER /path/to/c/compiler)
SET(CMAKE_CXX_COMPILER /path/to/cpp/compiler)

If you need to customize further, using a toolchain file works well. There are some examples in the documentation here.

0
votes

Yes, I've done this before. But you need a lot more then just setting the compiler path (since CMake would try to identify this compiler and then - since it's unknown to CMake - would throw an error).

An example implementation of a new "compiler" can be found in my answer here:

It shows a enable_language(FOO) example that could be replaced with enable_language(Cadul).