我的CMakeLists.txt中有以下代码: ExternalProject_Add( LibSndFile URL "http://www.mega-nerd.com/libsndfile/files/libsndfile-1.0.25.tar.gz" CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/LibSndFile/configure --prefix=INSTALL_DIR B
ExternalProject_Add( LibSndFile URL "http://www.mega-nerd.com/libsndfile/files/libsndfile-1.0.25.tar.gz" CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/LibSndFile/configure --prefix=<INSTALL_DIR> BUILD_COMMAND ${MAKE} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/LibSndFile UPDATE_COMMAND "" INSTALL_COMMAND "" LOG_DOWNLOAD ON LOG_CONFIGURE ON LOG_BUILD ON )
一切都配置和构建得很好,直到项目准备好链接.因为LibSndFile依赖于flac,libogg和libvorbis,它需要链接到那些,但它看不到它们.
我怎样才能使我的外部项目可以链接到我系统上安装的那些依赖项(是否有一些我没有看到的LINK_LIBRARY选项)?如果它们没有安装在我的系统上,我将如何将它们链接到LibSndFile?
所以我发现最安全的方法是使用另一个ExternalProject_Add作为LibSndFile的依赖项:find_package(FLAC) # test if FLAC is installed on the system if(${FLAC_FOUND}) # do something if it is found, maybe tell the user else(${FLAC_FOUND}) # FLAC isn't installed on the system and needs to be downloaded ExternalProject_Add( FLAC URL "http://downloads.xiph.org/releases/flac/flac-1.3.0.tar.xz" CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/flac/configure --prefix=<INSTALL_DIR> BUILD_COMMAND ${MAKE} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/flac UPDATE_COMMAND "" INSTALL_COMMAND "" LOG_DOWNLOAD ON LOG_CONFIGURE ON LOG_BUILD ON ) endif(${FLAC_FOUND})
然后使用LibSndFile中的DEPENDS指令将其指向项目所依赖的目标.
ExternalProject_Add( LibSndFile DEPENDS FLAC libogg libvorbis URL "http://www.mega-nerd.com/libsndfile/files/libsndfile-1.0.25.tar.gz" CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/LibSndFile/configure --prefix=<INSTALL_DIR> BUILD_COMMAND ${MAKE} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/LibSndFile UPDATE_COMMAND "" INSTALL_COMMAND "" LOG_DOWNLOAD ON LOG_CONFIGURE ON LOG_BUILD ON )