I am working on a CMake project that uses ExternalProject_Add to add an
external dependency. The issue is, I need all of my command line arguments
from my project to be propagated to the external project so it will build
using the same build configuration and with the correct compiler settings.

Is there a simple way to extract all of the command line arguments into a
variable so I can simply pass them to ExternalProject_Add with the
"CMAKE_ARGS" parameter?

The only solution I have found so far is a function that parses the CMake
Cache and extracts all of the variables with a help message that says "No
help, variable specified on the command line." While this does work, it
feels like a hacky workaround at best and seems like it may break in a
future update of CMake if they decide to change the default cache help
messages.

Here is the code to make this hack work:

    get_cmake_property(CACHE_VARS CACHE_VARIABLES)

    foreach(CACHE_VAR ${CACHE_VARS})

      get_property(CACHE_VAR_HELPSTRING CACHE ${CACHE_VAR} PROPERTY HELPSTRING)

      if(CACHE_VAR_HELPSTRING STREQUAL "No help, variable specified on
the command line.")

        get_property(CACHE_VAR_TYPE CACHE ${CACHE_VAR} PROPERTY TYPE)

        if(CACHE_VAR_TYPE STREQUAL "UNINITIALIZED")

          set(CACHE_VAR_TYPE)

        else()

          set(CACHE_VAR_TYPE :${CACHE_VAR_TYPE})

        endif()

        list(APPEND CMAKE_ARGS
"-D${CACHE_VAR}${CACHE_VAR_TYPE}=${${CACHE_VAR}}")

      endif()

    endforeach()


Is there any easy way to just get a list of all of the command line
arguments without parsing the cache and filtering by help messages? This
solution just really feels wrong... there must be a better way.

Thanks,
Tim
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to