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..60a9d4a7 100644 --- a/src/c/config/perfflowaspect-config.cmake.in +++ b/src/c/config/perfflowaspect-config.cmake.in @@ -1,15 +1,15 @@ if (NOT PERFFLOWASPECT_CONFIG_LOADED) - set(PERFFLOWASPECT_VERSION "@PROJECT_VERSION@") - set(PERFFLOWASPECT_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@") - set(PERFFLOWASPECT_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@") + set(PERFFLOWASPECT_VERSION "@PROJECT_VERSION@") + set(PERFFLOWASPECT_DIR "@CMAKE_INSTALL_PREFIX@") + set(PERFFLOWASPECT_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@") include(CMakeFindDependencyMacro) 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..fc17f929 --- /dev/null +++ b/src/c/examples/using-with-cmake/CMakeLists.txt @@ -0,0 +1,41 @@ +############################################################################### +# 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}/share/perfflowaspect-config.cmake) + message(FATAL_ERROR "Could not find PerfFlowAspect CMake include file (${PERFFLOWASPECT_DIR}/share/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 + */