[CMake] Change RPATH at the packaging stage
Vyacheslav Karamov
ubuntulist at yandex.ru
Fri Nov 2 11:31:01 EDT 2012
Oh, that is some kind of special street magic!
RPATH is empty without these lines in CMakeLists.txt
set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_SOURCE_DIR}/cmake/CPackOptions.cmake)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND EXISTS
"${CMAKE_ROOT}/Modules/CPack.cmake")
set(CPACK_PACKAGING_INSTALL_PREFIX ${install_dir})
set(CMAKE_INSTALL_RPATH ${install_dir})
endif()
02.11.2012 16:40, Vyacheslav Karamov пишет:
> Thank you very much, Eric!
> It works!
>
> ----------- CMakeLists.txt ------------------
>
> include (FindSubversion)
>
> if (NOT Subversion_FOUND)
> message(FATAL_ERROR "Please install subversion command-line client and
> add its folder to the system PATH")
> endif()
>
> # Update working copy at every non-debug build
> if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
>
> add_custom_target(svn_up ALL
> # update the working copy
> COMMAND ${Subversion_SVN_EXECUTABLE} up ${CMAKE_SOURCE_DIR}
> )
>
> endif() # if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
>
> # Add code which adds svn revision info at every build
>
> Subversion_WC_INFO(${CMAKE_SOURCE_DIR} ${CMAKE_PROJECT_NAME})
>
> set(chatterbox_revision ${${CMAKE_PROJECT_NAME}_WC_REVISION})
>
> # set product version
> set (chatterbox_version_major 1)
> set (chatterbox_version_minor 0)
> set (chatterbox_version_patch 0)
> set (chatterbox_version "${chatterbox_version_major},
> ${chatterbox_version_minor}, ${chatterbox_version_patch},
> ${chatterbox_revision}")
>
> set(version_h_contents "/**
> * Copyright (c) 2008-2012 Transparent Language, Inc. All rights reserved.
> */
> #define _VESRION_NUMBER_ ${chatterbox_version}
> #define _PRODUCT_NUMBER_ ${chatterbox_version}
> #define _VERSION_STRING_ \"${chatterbox_version}\"
> #define _PRODUCT_STRING_ \"${chatterbox_version}\"
> ")
>
> #Write version.h
> file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/chatterbox/src/version.h"
> ${version_h_contents})
>
> set (package_version
> "${chatterbox_version_major}.${chatterbox_version_minor}.${chatterbox_version_patch}")
>
> add_custom_target(configure_cpack ALL
> # generate cpackoptions.cmake at build time so we get the
> # most recent revision number
> COMMAND ${CMAKE_COMMAND}
> -DSOURCE_DIR=${CMAKE_SOURCE_DIR}
> -Dproj_name=${CMAKE_PROJECT_NAME}
> -Drevision=${chatterbox_revision}
> -Dpack_version=${package_version}
> -P ${CMAKE_SOURCE_DIR}/cmake/Create-cpackoptions.cmake
> )
>
> if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
> add_dependencies(configure_cpack svn_up)
> endif()
>
> set(CPACK_PROJECT_CONFIG_FILE
> ${CMAKE_SOURCE_DIR}/cmake/CPackOptions.cmake)
>
> ----------- CMakeLists.txt ------------------
>
>
> ---------------Create-cpackoptions.cmake--------------
>
> configure_file(${SOURCE_DIR}/cmake/CPackOptions.cmake.in
> ${SOURCE_DIR}/cmake/CPackOptions.cmake
> @ONLY)
>
> ---------------Create-cpackoptions.cmake--------------
>
>
> --------------------------CPackOptions.cmake.in-----------------------
>
> SET(CMAKE_INSTALL_RPATH "/opt/@proj_name@")
> set(CPACK_PACKAGE_VERSION "@pack_version@")
> set(CPACK_PACKAGE_FILE_NAME
> "@proj_name at -${CPACK_PACKAGE_VERSION}r at revision@-${CPACK_SYSTEM_NAME}")
>
> --------------------------CPackOptions.cmake.in-----------------------
>
> 02.11.2012 11:06, Eric Noulard пишет:
>> 2012/11/1 Vyacheslav Karamov <UbuntuList at yandex.ru>:
>>> Hi All!
>>>
>>> Is it possible to change rpath at the packaging stage?
>> CPack is using cmake_install.cmake scripts which gets influenced
>> by CMAKE_INSTALL_RPATH variable and/or INSTALL_RPATH target property.
>>
>> Did you try to play with that? i.e.
>>
>> SET(CMAKE_INSTALL_RPATH "/opt/chatterbox")
>>
>> you may try to set this in a CPACK_PROJECT_CONFIG_FILE
>> in order to set it to a "CPack-time" specific value.
>>
>> That said I'm not sure it'll work because I don't know for sure "when
>> exactly"
>> CMAKE_INSTALL_RPATH is processed, but iit's simple to try.
>>
>>
>>> I have CMake based project with CPack directives in its CMake script:
>>>
>>> if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND EXISTS
>>> "${CMAKE_ROOT}/Modules/CPack.cmake")
>>>
>>> SET(install_dir "/opt/chatterbox")
>>>
>>> SET(CMAKE_SKIP_BUILD_RPATH TRUE)
>>>
>>> SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
>>>
>>> SET(CMAKE_INSTALL_RPATH "/usr/local/lib")
>>>
>>> SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
>>>
>>> ...
>>> endif()
>>> --
>>>
>>> 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
>>
>>
>
> --
>
> 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
More information about the CMake
mailing list