On 10/06/2011 08:23 AM, [email protected] wrote:
> Hello,
> 
> I would like to create a custom install target: install-update
> The things done by this target are:
> - change CMAKE_INSTALL_PREFIX to a specific directory: 
> CMAKE_BINARY_PREFIX/PROJECT_NAME-REVISION_NUMBER
> - run "make install"
> 
> I don't know how to launch a defined target from within cmake. Is there any 
> simple solution to do that ?
> 
> Best regards,
> 
> YC

Look at the attached exemplary CMakeLists.txt file. However, note that

- changing the CMAKE_INSTALL_PREFIX means invalidating the build tree,
  so the whole project is built anew when install-update is triggered,
- triggering install-update means rebuilding *and* installing, so you
  possibly need root privileges for this to succeed; building as root
  is inadvisable, so you should perhaps limit yourself to a target
  "build-update" without the install step and run "make install"
  in the end as usual.

'hope that helps.

Regards,

Michael
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(INSTALLUPDATE C)
SET(CMAKE_VERBOSE_MAKEFILE ON)
SET(CMAKE_BINARY_PREFIX "/dev/shm" CACHE STRING "")
SET(REVISION_NUMBER "0" CACHE STRING "")
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "int main(void){return 0;}\n")
ADD_EXECUTABLE(main main.c)
INSTALL(TARGETS main DESTINATION bin)
ADD_CUSTOM_TARGET(install-update
    COMMAND ${CMAKE_COMMAND} 
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_PREFIX}/${PROJECT_NAME}-${REVISION_NUMBER}
 ${CMAKE_BINARY_DIR}
    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target install 
--config "$<CONFIGURATION>")
--
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to