From 096a252fb5cd49a5c5f798f4cdb82bf3abf972d4 Mon Sep 17 00:00:00 2001 From: sauravUppoor Date: Sun, 10 Mar 2024 00:58:31 +0530 Subject: [PATCH] [cmake] Generate CMakeArgs.txt file to store CMake src, build dir and invocation arguments --- CMakeLists.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb3aa603f..8e8e1900e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,20 @@ set(CMAKE_CXX_EXTENSIONS NO) include(GNUInstallDirs) +# MUST be done before call to clad project +get_cmake_property(_cache_vars CACHE_VARIABLES) +foreach(_cache_var ${_cache_vars}) + get_property(_helpstring CACHE ${_cache_var} PROPERTY HELPSTRING) + if(_helpstring STREQUAL + "No help, variable specified on the command line.") + set(CMAKE_ARGS "${CMAKE_ARGS} -D${_cache_var}=\"${${_cache_var}}\"") + endif() +endforeach() + +# Generate CMakeArgs.txt file with source, build dir and command line args +write_file("${CMAKE_CURRENT_BINARY_DIR}/CMakeArgs.txt" + "-S${CMAKE_SOURCE_DIR} -B${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_ARGS}") + if(POLICY CMP0075) cmake_policy(SET CMP0075 NEW) endif()