4

I was trying to use cmake to install some libraries and executables that are built via cmake.

I found What is cmake equivalent of 'configure --prefix=DIR && make all install '? which seemed to be easy. It looked like you just need to set the cmake variable CMAKE_INSTALL_PREFIX and then make install should work.

I found that setting the cmake variable alone did not fix make install and I kept getting the error message "No rule to make target install".

How do you fix cmake .. && make install "No rule to make target install"?

p.s. cmake version is 2.8.x

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177

1 Answers1

7

I consulted the Cmake textbook I have (or if you go to [the cmake tutorial0(https://cmake.org/cmake-tutorial/)). According to the textbook, in addition to setting the cmake variable CMAKE_INSTALL_PREFIX you also need to invoke the cmake function install() for anything you wish to be installed via the generated Makefile.

So in my case I set the variable in my CMakeLists.txt via:

set(CMAKE_INSTALL_PREFIX path/to/directory)

then under each add_library() and add_executable() I added:

install(TARGETS name1
    DESTINATION ${CMAKE_INSTALL_PREFIX}
    )

Then when I did cmake .. && make && make install I was successful and the expected files were installed at the expected destination.

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
  • This is not really a generic solution. Might have worked in your case, but in general there are different ways to set up a CMake project. The readme or some kind of documentation should tell you how to use it, if it's not obvious. – super Apr 26 '18 at 17:07
  • 1
    @super i guess this is not so generic. feel free to edit my solution. the point of my solution is that you have to have at least one `install()` function call in your `cmake` project. So my solution attempts to provide a [MCVE](https://stackoverflow.com/help/mcve) to demonstrate the `cmake` function API usage for `install()`. – Trevor Boyd Smith Apr 26 '18 at 19:26
  • 1
    take a look at [GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) built-in module also.. Then define config.cmake file also... – Mizux Apr 27 '18 at 16:20
  • 1
    This answer helps a lot. Thank you, soldier! Too much gung ho for a **generic solution** that fails to spark a learning **aha** moment is pure evil. I believe in the strive for a **generic solution** in certain domains, but given the context that software build systems is an infant piece of engineering, it is better to expose the primitives necessary for new constructions. – daparic Apr 10 '20 at 20:34
  • 1
    @eigenfield thank you for understanding the reason i wrote this up (i.e. get something going that is easy to understand). the kind words are a nice counter balance to the criticisms of 'your solution is not generic'. i think the idea of "strive for generic solution" is a good idea... which is what i do in most of my code (because building robust generic solutions are 2-10x more lines and can be 2-10x harder to understand and can take 2x-10x more time to develop... and more importantly... most code does not need robust generic solutions). – Trevor Boyd Smith Oct 26 '20 at 14:18