3

I am writing a script and started working with the install command (for copying files) and it is not working. CMake configure/generate does not show any errors (i.e. it does not stop and no warnings/errors show related to this command) and the command does not seem to be working, because I don't see any files being copied.

Since I am new, I am wondering:

  • How can I tell that install failed (perhaps the source directory was wrong, or the destination directory was wrong)? It appears to be failing silently.
  • Are there error codes I can check to see what went wrong?
  • When is install called? When I click configure? Or when the project is built?

I am on Windows.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Samaursa
  • 16,527
  • 21
  • 89
  • 160

2 Answers2

2

To the general question, there are a number of ways to get more verbose output from CMake - I just learned a third for gnarly errors:

  1. to debug CMake recipes, I like using the message command and you can even iterate over directories and issue messages*
    • e.g. message( STATUS "SQLITE3_LIB: ${SQLITE3_LIB} SQLITE3_PATH: ${SQLITE3_PATH}") # prints SQLITE3_LIB and SQLITE3_PATH variables
  2. perform verbose builds to troubleshoot your build itself
    • run make VERBOSE=1 (with make, ninja -v with ninja, etc.) to help you troubleshoot the process, such as cmake -DYOUR_OPTION="insert values" ~/path/to/files/ && make VERBOSE=1
  3. if you ever find an inscrutable error, I just learned that we can run strace on the failing command - this can be a bit overwhelming, but can help when you have exhausted #1 and #2
    • I just used strace /usr/bin/cmake -E copy_directory $MY_SOURCE_PATH $MY_DEST_PATH to try to understand why a copy was failing

*I have used DLRdave's answer to a different question to print out the INCLUDE_DIRS:

get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
  message(STATUS "dir='${dir}'")
endforeach()
Community
  • 1
  • 1
sage
  • 4,863
  • 2
  • 44
  • 47
1

When you add an install command to your CMakeLists.txt, you get a new target created called "install".

In order to actually install the chosen files/targets, you need to build this install target. It's not automatically built as part of the "ALL" target.

For example, if you're using Visual Studio, the "INSTALL" target should appear in the "CMakePredefinedTargets" folder of the Solution Explorer. Just selecting this target and building it will cause the solution to be built and the selected items installed.

If any part of the build or install process fails, the notifications should then be apparent.

Fraser
  • 74,704
  • 20
  • 238
  • 215
  • That makes a lot of sense. Either I am not looking hard enough or the documentation does a poor job at describing these details. – Samaursa Mar 24 '13 at 01:07
  • 1
    [This tutorial](http://www.cmake.org/cmake/help/cmake_tutorial.html#s3) might help a bit? – Fraser Mar 24 '13 at 02:19