xo-cmake: refactor xo-reconfigure to use cmake template

This commit is contained in:
Roland Conybeare 2026-01-11 14:53:47 -05:00
commit bffe189ea1
3 changed files with 36 additions and 16 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
usage() {
echo "$0 [-u|--usage|-h|--help|--lcov-exe|--genhtml-exe|--lcov-harness-exe|--gen-ccov-template|--cmake-module-path|--subsystem-list]" 1>&2
echo "$0 [-u|--usage|-h|--help|--lcov-exe|--genhtml-exe|--lcov-harness-exe|--gen-ccov-template|--reconfigure-template|--cmake-module-path|--subsystem-list]" 1>&2
}
help() {
@ -18,8 +18,9 @@ Options:
--lcov-exe report path to 'lcov' executable
--genhtml-exe report path to 'genhtml' executable
--lcov-harness-exe report path to 'xo-cmake-lcov-harness' executable
--gen-ccov-template report path to 'gen-ccov.in' template
--doxygen-template report path to 'Doxyfile.in' template
--gen-ccov-template report path to 'gen-ccov.in' template
--reconfigure-template report path to 'xo-reconfigure.in' template
--doxygen-template report path to 'Doxyfile.in' template
--subsystem-list report path to 'subsystem-ilst'
EOF
@ -48,6 +49,9 @@ while [[ $# > 0 ]]; do
--gen-ccov-template)
cmd='gen_ccov_template'
;;
--reconfigure-template)
cmd='reconfigure_template'
;;
--doxygen-template)
cmd='doxygen_template'
;;
@ -79,6 +83,8 @@ elif [[ $cmd == 'lcov_harness_exe' ]]; then
echo -n @CMAKE_INSTALL_FULL_BINDIR@/xo-cmake-lcov-harness
elif [[ $cmd == 'gen_ccov_template' ]]; then
echo -n @CMAKE_INSTALL_FULL_DATADIR@/xo-macros/gen-ccov.in
elif [[ $cmd == 'reconfigure_template' ]]; then
echo -n @CMAKE_INSTALL_FULL_DATADIR@/xo-macros/xo-reconfigure.in
elif [[ $cmd == 'doxygen_template' ]]; then
echo -n @CMAKE_INSTALL_FULL_DATADIR@/xo-macros/Doxyfile.in
elif [[ $cmd == 'subsystem_list' ]]; then

View file

@ -272,25 +272,28 @@ macro(xo_toplevel_asm_config2)
endmacro()
function(xo_generate_reconfigure_script)
set(_reconfigure_script "${CMAKE_BINARY_DIR}/reconfigure.sh")
# In submodule build: only generate at umbrella toplevel
# In standalone build: always generate
if(XO_SUBMODULE_BUILD AND NOT (CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR))
return()
endif()
file(WRITE ${_reconfigure_script} "#!/bin/bash\n")
file(APPEND ${_reconfigure_script} "# Generated by cmake - rerun to reconfigure\n")
file(APPEND ${_reconfigure_script} "cmake \\\n")
file(APPEND ${_reconfigure_script} " -B ${CMAKE_BINARY_DIR} \\\n")
file(APPEND ${_reconfigure_script} " -S ${CMAKE_SOURCE_DIR} \\\n")
file(APPEND ${_reconfigure_script} " -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \\\n")
file(APPEND ${_reconfigure_script} " -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} \\\n")
file(APPEND ${_reconfigure_script} " -DXO_ENABLE_DOCS=${XO_ENABLE_DOCS} \\\n")
file(APPEND ${_reconfigure_script} " -DXO_ENABLE_EXAMPLES=${XO_ENABLE_EXAMPLES} \\\n")
file(APPEND ${_reconfigure_script} " -DXO_ENABLE_ASM=${XO_ENABLE_ASM} \\\n")
file(APPEND ${_reconfigure_script} " \"$@\"\n")
# Locate template
if(XO_SUBMODULE_BUILD)
set(_reconfigure_template "${XO_UMBRELLA_SOURCE_DIR}/xo-cmake/share/xo-macros/xo-reconfigure.in")
else()
execute_process(COMMAND ${XO_CMAKE_CONFIG_EXECUTABLE} --reconfigure-template
OUTPUT_VARIABLE _reconfigure_template
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if(NOT EXISTS "${_reconfigure_template}")
message(WARNING "xo_generate_reconfigure_script: template not found: ${_reconfigure_template}")
return()
endif()
set(_reconfigure_script "${CMAKE_BINARY_DIR}/xo-reconfigure")
configure_file(${_reconfigure_template} ${_reconfigure_script} @ONLY)
file(CHMOD ${_reconfigure_script} PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE

View file

@ -0,0 +1,11 @@
#!/bin/bash
# Generated by cmake - rerun to reconfigure
cmake \
-B @CMAKE_BINARY_DIR@ \
-S @CMAKE_SOURCE_DIR@ \
-DCMAKE_BUILD_TYPE=@CMAKE_BUILD_TYPE@ \
-DCMAKE_INSTALL_PREFIX=@CMAKE_INSTALL_PREFIX@ \
-DXO_ENABLE_DOCS=@XO_ENABLE_DOCS@ \
-DXO_ENABLE_EXAMPLES=@XO_ENABLE_EXAMPLES@ \
-DXO_ENABLE_ASM=@XO_ENABLE_ASM@ \
"$@"