[CMake] Configuration dependent Install and Export

Fabian Saccilotto f.saccilotto at gmx.ch
Fri Jul 26 04:49:21 EDT 2013


I made a feature request (http://www.cmake.org/Bug/view.php?id=14317) 
for that problem with a proposal of a code change.

If you are interested in an immediate solution, apply the patch to the 
sources of version 2.8.11.2 and the BUILD_TYPE will be set in the 
*-targets-<configuration>.cmake files which allows you to use that 
variable in install destinations.

Kind regards
Fabian Saccilotto

Am 25.07.2013 16:53, schrieb Gregoire Aujay:
> Hello,
>
> I have the same need as you but unfortunately never managed to find a solution.
>
> I had to disable the export when using visual IDE and I only make installs with nmake, jom or ninja (not multi-configuration) which is a temporary solution until this is supported by cmake.
>
>
> foreach(_build_iter ${_all_current_build_types})
> 	if (_is_multi_conf_generator) # due to a limitation of cmake
> 		install(TARGETS "${p_target}"
> 			...
> 			CONFIGURATIONS "${_build_iter}"
> 		)
> 	else()  # the correct export
> 		install(TARGETS "${p_target}" EXPORT "${_component_name}-targets"
> 			...
> 			CONFIGURATIONS "${_build_iter}"
> 		)
> 	endif()
> endforeach()
>
>
> Regards,
> Gregoire
>
> -----Original Message-----
> From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf Of Fabian Saccilotto
> Sent: jeudi 25 juillet 2013 16:38
> To: cmake at cmake.org
> Subject: [CMake] Configuration dependent Install and Export
>
> Dear CMake-Users,
>
> as we normally use Visual Studio, we would like to provide pre-built configuration dependent 3rd-party libraries for our developers.
> Developing with sources on the same machine works, but when I try to build machine-independent builds library paths are not correct. Details and code snippet found below.
>
> Example of a prebuilt library folder (sba stands for Sparse Bundle
> Adjustment) which could be used via find_package(sba):
> sba/
>     <version-number>/
>       include
>       <Configurationname> (Debug, Release, MinSizeRel, RelWithDebInfo)
>         /lib
>           sba.lib
>         /bin
>       sba-config.cmake
>       sba-config-version.cmake
>       sba-targets.cmake
>       sba-targets-<Configurationname>.cmake
>
> I successfully builded a project depending on that library when the library was built on the same machine and exporting the targets via the "export(TARGETS" CMake-Command.
>
> What I wanted to do now is installing the library to a specific folder and use that one as machine-independent reference in projects that depend on that library. To distinct the configuration for which the *.lib was built, I prepend the install destination with the ${BUILD_TYPE}.
>
> When executing the install from within Visual Studio, the libraries and files are copied to the correct directory and the *.cmake files are generated per configuration.
>
> The problem occurs when I want to reference that library from another project. Because of the fact that the *-targets-<configuration>.cmake files are generated during execution of CMake for the sba library, they contain paths with ${BUILD_TYPE}.
> ("${_IMPORT_PREFIX}/${BUILD_TYPE}/lib/sba.lib"). During the
> find_package(sba) stage of the parent project this variable will be empty and therefore an error occurs that the file can't be found.
>
> My questions are:
> - Has anyone done this before, maybe in another way?
> - Is there a way to tell the exported target files the current configuration name?
>
> Steps done:
> - Found similar but unanswered question:
> http://public.kitware.com/pipermail/cmake/2013-January/053144.html
> - I tried install(CODE "install(EXPORT...") to export the file at install time (when the configuration is known) which results in an error that install is not scriptable.
> - I tried using ${CMAKE_INSTALL_CONFIG_NAME} instead of BUILD_TYPE - copying files was not successful as the variable is not set when installing from visual studio.
>
> Thank you for your help,
>
> Kind regards
> Fabian Saccilotto
>
>
> Install Snippet from CMakeLists.txt:
> # Export for later reuse
> set(PACKAGE_NAME sba)
> set(VERSION 1.6)
>
> # Make a directory for each config
> install(TARGETS sba
>     EXPORT ${PACKAGE_NAME}-targets
>       RUNTIME DESTINATION ${VERSION}/bin/\${BUILD_TYPE} COMPONENT Runtime
>       LIBRARY DESTINATION ${VERSION}/lib/\${BUILD_TYPE} COMPONENT Runtime
>       ARCHIVE DESTINATION ${VERSION}/lib/\${BUILD_TYPE} COMPONENT Development}
>       )
>
> configure_file(
>       ${${PROJECT_NAME}_SOURCE_DIR}/${PACKAGE_NAME}-config.cmake.in
>       ${${PROJECT_NAME}_BINARY_DIR}/${PACKAGE_NAME}-config.cmake
>     @ONLY
>       )
>
> configure_file(
> ${${PROJECT_NAME}_SOURCE_DIR}/${PACKAGE_NAME}-config-version.cmake.in
> ${${PROJECT_NAME}_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake
>     @ONLY
>       )
>
> install(FILES
>     ${${PROJECT_NAME}_BINARY_DIR}/${PACKAGE_NAME}-config.cmake
>     ${${PROJECT_NAME}_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake
>     DESTINATION ${VERSION}
>     )
>
> install(EXPORT ${PACKAGE_NAME}-targets DESTINATION ${VERSION})
>
> # Export targets for local use
> export(TARGETS sba FILE ${PACKAGE_NAME}-targets.cmake)
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
>



More information about the CMake mailing list