CMake ExternalProject_Add() and FindPackage()

前端 未结 3 1528
别那么骄傲
别那么骄傲 2020-11-29 23:03

Is there are proper way to find a library (via FindPackage()) which was built with ExternalProject_Add()?

The problem is that CMake cannot

3条回答
  •  情话喂你
    2020-11-30 00:00

    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()
    

    this seems to work well for mingw makefiles / eclipse makefile projects. vs will request to reload all projects after first build.

提交回复
热议问题