diff --git a/cmake/Templates/HEJ-config.cc.in b/cmake/Templates/HEJ-config.cc.in index bbb4f41..02c0f73 100644 --- a/cmake/Templates/HEJ-config.cc.in +++ b/cmake/Templates/HEJ-config.cc.in @@ -1,105 +1,111 @@ /** * \authors The HEJ collaboration (see AUTHORS for details) * \date 2019-2022 * \copyright GPLv2 or later */ +#include #include #include #include #include #include "cxxopts.hpp" #include "HEJ/ConfigFlags.hh" namespace { constexpr std::string_view get_features() { std::string_view features = "" #ifdef HEJ_BUILD_WITH_QCDLOOP "QCDloop " #endif #ifdef HEJ_BUILD_WITH_HepMC2 "HepMC2 " #endif #ifdef HEJ_BUILD_WITH_HepMC3 "HepMC3 " #endif #ifdef HEJ_BUILD_WITH_RIVET #ifdef HEJ_USE_RIVET2 "Rivet2 " #else "Rivet3 " #endif #endif #ifdef HEJ_BUILD_WITH_HDF5 "HDF5 " #endif ; if(! features.empty()) { features.remove_suffix(1); } return features; } constexpr std::string_view FEATURES = get_features(); } int main(int argc, char** argv) { cxxopts::Options options{ argv[0], "Configuration of the @CMAKE_PROJECT_NAME@ installation" }; options.add_options() ("h,help", "show this help message and exit") ("prefix", "show @CMAKE_PROJECT_NAME@ installation prefix") ("includedir", "show the path with the installed @CMAKE_PROJECT_NAME@ header files") ("bindir", "show the path with the installed @CMAKE_PROJECT_NAME@ executable") ("libdir", "show the path with the installed @CMAKE_PROJECT_NAME@ library file") ("libs", "show flags for linking the @CMAKE_PROJECT_NAME@ library") ("cxxflags", "show the compiler flags for the @CMAKE_PROJECT_NAME@ headers") ("cxx", "show the compiler used to build @CMAKE_PROJECT_NAME@") ("features", "show the optional features enabled when building @CMAKE_PROJECT_NAME@") ("version", "show the installed @CMAKE_PROJECT_NAME@ version") ("revision", "show the hash of the installed @CMAKE_PROJECT_NAME@ git revision") ; if(argc == 1) { std::cout << options.help(); return EXIT_SUCCESS; } try { const auto opts = options.parse(argc, argv); if(opts.count("help")) { std::cout << options.help(); return EXIT_SUCCESS; } + std::string output{}; for(auto const & op: opts.arguments()){ if(op.key()=="prefix") - std::cout << "@CMAKE_INSTALL_PREFIX@"; + output += "@CMAKE_INSTALL_PREFIX@"; else if(op.key()=="includedir") - std::cout << "@CMAKE_INSTALL_PREFIX@/@INSTALL_INCLUDE_DIR_BASE@"; + output += "@CMAKE_INSTALL_PREFIX@/@INSTALL_INCLUDE_DIR_BASE@"; else if(op.key()=="bindir") - std::cout << "@CMAKE_INSTALL_PREFIX@/@INSTALL_BIN_DIR@"; + output += "@CMAKE_INSTALL_PREFIX@/@INSTALL_BIN_DIR@"; else if(op.key()=="libdir") - std::cout << "@CMAKE_INSTALL_PREFIX@/@INSTALL_LIB_DIR@"; + output += "@CMAKE_INSTALL_PREFIX@/@INSTALL_LIB_DIR@"; else if(op.key()=="libs") - std::cout << "-L@CMAKE_INSTALL_PREFIX@/@INSTALL_LIB_DIR@ -lHEJ"; + output += "-L@CMAKE_INSTALL_PREFIX@/@INSTALL_LIB_DIR@ -lHEJ"; else if(op.key()=="cxxflags") - std::cout << "-I@CMAKE_INSTALL_PREFIX@/@INSTALL_INCLUDE_DIR_BASE@"; + output += "-I@CMAKE_INSTALL_PREFIX@/@INSTALL_INCLUDE_DIR_BASE@"; else if(op.key()=="cxx") - std::cout << "@CMAKE_CXX_COMPILER@"; + output += "@CMAKE_CXX_COMPILER@"; else if(op.key()=="features") - std::cout << FEATURES; + output += FEATURES; else if(op.key()=="version") - std::cout << "@PROJECT_VERSION@"; + output += "@PROJECT_VERSION@"; else if(op.key()=="revision") - std::cout << "@PROJECT_GIT_REVISION@"; - std::cout << " "; + output += "@PROJECT_GIT_REVISION@"; + output += ' '; } - std::cout << std::endl; + if(!output.empty()) { + assert(output.back() == ' '); + output.pop_back(); + } + std::cout << output << std::endl; } catch(cxxopts::OptionException const &) { std::cout << options.help(); } return EXIT_SUCCESS; }