diff --git a/.github/workflows/mcg-ci.yml b/.github/workflows/mcg-ci.yml index a325822e..109d9bea 100644 --- a/.github/workflows/mcg-ci.yml +++ b/.github/workflows/mcg-ci.yml @@ -45,7 +45,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: cmake - run: cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -B build -S . + run: cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_INSTALL_PREFIX="$(pwd)/install" -B build -S . - name: build run: cmake --build build --parallel - name: install @@ -58,6 +58,12 @@ jobs: run: | CMAKE_PREFIX_PATH=install/lib/cmake/metacg cmake -S graph/test/install -B build-install-test cmake --build build-install-test + - name: metacg-config-test + run: | + MCG_CFG=install/bin/metacg-config + stat $MCG_CFG + [[ "$($MCG_CFG --prefix)" == "$(cd install; pwd)" ]] || exit 1 + [[ "$($MCG_CFG --revision)" == "$(git rev-parse HEAD)" ]] || exit 1 build-container: runs-on: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index e43a59d2..75f7289f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,3 +191,5 @@ option( if(METACG_BUILD_PYMETACG) add_subdirectory(pymetacg) endif() + +add_subdirectory(utils) diff --git a/cmake/ToolchainOptions.cmake b/cmake/ToolchainOptions.cmake index a6226108..48cde7be 100644 --- a/cmake/ToolchainOptions.cmake +++ b/cmake/ToolchainOptions.cmake @@ -1,12 +1,6 @@ include(json) include(spdlog) - -if(METACG_BUILD_GRAPH_TOOLS - OR METACG_BUILD_CGCOLLECTOR - OR METACG_BUILD_PGIS -) - include(cxxopts-lib) -endif() +include(cxxopts-lib) # Internal dependencies function(add_metacg target) diff --git a/graph/test/integration/TargetCollector/TestRunner.sh b/graph/test/integration/TargetCollector/TestRunner.sh index 89aee4cb..9150b825 100755 --- a/graph/test/integration/TargetCollector/TestRunner.sh +++ b/graph/test/integration/TargetCollector/TestRunner.sh @@ -27,7 +27,7 @@ done echo "Running integration test for TargetCollector script" echo "{}" > src/wholeProgramCG-${CI_CONCURRENT_ID}.ipcg -test_command=(python3 ../../../../TargetCollector.py \ +test_command=(python3 ../../../../utils/TargetCollector.py \ -a=".." \ -g=both \ -b=build-${CI_CONCURRENT_ID} \ diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt new file mode 100644 index 00000000..9040988f --- /dev/null +++ b/utils/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(config) diff --git a/TargetCollector.py b/utils/TargetCollector.py similarity index 100% rename from TargetCollector.py rename to utils/TargetCollector.py diff --git a/utils/config/CMakeLists.txt b/utils/config/CMakeLists.txt new file mode 100644 index 00000000..ccf3f1b6 --- /dev/null +++ b/utils/config/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(metacg-config MCGConfig.cpp) +add_config_include(metacg-config) +target_compile_definitions(metacg-config PRIVATE INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}") +add_cxxopts(metacg-config) + +install(TARGETS metacg-config DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/utils/config/MCGConfig.cpp b/utils/config/MCGConfig.cpp new file mode 100644 index 00000000..fddb16d1 --- /dev/null +++ b/utils/config/MCGConfig.cpp @@ -0,0 +1,50 @@ +/** + * File: MCGConfig.cpp + * License: Part of the MetaCG project. Licensed under BSD 3 clause license. See LICENSE.txt file at + * https://github.com/tudasc/metacg/LICENSE.txt + */ +#include "config.h" + +#include + +#include "cxxopts.hpp" + +int main(int argc, char** argv) { + cxxopts::Options options("metacg-config", "MetaCG configuration tool"); + options.add_options("commands")("v,version", "Prints the version of this MetaCG installation")( + "revision", "Prints the revision hash of this MetaCG installation")( + "prefix", "Prints the installation prefix of this MetaCG installation.")("h,help", "Print help"); + + const cxxopts::ParseResult result = options.parse(argc, argv); + + if (result.contains("help")) { + std::cout << options.help() << std::endl; + return EXIT_SUCCESS; + } + + // Exactly one of these is allowed at the same time + int optCount = result.count("version") + result.count("revision") + result.count("prefix"); + if (optCount == 0) { + std::cerr << "Error: No command specified.\n"; + return EXIT_FAILURE; + } else if (optCount > 1) { + std::cerr << "Warning: Multiple mutually exclusive commands specified. Only one of them will be processed.\n"; + } + + if (result.contains("version")) { + std::cout << MetaCG_VERSION_MAJOR << "." << MetaCG_VERSION_MINOR; + return EXIT_SUCCESS; + } + + if (result.contains("revision")) { + std::cout << MetaCG_GIT_SHA; + return EXIT_SUCCESS; + } + + if (result.contains("prefix")) { + std::cout << INSTALL_PREFIX; + return EXIT_SUCCESS; + } + + return EXIT_SUCCESS; +}