[cmake-developers] [CMake 0014317]: Configuration dependent install EXPORT
Mantis Bug Tracker
mantis at public.kitware.com
Fri Jul 26 04:43:30 EDT 2013
The following issue has been SUBMITTED.
======================================================================
http://www.cmake.org/Bug/view.php?id=14317
======================================================================
Reported By: Fabian Saccilotto
Assigned To:
======================================================================
Project: CMake
Issue ID: 14317
Category: CMake
Reproducibility: always
Severity: feature
Priority: normal
Status: new
======================================================================
Date Submitted: 2013-07-26 04:43 EDT
Last Modified: 2013-07-26 04:43 EDT
======================================================================
Summary: Configuration dependent install EXPORT
Description:
Commands
INSTALL(TARGETS ... EXPORT
INSTALL(EXPORT
Installing exported libraries to configuration dependent folder doesn't work at
the moment.
Because of the fact that *-targets-<configuration>.cmake files are generated
during execution of CMake for the library to export, they contain paths with
${BUILD_TYPE}. During the find_package() stage of the parent project this
variable will be empty and therefore an error occurs that the file can't be
found.
Extract from *-targets-debug.cmake
set_target_properties(sba PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG "blas;lapack;f2c"
IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/1.6/lib/${BUILD_TYPE}/sba.lib"
)
Steps to Reproduce:
Install a library to a configuration dependent folder and install the export.
See the following CMakeLists.txt snippet.
# Snippet from CMakeLists.txt -----------------------------------
add_library(<libname> <sources>)
# Export for later reuse
set(PACKAGE_NAME <packagename>)
set(VERSION <version>)
# Make a directory for each config
install(TARGETS <libname>
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.cmake
DESTINATION ${VERSION}
)
install(EXPORT ${PACKAGE_NAME}-targets DESTINATION ${VERSION})
# *-config.cmake.in ---------------------------------------
# Import the targets
get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(${SELF_DIR}/@PACKAGE_NAME at -targets.cmake)
Additional Information:
My proposal to add this feature:
The ${BUILD_TYPE} Variable could be set in the *-targets-<configuration>.cmake
file during creation of the files as the configuration is known.
I implemented the code on the source of 2.8.11.2 tag of the git repository and
made a patch.
In cmExportFileGenerator::GenerateImportHeaderCode the BUILD_TYPE variable is
set if a configuration is available. This allows users to use that variable in
install paths.
//----------------------------------------------------------------------------
void cmExportFileGenerator::GenerateImportHeaderCode(std::ostream& os,
const char* config)
{
os << "#----------------------------------------------------------------\n"
<< "# Generated CMake target import file";
if(config)
{
os << " for configuration \"" << config << "\".\n";
}
else
{
os << ".\n";
}
os << "#----------------------------------------------------------------\n"
<< "\n";
this->GenerateImportConfigurationCode(os, config);
this->GenerateImportVersionCode(os);
}
//----------------------------------------------------------------------------
void cmExportFileGenerator::GenerateImportConfigurationCode(std::ostream& os,
const char* config)
{
// Store the used configuration, this will allow configuration dependent
// paths in multi-configuration environments
if(config)
{
os << "# Set configuration for use in paths.\n"
<< "set(BUILD_TYPE " << config << ")\n"
<< "\n";
}
}
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2013-07-26 04:43 Fabian SaccilottoNew Issue
2013-07-26 04:43 Fabian SaccilottoFile Added: config_dependent_install.patch
======================================================================
More information about the cmake-developers
mailing list