6

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.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Milayamila
  • 61
  • 2
  • You can use the `toolchain.txt` file, look it up in the cmake documentation please. – πάντα ῥεῖ Jul 29 '16 at 16:49
  • `The problem is that CMake does not support it` - What do you mean? Does CMake pass wrong parameters to your compiler? Or what? – Tsyvarev Jul 29 '16 at 18:34
  • `cmake -DCMAKE_CXX_COMPILER=/path/to/cadul ../` what does this do? – Christian Rapp Jul 30 '16 at 07:50
  • I did that once wit some weird C compiler: toolchain file and a bash wrapper for the hard stuff. – Velkan Aug 01 '16 at 06:16
  • @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 Aug 01 '16 at 12:14
  • @ChristianRapp This says the following:-- Configuring done -- Generating done -- Build files have been written to: D:/arrays. As soon as I look for updates in my folder, I see just CMakeCache.txt updates but no Makefiles created. – Milayamila Aug 01 '16 at 12:15
  • @Milayamila, I call 'bash wrapper' a script with hacks to grind a bit the input parameters to fit what the compiler expects. For that compiler, for example, I had to parse the `-D` flags and write them as `#define` into the files that were compiled. – Velkan Aug 01 '16 at 12:23
  • @Tsyvarev So if I use Cmake-gui and specify my CXX compiler by giving the right path, than my Cmake interpretates it as GNU 4.9.3 and says: You have changed variables that require your cache to be deleted. Configure will be re-run and you may have to reset some variables. The following variables have changed: CMAKE_CXX_COMPILER= D:/daily_08_02/Z710_RSC/tools/cadul/bin/cxx386.exe – Milayamila Aug 01 '16 at 12:26
  • @Velkan, So basically this is such in script in which you define specific compiler flags? – Milayamila Aug 01 '16 at 12:33
  • @Milayamila specific compiler flags can be added in the toolchain file. The script is useful when there are incompatibilities with the existing flags (it's the place to do arbitrary things). – Velkan Aug 01 '16 at 12:43
  • @Velkan, I will try that, thanks a lot!! – Milayamila Aug 01 '16 at 13:00

2 Answers2

2

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.

Francesca Nannizzi
  • 1,695
  • 13
  • 18
1

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).

Florian
  • 39,996
  • 9
  • 133
  • 149