Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have cmake unpack my compiler

Tags:

cmake

In order to ensure that my Linux builds are identical regardless of the distribution the build host uses, I have packaged up my compiler and the sysroot files into a relocatable tar file and checked that into source control.

So the first step in any build (or at least, a step that must be invoked before any compile step) must be to extract this tar file.

If I was using a makefile, this would be simple to do. However, the project is using cmake and I can't figure out any way to do it with cmake. It might even be that I need this extract step invoked before cmake starts to detect the compiler: I can hard-code the compiler name but if cmake fails if it can't find the compiler then I need the unpack to happen before that test.

Is this possible with cmake?

like image 661
MadScientist Avatar asked Jan 30 '13 22:01

MadScientist


People also ask

Can you use CMake with C?

In the C/C++ ecosystem, the best tool for project configuration is CMake. CMake allows you to specify the build of a project, in files named CMakeLists. txt, with a simple syntax (much simpler than writing Makefiles).

What is build tree in CMake?

Build Tree. The top-level directory in which buildsystem files and build output artifacts (e.g. executables and libraries) are to be stored. CMake will write a CMakeCache. txt file to identify the directory as a build tree and store persistent information such as buildsystem configuration options.

Is CMake better than make?

So, what is the real difference? CMake is much more high-level. It's tailored to compile C++, for which you write much less build code, but can be also used for general purpose build. make has some built-in C/C++ rules as well, but they are useless at best.


1 Answers

You can use execute_process to invoke cmake's cross-platform command mode (cmake -E tar). The command would be something like:

execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf MyCompiler.bz2)

The command which causes CMake to check for a valid compiler is project, so as long as you have your execute_process call before the project call, the unpacking will be done before the compiler check.

like image 93
Fraser Avatar answered Oct 07 '22 03:10

Fraser