[CMake] install() question

Michael Hertling mhertling at online.de
Thu Oct 13 16:47:16 EDT 2011


On 10/13/2011 07:09 PM, Robert Dailey wrote:
> First of all I'm using cmake 2.8.6 and generating Visual Studio 2003
> projects with it.
> 
> There is a particular project that needs to first copy its header files to a
> specific directory in a specific structure. After that, all other projects
> need to reference this project's source code from the installed location,
> not its actual location that it was copied from.
> 
> The install() command sounded perfect for this but unfortunately it seems
> that the INSTALL project builds *last*. What I need is for the files to be
> installed/copied FIRST, so that the other projects will succeed when I build
> them.
> 
> Any idea if install() can do this? I'm not really sure of the purpose for
> install(), so maybe I'm approaching this wrong.

You might use an installation component for the concerned headers:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(INSTCOMP C)
SET(CMAKE_VERBOSE_MAKEFILE ON)
SET(F_PREFIX "/dev/shm" CACHE PATH "")
FILE(WRITE ${CMAKE_BINARY_DIR}/f.h "void f(void);\n")
INSTALL(FILES ${CMAKE_BINARY_DIR}/f.h
    DESTINATION ${F_PREFIX}/include
    COMPONENT f)
ADD_CUSTOM_TARGET(f_install
    ${CMAKE_COMMAND} -DCOMPONENT=f -P cmake_install.cmake)
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c
"#include <${F_PREFIX}/include/f.h>
int main(void){return 0;}
")
ADD_EXECUTABLE(main main.c)
ADD_DEPENDENCIES(main f_install)

The f.h header is selectively installed via the f_install custom
target, and due to the main-on-f_install dependency, it will be
installed before the main target is built.

'hope that helps.

Regards,

Michael


More information about the CMake mailing list