How can CMake arguments be forwarded to ExternalProject

前端 未结 2 1130
轮回少年
轮回少年 2020-12-31 02:10

I have (mostly) successfully set up ExternalProject_Add for googletest. However, I noticed that things like my choice of C++ compiler, build type, etc. are not automatically

相关标签:
2条回答
  • I don't know of a robust way to achieve this, and I'm pretty sure there's no standard "CMake way", but my answer to a similar question about capturing CMake command line arguments might help you?

    0 讨论(0)
  • 2020-12-31 02:29

    After long hours of trying to figure this out, it was finally answered (by Don Hinton) in the CMake mailing list. Fraser's solution is very close, but can still pass some project specific arguments that can cause some unpredictable behavior.

    The following works properly. Hopefully this will save people some time trying to figure this out:

    cmake_minimum_required(VERSION 3.1)
    
    # MUST be done before call to 'project'
    get_cmake_property(vars CACHE_VARIABLES)
    foreach(var ${vars})
      get_property(currentHelpString CACHE "${var}" PROPERTY HELPSTRING)
        if("${currentHelpString}" MATCHES "No help, variable specified on the command line." OR "${currentHelpString}" STREQUAL "")
            # message("${var} = [${${var}}]  --  ${currentHelpString}") # uncomment to see the variables being processed
            list(APPEND CL_ARGS "-D${var}=${${var}}")
        endif()
    endforeach()
    
    project(SuperBuild)
    
    include(ExternalProject)
    
    ExternalProject_Add(ext_proj
      ...
    
      CMAKE_ARGS ${CL_ARGS}
    )
    

    Link to mailing list thread: https://cmake.org/pipermail/cmake/2018-January/067002.html

    0 讨论(0)
提交回复
热议问题