add_executable(fpt-fp-demo fp_demo.cpp)
set_target_properties(fpt-fp-demo PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
target_compile_options(fpt-fp-demo PRIVATE
  -Wall -Wextra -Wpedantic -Werror -fno-fast-math -frounding-math -ffp-contract=off)

# Escape arbitrary compiler paths before serializing build provenance.
function(json_escape output value)
  string(REPLACE "\\" "\\\\" escaped "${value}")
  string(REPLACE "\"" "\\\"" escaped "${escaped}")
  string(REPLACE "\n" "\\n" escaped "${escaped}")
  string(REPLACE "\r" "\\r" escaped "${escaped}")
  string(REPLACE "\t" "\\t" escaped "${escaped}")
  set(${output} "${escaped}" PARENT_SCOPE)
endfunction()
json_escape(FPT_COMPILER_PATH "${CMAKE_CXX_COMPILER}")
# configure_file makes source changes trigger reconfiguration and a fresh hash.
configure_file(fp_demo.cpp "${CMAKE_BINARY_DIR}/fp_demo.source.cpp" COPYONLY)
file(SHA256 "${CMAKE_BINARY_DIR}/fp_demo.source.cpp" FPT_SOURCE_SHA256)
file(WRITE "${CMAKE_BINARY_DIR}/build_info.json"
  "{\"compiler_id\":\"${CMAKE_CXX_COMPILER_ID}\",\"compiler_version\":\"${CMAKE_CXX_COMPILER_VERSION}\",\"compiler_path\":\"${FPT_COMPILER_PATH}\",\"cmake_version\":\"${CMAKE_VERSION}\",\"cxx_standard\":20,\"source_sha256\":\"${FPT_SOURCE_SHA256}\"}\n")
