CMAKE_CACHE_ARGS.cmake 632 B

123456789101112131415161718192021
  1. include(ExternalProject)
  2. set(_tmp_dir "${CMAKE_CURRENT_BINARY_DIR}/tmp")
  3. set(_cache_file "${_tmp_dir}/FOO-cache.cmake")
  4. ExternalProject_Add(FOO TMP_DIR "${_tmp_dir}"
  5. DOWNLOAD_COMMAND ""
  6. CMAKE_CACHE_ARGS "-DFOO:STRING=BAR")
  7. if(NOT EXISTS "${_cache_file}")
  8. message(FATAL_ERROR "Initial cache not created")
  9. endif()
  10. file(READ "${_cache_file}" _cache)
  11. if(NOT "${_cache}" MATCHES "set\\(FOO \"BAR\".+\\)") # \(\)
  12. message(FATAL_ERROR "Cannot find FOO argument in cache")
  13. endif()
  14. if(NOT "${CMAKE_MATCH_0}" MATCHES FORCE)
  15. message(FATAL_ERROR "Expected forced FOO argument")
  16. endif()