CMake ExternalProject_Add () and FindPackage ()

Is there a way to find the library (via FindPackage() ) that was built using ExternalProject_Add() ?

The problem is that CMake cannot find the library in CMake-time, because the external library receives the assembly at compile time. I know that you can combine these two CMake functions when building a library and a project in superbyte, but I want to use it in a regular CMake project.

Actually, I would like to build VTK 6 with ExternalProject_Add and find it with FindPackage everyone inside my CMake project.

+17
c ++ build cmake vtk
Jul 03 '13 at 11:40
source share
2 answers

there is a way to do this. but these are hacks. you basically add a custom target that re-launches 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() 

this seems to work well for makefile mingw makefile / eclipse projects. vs will ask you to restart all projects after the first build.

+17
Jul 04 '13 at 15:04 on
source share

You can force build an assembly using the build_external_project function.

It works by creating a simple helper project inside the assembly tree, and then invoking the cmake configuration and cmake assembly on the helper.

Customize the actual ExternalProject_add command as desired.

Note that the returned arguments are used to pass CMAKE_ARGS. Furthur enhancements are left as an exercise for the reader :-)

 # This function is used to force a build on a dependant project at cmake configuration phase. # function (build_external_project target prefix url) #FOLLOWING ARGUMENTS are the CMAKE_ARGS of ExternalProject_Add set(trigger_build_dir ${CMAKE_BINARY_DIR}/force_${target}) #mktemp dir in build tree file(MAKE_DIRECTORY ${trigger_build_dir} ${trigger_build_dir}/build) #generate false dependency project set(CMAKE_LIST_CONTENT " cmake_minimum_required(VERSION 2.8) include(ExternalProject) ExternalProject_add(${target} PREFIX ${prefix}/${target} URL ${url} CMAKE_ARGS ${ARGN} INSTALL_COMMAND \"\" ) add_custom_target(trigger_${target}) add_dependencies(trigger_${target} ${target}) ") file(WRITE ${trigger_build_dir}/CMakeLists.txt "${CMAKE_LIST_CONTENT}") execute_process(COMMAND ${CMAKE_COMMAND} .. WORKING_DIRECTORY ${trigger_build_dir}/build ) execute_process(COMMAND ${CMAKE_COMMAND} --build . WORKING_DIRECTORY ${trigger_build_dir}/build ) endfunction() 
+9
May 9 '14 at 17:31
source share



All Articles