From 8b7a2e86b804a0e54c0a2db92892df30eff9b542 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Thu, 18 Mar 2021 16:07:40 -0400 Subject: [PATCH] Avoid recompiling option_parser every time cmake runs. Switch to `configure_file`, which won't touch the output file unless the contents change. --- cmake/FileToString.cmake | 6 ++++-- cmake/FileToString.in | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 cmake/FileToString.in diff --git a/cmake/FileToString.cmake b/cmake/FileToString.cmake index fd65d6d..3935908 100644 --- a/cmake/FileToString.cmake +++ b/cmake/FileToString.cmake @@ -3,11 +3,13 @@ # Create a C++ file `file_out` that defines a string named `string_name` in # `namespace`, which contains the contents of `file_in`. +# Cache this so we can access it from wherever file_to_string is called. +set(_nvbench_file_to_string_path "${CMAKE_CURRENT_LIST_DIR}/FileToString.in") function(file_to_string file_in file_out namespace string_name) file(READ "${file_in}" file_in_contents) set(file_out_contents) - string(APPEND file_out_contents + string(APPEND file_to_string_payload "#include \n" "namespace ${namespace} {\n" "const std::string ${string_name} =\n" @@ -15,5 +17,5 @@ function(file_to_string file_in file_out namespace string_name) "}\n" ) - file(WRITE "${file_out}" "${file_out_contents}") + configure_file("${_nvbench_file_to_string_path}" "${file_out}") endfunction() diff --git a/cmake/FileToString.in b/cmake/FileToString.in new file mode 100644 index 0000000..aeff339 --- /dev/null +++ b/cmake/FileToString.in @@ -0,0 +1 @@ +${file_to_string_payload}