[CMake] Using GET_PREREQUISITES()

Timothy M. Shead tshead at sandia.gov
Mon Jun 8 13:02:10 EDT 2009


Folks:

I've been experimenting with using GET_PREREQUISITES() to automatically 
generate packages that contain third-party dependencies, and I'm curious 
to hear about other people's experiences.  The main challenge seems to 
be that you need to run GET_PREREQUISITES() at install-time, i.e. after 
your binaries are built.  In the following example, I generate a script 
that contains the path to my built binary, then run the script at 
install-time using INSTALL(SCRIPT ...)  It all works great, but I had to 
use FILE(INSTALL ...) which isn't documented anywhere (I noticed it in 
the cmake_install.cmake files generated by CMake) in my install-time 
script.  Is this supported?  Is there some better way to do it?

Cheers,
Tim

# CMakeLists.txt
GET_TARGET_PROPERTY(MY_BINARY_LOCATION my_binary LOCATION)
CONFIGURE_FILE(
   "${CMAKE_CURRENT_SOURCE_DIR}/dependencies.cmake.in"
   "${CMAKE_CURRENT_BINARY_DIR}/dependencies.cmake"
   @ONLY
   )
INSTALL(SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/dependencies.cmake")

# dependencies.cmake.in
INCLUDE(GetPrerequisites)
GET_PREREQUISITES(@MY_BINARY_LOCATION@ DEPENDENCIES 1 1 "" "")

FOREACH(DEPENDENCY ${DEPENDENCIES})
   GET_FILENAME_COMPONENT(DEPENDENCY_NAME "${DEPENDENCY}" NAME)
   GET_FILENAME_COMPONENT(DEPENDENCY_ACTUAL "${DEPENDENCY}" REALPATH)
   FILE(INSTALL
     DESTINATION "${CMAKE_INSTALL_PREFIX}/lib"
     TYPE EXECUTABLE
     RENAME "${DEPENDENCY_NAME}"
     FILES "${DEPENDENCY_ACTUAL}"
     )
ENDFOREACH()

-- 
Timothy M. Shead
Data Analysis & Visualization (1424)
Sandia National Laboratories
505-284-0139



More information about the CMake mailing list