diff --git a/README.md b/README.md index 02800e15..f2f0ba0e 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,22 @@ $ cmake -B .build -S . -DCMAKE_INSTALL_PREFIX=${PREFIX} -DXO_ENABLE_EXAMPLES=1 - ``` $ cd xo -$ .build/reconfigure.sh +$ .build/reconfigure -n +cmake -B /home/roland/proj/xo-umbrella2-claude1/.build -S /home/roland/proj/xo-umbrella2-claude1 \ + -DCMAKE_BUILD_TYPE=debug \ + -DCMAKE_INSTALL_PREFIX=/home/roland/local \ + -DCMAKE_INSTALL_DOCDIR=share/doc/xo-umbrella \ + -DCMAKE_MODULE_PATH=/home/roland/proj/xo-umbrella2/xo-cmake/cmake \ + -DCMAKE_PREFIX_PATH= \ + -DCMAKE_CXX_STANDARD=20 \ + -DXO_CMAKE_CONFIG_EXECUTABLE=/home/roland/local/bin/xo-cmake-config \ + -DENABLE_TESTING=1 \ + -DXO_ENABLE_DOCS=1 \ + -DXO_ENABLE_ASM=1 \ + -DXO_ENABLE_EXAMPLES=1 \ + -DXO_ENABLE_VULKAN=1 \ + -DXO_ENABLE_OPENGL=ON +$ .build/reconfigure # to rerun cmake ``` ### Cmake build documentation diff --git a/xo-cmake/cmake/xo_macros/xo_cxx.cmake b/xo-cmake/cmake/xo_macros/xo_cxx.cmake index 5be3ce0b..c071f061 100644 --- a/xo-cmake/cmake/xo_macros/xo_cxx.cmake +++ b/xo-cmake/cmake/xo_macros/xo_cxx.cmake @@ -292,7 +292,7 @@ function(xo_generate_reconfigure_script) return() endif() - set(_reconfigure_script "${CMAKE_BINARY_DIR}/xo-reconfigure") + set(_reconfigure_script "${CMAKE_BINARY_DIR}/reconfigure") configure_file(${_reconfigure_template} ${_reconfigure_script} @ONLY) file(CHMOD ${_reconfigure_script} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE diff --git a/xo-cmake/share/xo-macros/xo-reconfigure.in b/xo-cmake/share/xo-macros/xo-reconfigure.in index cf5c8f72..3d8118bb 100644 --- a/xo-cmake/share/xo-macros/xo-reconfigure.in +++ b/xo-cmake/share/xo-macros/xo-reconfigure.in @@ -1,11 +1,55 @@ #!/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@ \ - "$@" + +dry_run_flag=false + +# Parse arguments +while [[ $# -gt 0 ]]; do + case "$1" in + -n|--dry-run) + dry_run_flag=true + ;; + --) + break; + ;; + *) + echo "error: xo-reconfigure: unexpected argument [$1]" + echo "usage: xo-reconfigure" + echo " xo-reconfigure [-n] -- CMAKE_ARGS" + exit 1 + esac + + shift +done + +# Build the cmake command +CMAKE_CMD=( + cmake + -B @CMAKE_BINARY_DIR@ + -S @CMAKE_SOURCE_DIR@ + -DCMAKE_BUILD_TYPE=@CMAKE_BUILD_TYPE@ + -DCMAKE_INSTALL_PREFIX=@CMAKE_INSTALL_PREFIX@ + -DCMAKE_INSTALL_DOCDIR=@CMAKE_INSTALL_DOCDIR@ + -DCMAKE_MODULE_PATH=@CMAKE_MODULE_PATH@ + -DCMAKE_PREFIX_PATH=@CMAKE_PREFIX_PATH@ + -DCMAKE_CXX_STANDARD=@CMAKE_CXX_STANDARD@ + -DXO_CMAKE_CONFIG_EXECUTABLE=@XO_CMAKE_CONFIG_EXECUTABLE@ + -DENABLE_TESTING=@ENABLE_TESTING@ + -DXO_ENABLE_DOCS=@XO_ENABLE_DOCS@ + -DXO_ENABLE_ASM=@XO_ENABLE_ASM@ + -DXO_ENABLE_EXAMPLES=@XO_ENABLE_EXAMPLES@ + -DXO_ENABLE_VULKAN=@XO_ENABLE_VULKAN@ + -DXO_ENABLE_OPENGL=@XO_ENABLE_OPENGL@ + + "${@}" +) + +if [[ ${dry_run_flag} = true ]]; then + # Print the command with proper quoting for copy-paste + printf '%q ' "${CMAKE_CMD[@]}" | sed -e 's: -D: \\\n -D:g' + printf '\n' +else + # Execute the command + "${CMAKE_CMD[@]}" +fi