swh:1:snp:f521c49ab17ef7db6ec70b2430e1ed203f50383f
Raw File
Tip revision: de716c0b3eb9ad038ba6ed8f97fca410542551aa authored by Wenqing Wang on 21 October 2021, 11:10:21 UTC
[Test/HT] Added a parallel computing test
Tip revision: de716c0
ParseCMakeArgs.cmake
# Implementation from https://stackoverflow.com/questions/10205986
#
# Captures not-yet cached CMake variables. On first CMake run via cmake-cli this
# works as expected. Once the variables are cached this will not work anymore
# (and is therefore skipped).
#
# When running CMake -D.. passed args can be retrieved with by the
# CACHE_VARIABLES CMake property. On sub-sequent CMake runs it is no longer
# possible to differentiate between variables already cached by option()-calls
# and variables passed to the CMake call with -D..
#
# A (cached) map data structure would solve this. Tried the following map
# implementations without luck: - https://github.com/toeb/cmakepp (not cached) -
# https://github.com/j3lamp/mcl (did not work at all)

if(EXISTS ${PROJECT_BINARY_DIR}/CMakeCache.txt)
    return()
endif()

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()
        file(TO_CMAKE_PATH "${${cache_var}}" cache_value)
        set(CMAKE_ARGS
            "${CMAKE_ARGS} -D${cache_var}${CACHE_VAR_TYPE}=\"${cache_value}\""
        )
    endif()
endforeach()

set(CMAKE_ARGS "${CMAKE_ARGS} -DCMAKE_BUILD_TYPE=\"${CMAKE_BUILD_TYPE}\""
    CACHE STRING ""
)
string(REPLACE "\"" "\\\"" CMAKE_ARGS_ESCAPED ${CMAKE_ARGS})
set(CMAKE_ARGS_ESCAPED "${CMAKE_ARGS_ESCAPED}" CACHE STRING "")
file(WRITE ${PROJECT_BINARY_DIR}/cmake-args "${CMAKE_ARGS}\n")
back to top