From f685ee4e6a33ed31ab170ffcda1781e3c5be9b58 Mon Sep 17 00:00:00 2001 From: Stephanie Brink Date: Fri, 5 Apr 2024 18:04:12 -0700 Subject: [PATCH] add initial example cmake integration --- src/c/CMakeLists.txt | 1 + src/c/config/perfflowaspect-config.cmake.in | 6 +-- src/c/examples/CMakeLists.txt | 2 + .../examples/using-with-cmake/CMakeLists.txt | 42 +++++++++++++++ src/c/examples/using-with-cmake/smoketest.cpp | 54 +++++++++++++++++++ 5 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 src/c/examples/CMakeLists.txt create mode 100644 src/c/examples/using-with-cmake/CMakeLists.txt create mode 100644 src/c/examples/using-with-cmake/smoketest.cpp diff --git a/src/c/CMakeLists.txt b/src/c/CMakeLists.txt index 26baeeb7..0d75407d 100644 --- a/src/c/CMakeLists.txt +++ b/src/c/CMakeLists.txt @@ -43,6 +43,7 @@ add_subdirectory(parser) add_subdirectory(runtime) add_subdirectory(weaver) add_subdirectory(test) +add_subdirectory(examples) add_library(perfflowaspect INTERFACE) target_link_libraries(perfflowaspect INTERFACE perfflow_runtime perfflow_parser WeavePassPlugin) diff --git a/src/c/config/perfflowaspect-config.cmake.in b/src/c/config/perfflowaspect-config.cmake.in index db15c33b..8245a7da 100644 --- a/src/c/config/perfflowaspect-config.cmake.in +++ b/src/c/config/perfflowaspect-config.cmake.in @@ -1,6 +1,6 @@ if (NOT PERFFLOWASPECT_CONFIG_LOADED) set(PERFFLOWASPECT_VERSION "@PROJECT_VERSION@") - set(PERFFLOWASPECT_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@") + set(PERFFLOWASPECT_DIR "@CMAKE_INSTALL_PREFIX@") set(PERFFLOWASPECT_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@") include(CMakeFindDependencyMacro) @@ -8,8 +8,8 @@ if (NOT PERFFLOWASPECT_CONFIG_LOADED) find_dependency(OpenSSL REQUIRED) # Library targets imported from file - # include(${PERFFLOWASPECT_INSTALL_PREFIX}/share/perfflowaspect_setup_targets.cmake) - include(${PERFFLOWASPECT_INSTALL_PREFIX}/share/perfflowaspect_targets.cmake) + # include(${PERFFLOWASPECT_DIR}/share/perfflowaspect_setup_targets.cmake) + include(${PERFFLOWASPECT_DIR}/share/perfflowaspect_targets.cmake) set(PERFFLOWASPECT_CONFIG_LOADED TRUE) endif() diff --git a/src/c/examples/CMakeLists.txt b/src/c/examples/CMakeLists.txt new file mode 100644 index 00000000..30371b23 --- /dev/null +++ b/src/c/examples/CMakeLists.txt @@ -0,0 +1,2 @@ +install(DIRECTORY using-with-cmake + DESTINATION examples) diff --git a/src/c/examples/using-with-cmake/CMakeLists.txt b/src/c/examples/using-with-cmake/CMakeLists.txt new file mode 100644 index 00000000..711da54c --- /dev/null +++ b/src/c/examples/using-with-cmake/CMakeLists.txt @@ -0,0 +1,42 @@ +############################################################################### +# Example that shows how to use an installed instance of PerfFlowAspect in +# another CMake-based build system. +# +# To build: +# mkdir build +# cd build +# cmake -DPERFFLOWASPECT_DIR={perfflowaspect install path} ../ +# make +# ./smoketest +# +# If run in-sub directory below using-with-cmake in a PerfFlowAspect install, +# PERFFLOWASPECT_DIR will be defaulted to ../../.. +# +# mkdir build +# cd build +# cmake .. +# make +# ./smoketest +############################################################################### + +cmake_minimum_required(VERSION 3.0) + +project(using_with_cmake) + +# +# Provide default for PERFFLOWASPECT_DIR that works for an PerfFlowAspect install +# +if(NOT PERFFLOWASPECT_DIR) + set(PERFFLOWASPECT_DIR "../..") +endif() + +# +# Check for valid PerfFlowAspect install +# +get_filename_component(PERFFLOWASPECT_DIR ${PERFFLOWASPECT_DIR} ABSOLUTE) +if(NOT EXISTS ${PERFFLOWASPECT_DIR}/lib/cmake/perfflowaspect-config.cmake) + message(FATAL_ERROR "Could not find PerfFlowAspect CMake include file +(${PERFFLOWASPECT_DIR}/lib/cmake/perfflowaspect-config.cmake)") +endif() + +# diff --git a/src/c/examples/using-with-cmake/smoketest.cpp b/src/c/examples/using-with-cmake/smoketest.cpp new file mode 100644 index 00000000..5a10887b --- /dev/null +++ b/src/c/examples/using-with-cmake/smoketest.cpp @@ -0,0 +1,54 @@ +/************************************************************\ + * Copyright 2021 Lawrence Livermore National Security, LLC + * (c.f. AUTHORS, NOTICE.LLNS, COPYING) + * + * This file is part of the Flux resource manager framework. + * For details, see https://github.com/flux-framework. + * + * SPDX-License-Identifier: LGPL-3.0 +\************************************************************/ + +#include +#include +#include + +__attribute__((annotate("@critical_path(pointcut='around')"))) +void bas() +{ + printf("bas\n"); +} + +__attribute__((annotate("@critical_path(pointcut='around')"))) +void bar() +{ + printf("bar\n"); + usleep(1000); + bas(); +} + +__attribute__((annotate("@critical_path()"))) +int foo(const std::string &str) +{ + printf("foo\n"); + usleep(1000); + bar(); + if (str == "hello") + { + return 1; + } + return 0; +} + +int main(int argc, char *argv[]) +{ + printf("Inside main\n"); + for (int i = 0; i < 4; i++) + { + foo("hello"); + } + return 0; +} + +/* + * vi:tabstop=4 shiftwidth=4 expandtab + */