cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

# this is for internal use
if("${CMAKE_PROJECT_NAME}" STREQUAL "timemory" AND NOT TIMEMORY_USE_PAPI)
    return()
endif()

project(timemory-CPU-Roofline-Example LANGUAGES C CXX)

set(EXE_NAME ex_cpu_roofline)
set(COMPONENTS papi threading compile-options analysis-tools arch)
set(_LINKER_LANG CXX)

option(USE_EXTERN_TEMPLATES "Enable extern templates" OFF)
if(USE_EXTERN_TEMPLATES)
    list(APPEND COMPONENTS cxx extern-templates)
    if(TIMEMORY_USE_CUPTI OR TIMEMORY_USE_CUDA)
        set(_LINKER_LANG CUDA)
    endif()
endif()

find_package(timemory REQUIRED COMPONENTS ${COMPONENTS})

add_library(cpu-fp-single INTERFACE)
add_library(cpu-fp-double INTERFACE)

target_compile_definitions(cpu-fp-single INTERFACE ROOFLINE_FP_BYTES=4)
target_compile_definitions(cpu-fp-double INTERFACE ROOFLINE_FP_BYTES=8)

# create the fibonacci example
add_executable(ex-cpu-roofline-fib-single          ${EXE_NAME}.cpp)
target_link_libraries(ex-cpu-roofline-fib-single   timemory cpu-fp-single)
set_target_properties(ex-cpu-roofline-fib-single   PROPERTIES OUTPUT_NAME ${EXE_NAME}.sp
    LINKER_LANGUAGE ${_LINKER_LANG})

add_executable(ex-cpu-roofline-fib-double          ${EXE_NAME}.cpp)
target_link_libraries(ex-cpu-roofline-fib-double   timemory cpu-fp-double)
set_target_properties(ex-cpu-roofline-fib-double   PROPERTIES OUTPUT_NAME ${EXE_NAME}
    LINKER_LANGUAGE ${_LINKER_LANG})

# install the targets
install(TARGETS ex-cpu-roofline-fib-single ex-cpu-roofline-fib-double DESTINATION bin)
