################################################################################
# Copyright © 2023 MetaX Integrated Circuits (Shanghai) Co.,Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#   1. Redistributions of source code must retain the above copyright notice, this list of
#      conditions and the following disclaimer.
#   2. Redistributions in binary form must reproduce the above copyright notice, this list of
#      conditions and the following disclaimer in the documentation and/or other materials
#      provided with the distribution.
#   3. Neither the name of the copyright holder nor the names of its contributors may be used
#      to endorse or promote products derived from this software without specific prior written
#      permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

cmake_minimum_required(VERSION 3.10)
project(sparse_example)
set(CMAKE_BUILD_TYPE "Debug")

add_definitions(-w)

if(NOT DEFINED ENV{MACA_PATH})
    message(FATAL_ERROR "Please make sure the environment variable MACA_PATH is set.
    using export MACA_PATH=/your/maca/path")
endif()

if(NOT DEFINED ENV{MACA_CLANG_PATH})
    message(FATAL_ERROR "\n The MACA_CLANG_PATH is not specified.")
else()
    add_compile_options(-std=c++17)
    INCLUDE_DIRECTORIES($ENV{MACA_CLANG_PATH}/../lib)
endif()

INCLUDE_DIRECTORIES($ENV{MACA_PATH}/include/mcr)
INCLUDE_DIRECTORIES($ENV{MACA_PATH}/include)
INCLUDE_DIRECTORIES($ENV{MACA_PATH}/include/mcsparse)
INCLUDE_DIRECTORIES(${SPARSE_INCLUDE_DIR})
LINK_DIRECTORIES(${SPARSE_LINK_DIR})

find_library(MC_RUNTIME_LIB mcruntime HINTS $ENV{MACA_PATH}/lib)

foreach(EXAMPLE
        "example_coo_spmv"
        "example_csr_spmv"
        "example_csr_spsv"
        "example_spgemm"
        "example_csrgemm2"
        "example_spgemm_complex"
        "example_spmm"
        "example_axpby"
        "example_coo2csr"
        "example_csr2coo"
        "example_csr2csr_compress"
        "example_csr2csc"
        "example_csr_sort"
        "example_csc_sort"
        "example_coo_sort"
        "example_gemvi"
        "example_dense2sparse"
        "example_sparse2dense"
        "example_prune_dense2csr"
        "example_prune_csr2csr"
        "example_csrgeam"
        "example_gemmi"
        "example_scatter"
        "example_rot"
        "example_prune_csr2csr_by_percentage"
        "example_prune_dense2csr_by_percentage"
        "example_spvv"
        "example_csru2csr"
        "example_csr_ilu0"
        "example_sddmm"
        "example_csr_ic0"
        "example_batched_gpsv"
        "example_gtsv"
        "example_no_pivot_gtsv"
        "example_gtsv_strided_batch"
        "example_csr_spsm"
        "example_csr2gebsr"
        "example_gtsv_interleaved_batch"
        "example_bsrmv"
        "example_csr2bsr"
        "example_bsrx_spmv"
        "example_bsrmm"
        "example_bsrsv"
        "example_create_identity"
        )
    add_executable(${EXAMPLE} ${EXAMPLE}.cpp)
    target_link_libraries(${EXAMPLE} mcsparse ${MC_RUNTIME_LIB})
endforeach(EXAMPLE)
