trivial: cmake style update for helpers.cmake

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
This commit is contained in:
Gerwin Klein 2026-06-12 12:16:42 +10:00
parent c377a3233a
commit 868454e1d6

View file

@ -17,11 +17,8 @@ endif()
# Is equivalent to find_file except that it adds CMAKE_CURRENT_SOURCE_DIR as a path and sets
# CMAKE_FIND_ROOT_PATH_BOTH
function(RequireFile config_name file_name)
find_file(
${config_name} "${file_name}"
PATHS "${CMAKE_CURRENT_SOURCE_DIR}"
CMAKE_FIND_ROOT_PATH_BOTH ${ARGV}
)
find_file(${config_name} "${file_name}" PATHS "${CMAKE_CURRENT_SOURCE_DIR}"
CMAKE_FIND_ROOT_PATH_BOTH ${ARGV})
if("${${config_name}}" STREQUAL "${config_name}-NOTFOUND")
message(FATAL_ERROR "Failed to find required file ${file_name}")
endif()
@ -38,10 +35,7 @@ function(get_absolute_source_or_binary output input)
if(NOT EXISTS "${test}")
get_filename_component(test "${input}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
endif()
set("${output}"
"${test}"
PARENT_SCOPE
)
set("${output}" "${test}" PARENT_SCOPE)
endfunction(get_absolute_source_or_binary)
function(get_absolute_list_source_or_binary output input)
@ -49,10 +43,7 @@ function(get_absolute_list_source_or_binary output input)
if(NOT EXISTS "${test}")
get_absolute_source_or_binary(test ${input})
endif()
set("${output}"
"${test}"
PARENT_SCOPE
)
set("${output}" "${test}" PARENT_SCOPE)
endfunction()
# Generates a custom command that preprocesses an input file into an output file
@ -77,11 +68,9 @@ function(cppfile output output_target input)
set(file_copy_name ${CPP_EXACT_NAME})
endif()
add_custom_command(
OUTPUT ${file_copy_name}
COMMAND ${CMAKE_COMMAND} -E copy ${input} ${CMAKE_CURRENT_BINARY_DIR}/${file_copy_name}
COMMENT "Creating C input file for preprocessor"
DEPENDS ${CPP_EXTRA_DEPS} ${input}
)
OUTPUT ${file_copy_name} COMMAND ${CMAKE_COMMAND} -E copy ${input}
${CMAKE_CURRENT_BINARY_DIR}/${file_copy_name}
COMMENT "Creating C input file for preprocessor" DEPENDS ${CPP_EXTRA_DEPS} ${input})
add_custom_target(${output_target}_copy_in DEPENDS ${file_copy_name})
# Now generate an object library to persuade cmake to just do compilation and not try
# and link our 'object' files
@ -93,10 +82,9 @@ function(cppfile output output_target input)
target_compile_options(${output_target}_temp_lib PRIVATE ${CPP_EXTRA_FLAGS})
# Now copy from the random name cmake gave our object file into the one desired by the user
add_custom_command(
OUTPUT ${output}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:${output_target}_temp_lib> ${output}
DEPENDS ${output_target}_temp_lib $<TARGET_OBJECTS:${output_target}_temp_lib>
)
OUTPUT ${output} COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_OBJECTS:${output_target}_temp_lib>
${output} DEPENDS ${output_target}_temp_lib
$<TARGET_OBJECTS:${output_target}_temp_lib>)
add_custom_target(${output_target} DEPENDS ${output})
endfunction(cppfile)
@ -111,18 +99,15 @@ endfunction(cppfile)
# the bitfield generator
function(GenBFCommand args target_name pbf_path pbf_target deps)
# Since we're going to change the working directory first convert any paths to absolute
get_filename_component(
target_name_absolute "${target_name}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}"
)
get_filename_component(target_name_absolute "${target_name}" ABSOLUTE BASE_DIR
"${CMAKE_CURRENT_BINARY_DIR}")
get_absolute_source_or_binary(pbf_path_absolute "${pbf_path}")
add_custom_command(
OUTPUT "${target_name_absolute}"
COMMAND "${PYTHON3}" "${BF_GEN_PATH}" "${args}" "${pbf_path_absolute}"
"${target_name_absolute}"
COMMAND "${PYTHON3}" "${BF_GEN_PATH}" "${args}" "${pbf_path_absolute}" "${target_name_absolute}"
DEPENDS "${BF_GEN_PATH}" "${pbf_path_absolute}" "${pbf_target}" ${deps}
COMMENT "Generating from ${pbf_path}"
COMMAND_EXPAND_LISTS VERBATIM
)
COMMAND_EXPAND_LISTS VERBATIM)
endfunction(GenBFCommand)
# Wrapper function for generating both a target and command to process a bitfield file
@ -133,8 +118,7 @@ function(
target_file
pbf_path
pbf_target
deps
)
deps)
GenBFCommand("${args}" "${target_file}" "${pbf_path}" "${pbf_target}" "${deps}")
add_custom_target(${target_name} DEPENDS "${target_file}")
endfunction(GenBFTarget)
@ -152,8 +136,7 @@ function(
pbf_target
prunes
deps
orig_file
)
orig_file)
set(args "")
if(NOT "${environment}" STREQUAL "")
list(APPEND args --environment "${environment}")
@ -176,8 +159,7 @@ function(
pbf_path
pbf_target
prunes
deps
)
deps)
get_filename_component(cspec_dir "${CSPEC_DIR}" ABSOLUTE BASE_DIR)
list(APPEND args --cspec-dir "${cspec_dir}")
if(SKIP_MODIFIES)
@ -197,8 +179,7 @@ function(
pbf_path
pbf_target
prunes
deps
)
deps)
set(args "")
list(APPEND args --hol_defs)
GenThyBFTarget(
@ -208,8 +189,7 @@ function(
"${pbf_path}"
"${pbf_target}"
"${prunes}"
"${deps}"
)
"${deps}")
endfunction(GenDefsBFTarget)
# Generate proofs from a bitfield specification
@ -220,8 +200,7 @@ function(
pbf_path
pbf_target
prunes
deps
)
deps)
set(args "")
# Get an absolute path to cspec_dir so that the final theory file is portable
list(APPEND args --hol_proofs --umm_types "${UMM_TYPES}")
@ -229,8 +208,7 @@ function(
list(APPEND args "--sorry_lemmas")
endif()
list(APPEND args
"--toplevel;$<JOIN:$<TARGET_PROPERTY:kernel_config_target,TOPLEVELTYPES>,;--toplevel;>"
)
"--toplevel;$<JOIN:$<TARGET_PROPERTY:kernel_config_target,TOPLEVELTYPES>,;--toplevel;>")
list(APPEND deps "${UMM_TYPES}")
GenThyBFTarget(
"${args}"
@ -239,8 +217,7 @@ function(
"${pbf_path}"
"${pbf_target}"
"${prunes}"
"${deps}"
)
"${deps}")
endfunction(GenProofsBFTarget)
macro(cfg_str_add_enabled cfg_str name var)
@ -300,15 +277,9 @@ function(config_option optionname configname doc)
# Check for an existing value, and set the option to that, otherwise use the default
# Also reset the default if we switched from disabled to enabled
if((DEFINED ${optionname}) AND (NOT DEFINED ${optionname}_DISABLED))
set(${optionname}
"${${optionname}}"
CACHE BOOL "${doc}" FORCE
)
set(${optionname} "${${optionname}}" CACHE BOOL "${doc}" FORCE)
else()
set(${optionname}
"${CONFIG_DEFAULT}"
CACHE BOOL "${doc}" FORCE
)
set(${optionname} "${CONFIG_DEFAULT}" CACHE BOOL "${doc}" FORCE)
unset(${optionname}_DISABLED CACHE)
endif()
# This is a directory scope setting used to allow or prevent config options
@ -317,14 +288,8 @@ function(config_option optionname configname doc)
mark_as_advanced(${optionname})
endif()
else()
set(${optionname}
"${CONFIG_DEFAULT_DISABLED}"
CACHE INTERNAL "${doc}" FORCE
)
set(${optionname}_DISABLED
TRUE
CACHE INTERNAL "" FORCE
)
set(${optionname} "${CONFIG_DEFAULT_DISABLED}" CACHE INTERNAL "${doc}" FORCE)
set(${optionname}_DISABLED TRUE CACHE INTERNAL "" FORCE)
endif()
set(local_config_string "${configure_string}")
if(${optionname})
@ -332,20 +297,14 @@ function(config_option optionname configname doc)
else()
cfg_str_add_disabled(local_config_string ${configname})
endif()
set(configure_string
"${local_config_string}"
PARENT_SCOPE
)
set(configure_string "${local_config_string}" PARENT_SCOPE)
endfunction(config_option)
# Set a configuration option to a particular value. This value will not appear in
# the cmake-gui, but will produce an internal cmake cache variable and generated
# configuration headers.
macro(config_set optionname configname value)
set(${optionname}
"${value}"
CACHE INTERNAL "" FORCE
)
set(${optionname} "${value}" CACHE INTERNAL "" FORCE)
if("${value}" STREQUAL "OFF")
cfg_str_add_disabled(configure_string ${configname})
else()
@ -368,9 +327,8 @@ endmacro(config_set)
# the configuration dependencies are unmet
# Adds to the global configure_string variable (see add_config_library)
function(config_string optionname configname doc)
cmake_parse_arguments(
PARSE_ARGV 3 "CONFIG" "UNQUOTE;UNDEF_DISABLED" "DEPENDS;DEFAULT_DISABLED;DEFAULT" ""
)
cmake_parse_arguments(PARSE_ARGV 3 "CONFIG" "UNQUOTE;UNDEF_DISABLED"
"DEPENDS;DEFAULT_DISABLED;DEFAULT" "")
if(NOT "${CONFIG_UNPARSED_ARGUMENTS}" STREQUAL "")
message(FATAL_ERROR "Unknown arguments to config_option: ${CONFIG_UNPARSED_ARGUMENTS}")
endif()
@ -405,10 +363,7 @@ function(config_string optionname configname doc)
set(force "FORCE")
unset(${optionname}_UNAVAILABLE CACHE)
endif()
set(${optionname}
"${CONFIG_DEFAULT}"
CACHE STRING "${doc}" ${force}
)
set(${optionname} "${CONFIG_DEFAULT}" CACHE STRING "${doc}" ${force})
set(cfg_tag_option ${optionname})
# This is a directory scope setting used to allow or prevent config options
# from appearing in the cmake config GUI
@ -420,17 +375,11 @@ function(config_string optionname configname doc)
unset(${optionname} CACHE)
else()
# Forcively change the value to its disabled_value
set(${optionname}
"${CONFIG_DEFAULT_DISABLED}"
CACHE INTERNAL "" FORCE
)
set(${optionname} "${CONFIG_DEFAULT_DISABLED}" CACHE INTERNAL "" FORCE)
set(cfg_tag_option ${optionname})
endif()
# Sset _UNAVAILABLE so we can detect when the option because enabled again
set(${optionname}_UNAVAILABLE
ON
CACHE INTERNAL "" FORCE
)
set(${optionname}_UNAVAILABLE ON CACHE INTERNAL "" FORCE)
endif()
if(cfg_tag_option)
if(CONFIG_UNQUOTE)
@ -440,10 +389,7 @@ function(config_string optionname configname doc)
endif()
cfg_str_add_string(local_config_string ${configname} "${quote}@${cfg_tag_option}@${quote}")
endif()
set(configure_string
"${local_config_string}"
PARENT_SCOPE
)
set(configure_string "${local_config_string}" PARENT_SCOPE)
endfunction(config_string)
# Defines a multi choice / select configuration option
@ -519,17 +465,11 @@ function(config_choice optionname configname doc)
endif()
# Check if this option is the one that is currently set
if("${${optionname}}" STREQUAL "${option_value}")
set(${option_cache}
ON
CACHE INTERNAL "" FORCE
)
set(${option_cache} ON CACHE INTERNAL "" FORCE)
cfg_str_add_enabled(local_config_string ${option_config} ${option_cache})
set(found_current ON)
else()
set(${option_cache}
OFF
CACHE INTERNAL "" FORCE
)
set(${option_cache} OFF CACHE INTERNAL "" FORCE)
cfg_str_add_disabled(local_config_string ${option_config})
endif()
else()
@ -547,14 +487,8 @@ function(config_choice optionname configname doc)
unset(${optionname} CACHE)
else()
cfg_str_add_string(local_config_string ${configname} "@${optionname}@")
set(configure_string
"${local_config_string}"
PARENT_SCOPE
)
set(${optionname}
"${default}"
CACHE STRING "${doc}" ${force_default}
)
set(configure_string "${local_config_string}" PARENT_SCOPE)
set(${optionname} "${default}" CACHE STRING "${doc}" ${force_default})
# This is a directory scope setting used to allow or prevent config options
# from appearing in the cmake config GUI
if(SEL4_CONFIG_DEFAULT_ADVANCED)
@ -565,23 +499,14 @@ function(config_choice optionname configname doc)
# The option is actually enabled, but we didn't enable the correct
# choice earlier, since we didn't know we were going to revert to
# the default. So add the option setting here
set(${first_cache}
ON
CACHE INTERNAL "" FORCE
)
set(${first_cache} ON CACHE INTERNAL "" FORCE)
cfg_str_add_enabled(local_config_string ${first_config} ${first_cache})
endif()
endif()
# Save all possible options to an internal value. This is to allow enumerating the options elsewhere.
# We create a new variable because cmake doesn't support arbitrary properties on cache variables.
set(${optionname}_all_strings
${all_strings}
CACHE INTERNAL "" FORCE
)
set(configure_string
"${local_config_string}"
PARENT_SCOPE
)
set(${optionname}_all_strings ${all_strings} CACHE INTERNAL "" FORCE)
set(configure_string "${local_config_string}" PARENT_SCOPE)
endfunction(config_choice)
# Defines a target for a 'configuration' library, which generates a header based
@ -610,8 +535,7 @@ function(add_config_library prefix configure_template)
execute_process(
COMMAND "${PYTHON3}" "${CONFIG_GEN_PATH}" "${config_yaml_file}" --skip-unchanged --write-c
"${config_header_file}" --write-json "${config_json_file}" RESULT_VARIABLE error
)
"${config_header_file}" --write-json "${config_json_file}" RESULT_VARIABLE error)
if(error)
message(FATAL_ERROR "Failed to generate header: ${config_yaml_file}")
endif()
@ -624,19 +548,11 @@ function(add_config_library prefix configure_template)
# Set a property on the library that is a list of the files we generated. This
# allows custom build commands to easily get a file dependency list so they can
# 'depend' upon this target easily
set_property(
TARGET ${prefix}_Gen
APPEND
PROPERTY GENERATED_FILES ${config_header_file}
)
set_property(TARGET ${prefix}_Gen APPEND PROPERTY GENERATED_FILES ${config_header_file})
endfunction(add_config_library)
macro(get_generated_files output target)
get_property(
${output}
TARGET ${target}
PROPERTY GENERATED_FILES
)
get_property(${output} TARGET ${target} PROPERTY GENERATED_FILES)
endmacro(get_generated_files)
# This rule tries to emulate an 'autoconf' header. autoconf generated headers
@ -658,11 +574,7 @@ function(generate_autoconf targetname config_list)
set(config_dir "${CMAKE_CURRENT_BINARY_DIR}/autoconf")
set(config_file "${config_dir}/autoconf.h")
file(
GENERATE
OUTPUT "${config_file}"
CONTENT "${config_header_contents}"
)
file(GENERATE OUTPUT "${config_file}" CONTENT "${config_header_contents}")
add_custom_target(${targetname}_Gen DEPENDS "${config_file}" ${gen_list})
add_library(${targetname} INTERFACE)
target_link_libraries(${targetname} INTERFACE ${link_list})
@ -670,11 +582,8 @@ function(generate_autoconf targetname config_list)
add_dependencies(${targetname} ${targetname}_Gen ${config_file} ${gen_list})
# Set our GENERATED_FILES property to include the GENERATED_FILES of all of our input
# configurations, as well as the files we generated
set_property(
TARGET ${targetname}_Gen
APPEND
PROPERTY GENERATED_FILES "${config_file}" ${gen_list}
)
set_property(TARGET ${targetname}_Gen APPEND PROPERTY GENERATED_FILES "${config_file}"
${gen_list})
endfunction(generate_autoconf)
# Macro that allows for appending to a specified list only if all the supplied conditions are true
@ -691,10 +600,7 @@ macro(list_append_if list dep)
if(list_append_valid)
list(APPEND list_append_local_list ${ARGN})
endif()
set(${list}
${list_append_local_list}
PARENT_SCOPE
)
set(${list} ${list_append_local_list} PARENT_SCOPE)
endmacro(list_append_if)
# Checks if a file is older than its dependencies
@ -766,22 +672,11 @@ macro(cmake_script_build_kernel RELPATH)
endforeach()
execute_process(
COMMAND cmake -G Ninja ${args} -C ${CMAKE_ARGV2} ${CMAKE_CURRENT_LIST_DIR}/${RELPATH}
INPUT_FILE /dev/stdin
OUTPUT_FILE /dev/stdout
ERROR_FILE /dev/stderr
)
execute_process(
COMMAND ninja kernel.elf
INPUT_FILE /dev/stdin
OUTPUT_FILE /dev/stdout
ERROR_FILE /dev/stderr
)
execute_process(
COMMAND ninja kernel_all_pp_wrapper
INPUT_FILE /dev/stdin
OUTPUT_FILE /dev/stdout
ERROR_FILE /dev/stderr
)
INPUT_FILE /dev/stdin OUTPUT_FILE /dev/stdout ERROR_FILE /dev/stderr)
execute_process(COMMAND ninja kernel.elf INPUT_FILE /dev/stdin OUTPUT_FILE /dev/stdout
ERROR_FILE /dev/stderr)
execute_process(COMMAND ninja kernel_all_pp_wrapper INPUT_FILE /dev/stdin
OUTPUT_FILE /dev/stdout ERROR_FILE /dev/stderr)
return()
endif()
endmacro()