我有一个CMakeLists.txt
文件正在构建共享 lib作为en ExternalProject
,并且此lib需要安装在特定位置,以便可以将其拾取由主项目建设时。我使用以下行来执行安装过程:
install(FILES $<TARGET_FILE:of_shared> DESTINATION oF/lib)
然而,这失败了:
Install the project...
-- Install configuration: ""
CMake Error at cmake_install.cmake:31 (FILE):
file INSTALL cannot find
"/Users/me/packages/builds/x86_64/of-0.9.3-osx-release/$<TARGET_FILE:of_shared>".
make[3]: *** [install] Error 1
make[2]: *** [of_shared-prefix/src/of_shared-stamp/of_shared-install] Error 2
make[1]: *** [CMakeFiles/of_shared.dir/all] Error 2
make: *** [all] Error 2
这可能是某种兼容性错误,可能在CMake版本之间。我正在使用CMake 2.8.12。
这些是相关的CMake行:
add_library(core OBJECT ${OF_SOURCE_FILES})
add_library(of_shared SHARED $<TARGET_OBJECTS:core>)
set_target_properties(of_shared PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
set_target_properties(of_shared PROPERTIES OUTPUT_NAME openFrameworks)
target_link_libraries(of_shared ${OF_CORE_FRAMEWORKS} ${OF_ADDON_FRAMEWORKS} ${OF_CORE_LIBS} ${OF_ADDON_LIBS})
install(FILES $<TARGET_FILE:of_shared> DESTINATION oF/lib)
install(FILES libs/fmodex/lib/osx/libfmodex.dylib DESTINATION oF/lib)
install(DIRECTORY libs/glut/lib/osx/GLUT.framework DESTINATION .)
显然,$<TARGET_FILE:of_shared>
的位置失败了。除此之外,一切正常。我可以看到正在创建共享库。
答案 0 :(得分:0)
我自己找到了解决方案。而不是使用:
install(FILES $<TARGET_FILE:of_shared> DESTINATION openFrameworks/lib)
应该使用:
install(TARGETS of_shared LIBRARY DESTINATION openFrameworks/lib)
在这种情况下,of_shared
是图书馆的名称。