CMake的ExternalProject_Add()和FindPackage() [英] CMake ExternalProject_Add() and FindPackage()
问题描述
时有找到一个库(通过 FindPackage()
),用内置ExternalProject_Add()
?
Is there are proper way to find a library (via FindPackage()
) which was built with ExternalProject_Add()
?
问题是,CMake的不能找到CMake的时间库,因为外部库得到建立在编译时。我知道这是可能的构建库,并在superbuild项目时要结合这两种的CMake功能,但我想在一个正常的CMake项目中使用它。
The problem is that CMake cannot find the library at CMake-time because the external library gets build at compile time. I know that it is possible to combine these two CMake function when building the library and the project in a superbuild but I want to use it in a normal CMake project.
其实我想建立VTK 6 ExternalProject_Add
和 FindPackage
发现这一切我CMake的项目中
In fact I would like to build VTK 6 with ExternalProject_Add
and find it with FindPackage
all inside my CMake project.
推荐答案
有一种方法可以做到这一点。但汇入作业种的hackish。
你基本上添加自定义目标,即构建过程中重新运行cmake的。
there is a way to do this. but it´s kind of hackish. you basically add a custom target, that reruns cmake during build.
您将不得不尝试这种在一个小的测试项目,以决定它是否适合你。
you will have to try this in a small test project, to decide if it works for you
find_package(Beaengine)
############################################
#
# BeaEngine
#
include(ExternalProject)
externalproject_add(BeaEngine
SOURCE_DIR ${PROJECT_SOURCE_DIR}/beaengine
SVN_REPOSITORY http://beaengine.googlecode.com/svn/trunk/
CMAKE_ARGS -DoptHAS_OPTIMIZED=TRUE -DoptHAS_SYMBOLS=FALSE -DoptBUILD_64BIT=FALSE -DoptBUILD_DLL=FALSE -DoptBUILD_LITE=FALSE
INSTALL_COMMAND ""
)
if(NOT ${Beaengine_FOUND})
#rerun cmake in initial build
#will update cmakecache/project files on first build
#so you may have to reload project after first build
add_custom_target(Rescan ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR} DEPENDS BeaEngine)
else()
#Rescan becomes a dummy target after first build
#this prevents cmake from rebuilding cache/projects on subsequent builds
add_custom_target(Rescan)
endif()
add_executable(testapp testapp.cpp )
add_dependencies(testapp Rescan)
if(${Beaengine_FOUND})
target_link_libraries(testapp ${Beaengine_LIBRARY})
endif()
这似乎也为MinGW的makefile文件工作/月食生成文件的项目。
VS将要求首先生成后重新加载的所有项目。
this seems to work well for mingw makefiles / eclipse makefile projects. vs will request to reload all projects after first build.
这篇关于CMake的ExternalProject_Add()和FindPackage()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!