Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify the path where CMake is installed in the CMakeLists.txt

Tags:

c++

linux

cmake

I downloaded the portable CMake version from the official site, and installed it in my home directory(~/usr) because I don't have root or sudo permission.

How do I specify the path where CMake is installed in CMakeLists.txt, such as ~/usr/cmake-path/bin/cmake?

Note: I don't want to use the default version of CMake on the Linux system for it's too old (version 2.6)

PS:

I know of the variable CMAKE_COMMAND which may be useful for my question, but I don't know how to use it!

like image 795
YoungkingWang Avatar asked Sep 23 '14 03:09

YoungkingWang


2 Answers

I feel a more robust solution is to prepend your cmake path to the PATH environment variable.

export PATH=~/usr/cmake-path/bin:$PATH

If your on an Ubuntu/Debian system you can add this command to your ~/.bashrc to execute it with every terminal session. Note, this change will only affect your account and you can set it without administrator permissions.

This way you only need to type cmake and the desired version will be found first.

like image 51
jmstoker Avatar answered Oct 30 '22 23:10

jmstoker


CMake will use whatever path the running CMake executable is in. Furthermore, it may get confused if you switch paths between runs without clearing the cache.

So what you have to do is simply instead of running cmake <path_to_src> from the command line, run ~/usr/cmake-path/bin/cmake <path_to_src>.

You may want to add an alias or a shell script to the path that is a little more typeable (so you only have to type my_cmake <path_to_src> or something like that).

Note that there is no clean way to solve this by just editing the CMakeLists.txt. While in theory you could have CMake 2.6 run an outer CMake script that does nothing but running an inner CMake script from a 3.0 executable, that's just a dirty hack. Just run the correct executable from the command line and you should be fine.

like image 4
ComicSansMS Avatar answered Oct 30 '22 21:10

ComicSansMS