我用CMake创建了一个版本化的MacOS框架,偶然发现了在何处安装软件包配置文件sample-config.cmake
,sample-config-version.cmake
,sample-exports.cmake
,sample-exports-release.cmake
的问题。
该框架已版本化,因此其结构大致如下:
<sample.framework>
|-- Headers # link to Versions/Current/Headers
|-- Resources # link to Versions/Current/Resources
+-- Versions
|-- Current # link to B
+-- B
|-- Headers
+-- Resources
|-- CMake
+-- Info.plist
我使用CMakes CMakePackageConfigHelpers
宏从包含内容的模板sample-config.cmake.in
生成程序包配置文件
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/sample-export.cmake")
CMake没有提到版本控制框架,建议将文件安装到目录Resources/CMake
中。
我是通过致电
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sample-config.cmake"
DESTINATION sample.framework/Resources/CMake
COMPONENT development
)
生成的文件如下:
####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was sample-config.cmake.in ########
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
macro(set_and_check _var _file)
set(${_var} "${_file}")
if(NOT EXISTS "${_file}")
message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
endif()
endmacro()
macro(check_required_components _NAME)
foreach(comp ${${_NAME}_FIND_COMPONENTS})
if(NOT ${_NAME}_${comp}_FOUND)
if(${_NAME}_FIND_REQUIRED_${comp})
set(${_NAME}_FOUND FALSE)
endif()
endif()
endforeach()
endmacro()
include("${CMAKE_CURRENT_LIST_DIR}/sample-export.cmake")
错误:
尽管我将这些文件安装到Resources/CMake
还是安装到Versions/B/Resources/CMake
,但它们都指向同一目录,所以生成的配置文件有所不同。
通过Resources
链接到Resources/CMake
进行安装时,设置为PACKAGE_PREFIX_DIR
的调用生成为
`get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)`
但是通过Versions/B/Resources/CMake
安装时,它生成为
`get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../../" ABSOLUTE)`
因此,安装到find_package(sample CONFIG)
时Versions/B/Resources/CMake
无法找到该软件包。
以前有人遇到过此错误吗?
感谢您对此的任何投入。