Skip to content

Commit

Permalink
add initial example integration with cmake (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
slabasan authored Apr 16, 2024
1 parent b3ff7c6 commit 483eaa5
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/c/config/perfflowaspect-config.cmake.in
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions src/c/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
install(DIRECTORY using-with-cmake
DESTINATION examples)
41 changes: 41 additions & 0 deletions src/c/examples/using-with-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

#
54 changes: 54 additions & 0 deletions src/c/examples/using-with-cmake/smoketest.cpp
Original file line number Diff line number Diff line change
@@ -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 <cstdio>
#include <string>
#include <unistd.h>

__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
*/

0 comments on commit 483eaa5

Please sign in to comment.