diff --git a/xo-cmake/bin/xo-cmake-config.in b/xo-cmake/bin/xo-cmake-config.in index bbea1361..8cb3f39d 100755 --- a/xo-cmake/bin/xo-cmake-config.in +++ b/xo-cmake/bin/xo-cmake-config.in @@ -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 diff --git a/xo-cmake/cmake/xo_macros/xo_cxx.cmake b/xo-cmake/cmake/xo_macros/xo_cxx.cmake index d07fb3ad..5be3ce0b 100644 --- a/xo-cmake/cmake/xo_macros/xo_cxx.cmake +++ b/xo-cmake/cmake/xo_macros/xo_cxx.cmake @@ -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 diff --git a/xo-cmake/share/xo-macros/xo-reconfigure.in b/xo-cmake/share/xo-macros/xo-reconfigure.in new file mode 100644 index 00000000..cf5c8f72 --- /dev/null +++ b/xo-cmake/share/xo-macros/xo-reconfigure.in @@ -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@ \ + "$@"