Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Introduce a new compiler to CMake

Tags:

c++

cmake

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.

like image 215
Milayamila Avatar asked Nov 08 '22 11:11

Milayamila


1 Answers

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.

like image 82
Francesca Nannizzi Avatar answered Nov 14 '22 21:11

Francesca Nannizzi